pyttsx3的语音/语言更改问题

时间:2019-08-27 07:07:09

标签: python text-to-speech

我想将pyttsx3模块中的声音更改为英国男性声音,我确实安装了该声音,因为我可以在语言/语音选项和regedit(Microsoft George)中看到它,并且确实安装了其他声音,但是当我运行此代码

我看不到PC上的所有声音,其中一个声音是英国男性。 我有9种声音,pyttsx3只认出4种 有什么解决办法吗?

谢谢

import pyttsx3
engine = pyttsx3.init()
voices = engine.getProperty('voices')
for voice in voices:
    print("Voice:")
    print(" - ID: %s" % voice.id)
    print(" - Name: %s" % voice.name)
    print(" - Languages: %s" % voice.languages)
    print(" - Gender: %s" % voice.gender)
    print(" - Age: %s" % voice.age)

2 个答案:

答案 0 :(得分:2)

嗯,这是可能的。 但是,您必须在注册表中进行一些更改,因此请自行承担风险。 备份您的注册表文件甚至您的系统是一个好习惯。

第 1 步打开注册表编辑器:

按:Windows Key + R 并以管理员身份运行 regedit。

第 2 步检查所有可用的语言:

您应该遵循以下路径:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\Voices\Tokens 在那里您将看到系统上所有已安装的语音(除了小娜语音)。

第 3 步导出声音:

选择您想要的文件夹并右键单击该文件夹。 例如: 右键单击 MSTTS_V110_elGR_Stefanos,然后单击导出。 您可以使用您想要的任何名称保存文件,但扩展名应以 .reg

结尾

第 4 步修改文件:

您需要修改它,使其值位于注册表中的另外两个位置。 使用您选择的任何文本编辑器打开文件并执行以下操作:

  1. 复制除第一行以外的所有内容(Windows 注册表编辑器 5.00 版)。
  2. 将所有内容粘贴到文件末尾。
  3. 修改第一个数据集的位置:[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\Voices\Tokens\ MSTTS_V110_elGR_Stefanos(Your voice name here)][HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\ MSTTS_V110_elGR_Stefanos(Your voice name here)] (只需将 Speech_OneCore 更改为 Speech) 这也适用于属性位置...\Speech\Voices\Tokens\(your voice name)\Attributes
  4. 将第二个数据集(您刚刚复制粘贴到最后的那个)的位置替换为: [HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\SPEECH\Voices\Tokens\(your voice name)] 它是带有 [HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\SPEECH\Voices\Tokens\(your voice name)\Attributes
  5. 的属性

举个例子:

原始文件:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\Voices\Tokens\MSTTS_V110_elGR_Stefanos]
@="Microsoft Stefanos - Greek (Greece)"
"408"="Microsoft Stefanos - Greek (Greece)"
"CLSID"="{179F3D56-1B0B-42B2-A962-59B7EF59FE1B}"
"LangDataPath"=hex(2):25,00,77,00,69,00,6e,00,64,00,69,00,72,00,25,00,5c,00,53,\
  00,70,00,65,00,65,00,63,00,68,00,5f,00,4f,00,6e,00,65,00,43,00,6f,00,72,00,\
  65,00,5c,00,45,00,6e,00,67,00,69,00,6e,00,65,00,73,00,5c,00,54,00,54,00,53,\
  00,5c,00,65,00,6c,00,2d,00,47,00,52,00,5c,00,4d,00,53,00,54,00,54,00,53,00,\
  4c,00,6f,00,63,00,45,00,6c,00,47,00,52,00,2e,00,64,00,61,00,74,00,00,00
"VoicePath"=hex(2):25,00,77,00,69,00,6e,00,64,00,69,00,72,00,25,00,5c,00,53,00,\
  70,00,65,00,65,00,63,00,68,00,5f,00,4f,00,6e,00,65,00,43,00,6f,00,72,00,65,\
  00,5c,00,45,00,6e,00,67,00,69,00,6e,00,65,00,73,00,5c,00,54,00,54,00,53,00,\
  5c,00,65,00,6c,00,2d,00,47,00,52,00,5c,00,4d,00,31,00,30,00,33,00,32,00,53,\
  00,74,00,65,00,66,00,61,00,6e,00,6f,00,73,00,00,00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\Voices\Tokens\MSTTS_V110_elGR_Stefanos\Attributes]
"Age"="Adult"
"DataVersion"="11.0.2016.1016"
"Gender"="Male"
"Language"="408"
"Name"="Microsoft Stefanos"
"SayAsSupport"="spell=NativeSupported; alphanumeric=NativeSupported"
"SharedPronunciation"=""
"Vendor"="Microsoft"
"Version"="11.0"

修改的注册表文件:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\MSTTS_V110_elGR_Stefanos]
@="Microsoft Stefanos - Greek (Greece)"
"408"="Microsoft Stefanos - Greek (Greece)"
"CLSID"="{179F3D56-1B0B-42B2-A962-59B7EF59FE1B}"
"LangDataPath"=hex(2):25,00,77,00,69,00,6e,00,64,00,69,00,72,00,25,00,5c,00,53,\
  00,70,00,65,00,65,00,63,00,68,00,5f,00,4f,00,6e,00,65,00,43,00,6f,00,72,00,\
  65,00,5c,00,45,00,6e,00,67,00,69,00,6e,00,65,00,73,00,5c,00,54,00,54,00,53,\
  00,5c,00,65,00,6c,00,2d,00,47,00,52,00,5c,00,4d,00,53,00,54,00,54,00,53,00,\
  4c,00,6f,00,63,00,45,00,6c,00,47,00,52,00,2e,00,64,00,61,00,74,00,00,00
"VoicePath"=hex(2):25,00,77,00,69,00,6e,00,64,00,69,00,72,00,25,00,5c,00,53,00,\
  70,00,65,00,65,00,63,00,68,00,5f,00,4f,00,6e,00,65,00,43,00,6f,00,72,00,65,\
  00,5c,00,45,00,6e,00,67,00,69,00,6e,00,65,00,73,00,5c,00,54,00,54,00,53,00,\
  5c,00,65,00,6c,00,2d,00,47,00,52,00,5c,00,4d,00,31,00,30,00,33,00,32,00,53,\
  00,74,00,65,00,66,00,61,00,6e,00,6f,00,73,00,00,00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\MSTTS_V110_elGR_Stefanos\Attributes]
"Age"="Adult"
"DataVersion"="11.0.2016.1016"
"Gender"="Male"
"Language"="408"
"Name"="Microsoft Stefanos"
"SayAsSupport"="spell=NativeSupported; alphanumeric=NativeSupported"
"SharedPronunciation"=""
"Vendor"="Microsoft"
"Version"="11.0"

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\SPEECH\Voices\Tokens\MSTTS_V110_elGR_Stefanos]
@="Microsoft Stefanos - Greek (Greece)"
"408"="Microsoft Stefanos - Greek (Greece)"
"CLSID"="{179F3D56-1B0B-42B2-A962-59B7EF59FE1B}"
"LangDataPath"=hex(2):25,00,77,00,69,00,6e,00,64,00,69,00,72,00,25,00,5c,00,53,\
  00,70,00,65,00,65,00,63,00,68,00,5f,00,4f,00,6e,00,65,00,43,00,6f,00,72,00,\
  65,00,5c,00,45,00,6e,00,67,00,69,00,6e,00,65,00,73,00,5c,00,54,00,54,00,53,\
  00,5c,00,65,00,6c,00,2d,00,47,00,52,00,5c,00,4d,00,53,00,54,00,54,00,53,00,\
  4c,00,6f,00,63,00,45,00,6c,00,47,00,52,00,2e,00,64,00,61,00,74,00,00,00
"VoicePath"=hex(2):25,00,77,00,69,00,6e,00,64,00,69,00,72,00,25,00,5c,00,53,00,\
  70,00,65,00,65,00,63,00,68,00,5f,00,4f,00,6e,00,65,00,43,00,6f,00,72,00,65,\
  00,5c,00,45,00,6e,00,67,00,69,00,6e,00,65,00,73,00,5c,00,54,00,54,00,53,00,\
  5c,00,65,00,6c,00,2d,00,47,00,52,00,5c,00,4d,00,31,00,30,00,33,00,32,00,53,\
  00,74,00,65,00,66,00,61,00,6e,00,6f,00,73,00,00,00

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\SPEECH\Voices\Tokens\MSTTS_V110_elGR_Stefanos\Attributes]
"Age"="Adult"
"DataVersion"="11.0.2016.1016"
"Gender"="Male"
"Language"="408"
"Name"="Microsoft Stefanos"
"SayAsSupport"="spell=NativeSupported; alphanumeric=NativeSupported"
"SharedPronunciation"=""
"Vendor"="Microsoft"
"Version"="11.0"

第 5 步导入文件:

保存文件并双击它。 将出现一个警告窗口,按是并继续。

第 6 步检查:

运行以下代码:

engine = pyttsx3.init()
voices = engine.getProperty("voices")

for voice in voices:
    print(voice.id)

输出:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_DAVID_11.0 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\MSTTS_V110_elGR_Stefanos HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_ZIRA_11.0

答案 1 :(得分:0)

Microsoft可下载的声音似乎受到限制。如果转到他们的regedit路径,您会看到与GB包相比,额外可下载的声音(如Microsoft George)将保存到与pyttsx3可接受的声音不同的路径上。

最重要的是,在进一步检查时,导航到这些声音的路径(Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\Voices\Tokens)时,我注意到这些声音都没有tts属性,就像默认的David,Zyra和Iriana一样。这使我相信它们不能用于tts。