python - 来自 gTTS 的机器人声音更少
问题描述
我创建了一个基本的虚拟助手。它有效,但听起来很糟糕,就像你从诈骗电话中得到的机器人声音。我为此使用的软件包是 gTTS,效果很好,但声音不好听。我能做些什么来改变它吗?
我的脚本中的代码:
tts = gTTS(text=audio_string, lang="en")
r = random.randint(1, 10000000)
audio_file = "audio-" + str(r) + ".mp3"
tts.save(audio_file)
playsound.playsound(audio_file)
print(audio_string)
os.remove(audio_file)
我已经尝试过en-us
,或者en-uk
它不起作用。声音还是一样的。有没有办法改变它?
解决方案
您可以使用 pyttsx3 模块
import pyttsx3
#Starting microsoft speech api sapi5
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')#fetching different voices from the system
engine.setProperty('voice', voices[1].id)#setting voice properties
engine.setProperty('rate', 130)#sets speed of speech
#enables speech
def speak(audio):
engine.say(audio)
engine.runAndWait()
您可以在 engine.setProperty('voice', voices[1].id) 语句中将 1 替换为 0
推荐阅读
- python - 使用管道时 VLC 无法打开 MRL
- python - PyGame 视频不同步
- node.js - 如何从 axios post API 请求中获取特定字段
- json - 将列表转储到 JSON 文件会在列表 [["x", "y","z"]] 中创建列表,为什么?
- sed - sed -n 函数在同一行重复调用
- azure - 在 Azure ARM 模板中执行复杂的脚本
- ruby-on-rails - Rails 在具有 has_many 关系的模型上使用“where”
- javascript - 如何制作高阶函数来处理其他函数并使它们可被递归`while`函数使用?
- r - 使用 FCC API 将 Lat/Lon 转换为县代码
- javascript - Vue的事件@click在下拉菜单中不起作用