python-3.x - 如何在 Python 中打开扬声器以说出给定的文本
问题描述
我怎样才能让 Python 说出一些文字?
我听说有一个 Python TTS 库。如何将其包含在程序中?以及我应该用给定的文本调用哪个函数来通过 CPU 扬声器说话。
解决方案
您将需要该模块:gTTS (Google Text-to-Speech)
首先,安装模块 gTTS
pip install gTTS
然后创建一个python文件:
from gtts import gTTS
#Write your text
text_to_speech = "So that's how you convert text to speech using Python"
#Choose your language (en : english, fr: french, ...)
language = "en"
#Passing the text, language and the speed to the module
myobj = gTTS(text=text_to_speech, lang=language, slow=False)
#Saving the audio in mp3
myobj.save("text_to_speech.mp3")
推荐阅读
- swift - Swift:如何在 UITableViewController 中立即重新加载数据?
- c# - 如何在网格中设置堆栈布局的行跨大小?
- java - 创建 ActiveMQ 代理在后续测试中失败,找不到服务:'META-INF/services/org/apache/activemq/wireformat/default'
- r - 如何在情节中在标题周围添加填充?
- sql - 如果不在排除表中,则插入 Sqlite
- angular - 更新不同的可观察值时如何更新可观察值?
- android - 集成系统语音操作,就像在 Twitter“查找 [xyz] [on] [app_name]”中一样。“在 [app_name] 上搜索 [xyz]”已经在工作
- angular - 在异步函数完成后调用一个函数
- powershell - 撤消 Conda Powershell 提示修改
- gulp - 使用 gulp 系列时从未定义的任务