Running recently Python Code , We often encounter the situation that the code runs for a long time , And I don't want to keep staring at the interface of code running , therefore , I wonder if I can send out a prompt tone after the code runs , Here are two ways I found .
import winsound
duration = 1000 # The duration of the /ms
frequency = 500 # frequency /Hz
winsound.Beep(frequency, duration)
Running this code will sound an alarm , The higher the frequency is. , The sharper it sounds . Frequency should be within [37,32767] Between .
import pyttsx3
engine = pyttsx3.init() # establish engine And initialization
engine.say(" end ")
engine.runAndWait() # Wait for the voice broadcast to complete
This method can broadcast the sound you want , Support Chinese .
If you want to slow down , It can be like this :
import pyttsx3
engine = pyttsx3.init() # establish engine And initialization
rate = engine.getProperty('rate') # Get the details of the current speed
print(rate) # Print the current speed
engine.setProperty('rate', 125)
engine.say(" end ")
engine.runAndWait() # Wait for the voice broadcast to complete
Reference resources :
https://blog.csdn.net/weixin_42838562/article/details/84106873
https://blog.csdn.net/white_hat_2009/article/details/124784680