来自 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-usen-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 为男声

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...