首页 > 解决方案 > 需要帮助将 Windows 通知转换为 python 中的文本转语音

问题描述

有什么方法可以获取通知示例的信息/文本,如果有通知,我希望能够将其作为字符串获取,以进一步使其成为文本到语音

标签: pythonautomationtext-to-speech

解决方案


您可以使用 gtts 和 playsound 库创建一个 python 脚本来将文本转换为语音。

import gtts 
from playsound import playsound  #https://pypi.org/project/playsound/

#Load the string into gtts   
tts = gtts.gTTS("STRINGTOCONVERTTOAUDIO")
filename = "audio.mp3"
#Remove the audio file if already exists
os.remove(filename)   
# save the audio file to a convenient location... 
tts.save(filename)
# play the audio file
playsound(filename)

然后,您可以在任何操作系统上的任何需要的地方调用此脚本/函数。


推荐阅读