程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Prompt tone after Python program running

編輯:Python

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 .

call winsound

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 .

call pyttsx3

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


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved