2

我正在尝试使用 pyttsx3 说法语文本。但是,只有英语可用。

遵循如何在 pyttsx3 中更改声音的建议?,我尝试按照此处的说明安装法语语音包https://support.office.com/en-us/article/how-to-download-text-to-speech-languages-for-windows-10-d5a6b612- b3ae-423f-afa5-4f6caf1ec5d3

我重新启动了计算机,现在已经安装了法语语音到文本模块,并且可以在 Windows 设置的“语音”菜单下使用。测试按钮有效,我听到法语的测试样本。

我尝试运行以下代码以查看 pyttsx3 可用的内容:

import pyttsx3 
engine = pyttsx3.init() 
voices = engine.getProperty('voices') 
for voice in voices: 
    print(voice, voice.id) 
    engine.setProperty('voice', voice.id) 
    engine.say("Hello World!") 
    engine.runAndWait() 
    engine.stop() 

但是,我只得到以下输出:

<Voice id=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_ZIRA_11.0
          name=Microsoft Zira Desktop - English (United States)
          languages=[]
          gender=None
          age=None> HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_ZIRA_11.0

我错过了什么?

4

2 回答 2

2

I found a workaround by doing what is described there: https://www.ghacks.net/2018/08/11/unlock-all-windows-10-tts-voices-system-wide-to-get-more-of-them/

Here is a summary of the steps I followed. It assumes that you already have downloaded the voice packs as in the original question.

  1. Open regedit.exe (Windows + R, and type regedit) and navigate to the Registry key Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\Voices\Tokens.

  2. Right click on the voice you want to use and chose export.

  3. Open the exported file with a text editor (for example Notepad++).

  4. Copy all the text a second time in the file so you have everything two times (except the first line Windows Registry Editor Version 5.00).

  5. In the first part of the data, replace \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\Voices\Tokensby HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens (you have to do this at two distinct places).

  6. In the second part (the one you pasted below), do the same but change for HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\SPEECH\Voices\Tokens (again, two places to change).

  7. Save the file, close it, and double click it. Accept the registry modification.

  8. Restart your computer.

Now the exported voices are available to use with pyttsx3!

于 2019-06-24T08:52:07.747 回答
0

不直接使用注册表的更简单方法是使用 Window Powershell(以管理员身份运行)来做与 Silver Duck 的答案相同的事情。将以下代码复制并粘贴到 Powershell 中:

$sourcePath = 'HKLM:\software\Microsoft\Speech_OneCore\Voices\Tokens' #Where the OneCore voices live
$destinationPath = 'HKLM:\SOFTWARE\Microsoft\Speech\Voices\Tokens' #For 64-bit apps
$destinationPath2 = 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\SPEECH\Voices\Tokens' #For 32-bit apps
cd $destinationPath
$listVoices = Get-ChildItem $sourcePath
foreach($voice in $listVoices)
{
$source = $voice.PSPath #Get the path of this voices key
copy -Path $source -Destination $destinationPath -Recurse
copy -Path $source -Destination $destinationPath2 -Recurse
}

参考:

于 2022-01-11T15:44:00.027 回答