pyttsx3 的语音/语言更改问题 [英] Problem with Voice/language change with pyttsx3

查看:76
本文介绍了pyttsx3 的语音/语言更改问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to change voice in pyttsx3 module to british male voice, which i do have installed since i can see it in language/speech options and in regedit (Microsoft George), and i do have other voices installed, but when i run this code

我没有看到我电脑上的所有声音,其中一个声音是英国男性.在我拥有的 9 个声音中,pyttsx3 只能识别 4 个有什么解决办法吗?

i dont see all voices that are on my PC, one of those voices is british male. Out of 9 voices i have, pyttsx3 only recognizes 4 Any fix for that?

谢谢

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)

推荐答案

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

Well it is possible. However you will have to do some changes in registry so proceed below at your own risk. It would be a good practice to backup your registry files or even your system.

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

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

Press: Windows Key + R and run regedit as administrator.

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

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

You should follow this path: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\Voices\Tokens and there you will see all installed voices on your system (except the cortana voices).

第 3 步导出声音:

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

Select the one you want and right click on the folder. For an example: Right click MSTTS_V110_elGR_Stefanos and click export. You can save the file with any name you want but the extension should finish as .reg

第 4 步修改文件:

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

You will need to modify it so that it's values are into two other locations in the registry. Open the file with any text editor of your choice and do the following:

  1. 复制除第一行以外的所有内容(Windows 注册表编辑器 5.00 版).
  2. 将所有内容粘贴到文件末尾.
  3. 修改第一个数据集的位置:[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\Voices\Tokens\MSTTS_V110_elGR_Stefanos(这里是你的语音名称)][HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\MSTTS_V110_elGR_Stefanos(此处为您的语音名称)](只需将 Speech_OneCore 更改为 Speech)这也适用于属性位置 ...\Speech\Voices\Tokens\(your voice name)\Attributes
  4. 将第二个数据集(您刚刚复制粘贴到最后的那个)的位置替换为:[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\SPEECH\Voices\Tokens\(你的声音名称)]它的属性为 [HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\SPEECH\Voices\Tokens\(your voice name)\Attributes
  1. Copy everything except the first line (Windows Registry Editor Version 5.00).
  2. Paste everything at the end of the file.
  3. Modify the location of first data set:[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\Voices\Tokens\ MSTTS_V110_elGR_Stefanos(Your voice name here)] to [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\ MSTTS_V110_elGR_Stefanos(Your voice name here)] (Just change the Speech_OneCore to Speech) And that goes to attributes location aswell ...\Speech\Voices\Tokens\(your voice name)\Attributes
  4. Replace the location of the second data set (The one you just copy-pasted at the end) with: [HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\SPEECH\Voices\Tokens\(your voice name)] and it's attributes with [HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\SPEECH\Voices\Tokens\(your voice name)\Attributes

举个例子:

原始文件:

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 步导入文件:

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

Save the file and double click on it. There will be a warning window press yes and proceed.

第 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_KEYINE\Microsoft_SteefanoS_HKEY_L0CAL_EN-US_DAVID_11.0US_ZIRA_11.0

这篇关于pyttsx3 的语音/语言更改问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆