我希望这有帮助。我还使用 pyttsx,在 win7 操作系统上使用 Python,我正在研究一个小型 AI,使用 pyttsx 作为语音输出。
pyttsx 语音选择类适用于 SAPI5 语音,可在此处找到;从开始按钮,键入并运行 regedit.exe 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\'
Win7 仅包含 1 个语音(MS-Anna)
在微软,有更多选择;
http://www.microsoft.com/en-us/download/details.aspx?id=27224
MSSpeech_TTS_en-CA_Heather MSSpeech_TTS_en-GB_Hazel MSSpeech_TTS_en-IN_Heera MSSpeech_TTS_en-US_Helen MSSpeech_TTS_en-US_ZiraPro MSSpeech_TTS_en-AU_Hayley
但是,您也可以下载并安装 eSpeak。在安装过程中可能会安装许多 SAPI5 声音,并且可以根据需要多次重复安装。目录中有很好的文档。使用 pyttsx,您可以直接选择要使用的任何声音。因此,要访问“令牌”目录中的 SAPI5 语音 ID
speech_engine = pyttsx.init()
voices = speech_engine.getProperty('voices')
for voice in voices:
print 'voice', voice.id
#speech_engine.setProperty('voice', voice.id)
#speech_engine.say('The quick brown fox')
# here I find I have installed just 1 eSpeak voice into the Tokens DIR;
anna_voice = 'HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Speech\\Voices\\Tokens\\MS-Anna-1033-20-DSK'
male_voice_1 = 'HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Speech\\Voices\\Tokens\\eSpeak'
#=====
rate = speech_engine.getProperty('rate')
# the rate should be signed + for faster or - for slower
speech_engine.setProperty('rate', rate-85)
#=====
volume = speech_engine.getProperty('volume')
speech_engine.setProperty('volume', volume+1.0)
#=====
def speak(input_text):
global talking_yes_or_no
i = ''
txt_list = list(input_text)
if len(txt_list) > 0:
for i in txt_list:
if i == '':
txt_list.remove(i)
txt = ''.join(txt_list)
if txt != "":
speech_engine.say(txt)
speech_engine.runAndWait()
#=====
def use_anna_voice():
speech_engine.setProperty('voice', anna_voice)
#=====
def use_male_voice_1():
speech_engine.setProperty('voice', male_voice_1)
#=====
#use_male_voice()
#speak('hello')