如何在PYTTS中设置属性: age, gender or language (Python)
How to set property: age, gender or language in PYTTS (Python)
我在 python 中使用 TTS。 (pyttsx 库)。
我在文档中读到我可以获得属性速率、语音、语音、音量。在文档中,我只能为速率、语音、音量设置 属性。这意味着我无法设置属性"voices"?我对声音很感兴趣,因为它包含年龄、性别、语言等。
此处的文档:http://pyttsx.readthedocs.io/en/latest/engine.html#pyttsx.voice.Voice
我可以轻松使用速率、语音、音量例如:
engine = pyttsx.init()
engine.getProperty('rate')
engine.getProperty('volume')
engine.setProperty('rate', 50)
engine.setProperty('volume', 0.25)
engine.say("something")
engine.runAndWait()
问题是。有机会改变"gander"、"age"或"language"说话的声音吗?如果有,请举例说明如何操作,因为我完全没有想法。
有一个使用 voices.id 的例子,实际上是 inside voices,但它并没有帮助我:
engine = pyttsx.init()
voices = engine.getProperty('voices')
for voice in voices:
engine.setProperty('voice', voice.id)
engine.say('The quick brown fox jumped over the lazy dog.')
engine.runAndWait()
抱歉打扰了,谢谢:-)
希望对您有所帮助。
我还使用 pyttsx,在 win7 os 上使用 Python,
我正在开发一个小型 AI,使用 pyttsx 作为语音输出。
pyttsx 语音 selection class 适用于 SAPI5 语音,
在这里找到;
从开始按钮,输入 运行 regedit.exe
'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\'
Win7 自带 1 个语音(MS-Anna)
在 micros 经常有更多选择os;
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,您可以直接 select 您想要使用的任何语音。
因此,要获取在 'Tokens' 目录
中找到的 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')
engine.setProperty('voice', voices[1].id) # voice select [0] for male.
我在尝试解决完全相同的问题时发现了这个问题。
经过一些尝试,更仔细地检查文档后,我清楚地知道这些属性与系统中安装的声音有关(在文档中称为 "The Voice metadata"),因此您不能修改它们,仅出于获取信息或出于其他“只读”原因阅读它们。
我在 python 中使用 TTS。 (pyttsx 库)。 我在文档中读到我可以获得属性速率、语音、语音、音量。在文档中,我只能为速率、语音、音量设置 属性。这意味着我无法设置属性"voices"?我对声音很感兴趣,因为它包含年龄、性别、语言等。 此处的文档:http://pyttsx.readthedocs.io/en/latest/engine.html#pyttsx.voice.Voice
我可以轻松使用速率、语音、音量例如:
engine = pyttsx.init()
engine.getProperty('rate')
engine.getProperty('volume')
engine.setProperty('rate', 50)
engine.setProperty('volume', 0.25)
engine.say("something")
engine.runAndWait()
问题是。有机会改变"gander"、"age"或"language"说话的声音吗?如果有,请举例说明如何操作,因为我完全没有想法。
有一个使用 voices.id 的例子,实际上是 inside voices,但它并没有帮助我:
engine = pyttsx.init()
voices = engine.getProperty('voices')
for voice in voices:
engine.setProperty('voice', voice.id)
engine.say('The quick brown fox jumped over the lazy dog.')
engine.runAndWait()
抱歉打扰了,谢谢:-)
希望对您有所帮助。 我还使用 pyttsx,在 win7 os 上使用 Python, 我正在开发一个小型 AI,使用 pyttsx 作为语音输出。
pyttsx 语音 selection class 适用于 SAPI5 语音, 在这里找到; 从开始按钮,输入 运行 regedit.exe 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\'
Win7 自带 1 个语音(MS-Anna)
在 micros 经常有更多选择os; 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,您可以直接 select 您想要使用的任何语音。 因此,要获取在 'Tokens' 目录
中找到的 SAPI5 语音 IDspeech_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')
engine.setProperty('voice', voices[1].id) # voice select [0] for male.
我在尝试解决完全相同的问题时发现了这个问题。 经过一些尝试,更仔细地检查文档后,我清楚地知道这些属性与系统中安装的声音有关(在文档中称为 "The Voice metadata"),因此您不能修改它们,仅出于获取信息或出于其他“只读”原因阅读它们。