Windows TTS无法切换男性语音包问题求助
问题重现
尝试通过gender=male筛选语音播放音频失败,手动添加了Microsoft Kangkang(中文男声)的注册表项:
Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_ZH-CN_KANGKANG_11.0] @="Microsoft Kangkang - Chinese (Simplified, PRC)" "804"="Microsoft Kangkang - Chinese (Simplified, PRC)" "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,7a,00,68,00,2d,00,43,00,4e,00,5c,00,4d,00,53,00,54,00,54,00,53,00,\ 4c,00,6f,00,63,00,7a,00,68,00,43,00,4e,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,7a,00,68,00,2d,00,43,00,4e,00,5c,00,4d,00,32,00,30,00,35,00,32,00,59,\ 00,61,00,6f,00,79,00,61,00,6f,00,00,00 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_ZH-CN_KANGKANG_11.0\Attributes] "Age"="Adult" "DataVersion"="11.0.2013.1022" "Gender"="Male" "Language"="804" "Name"="Microsoft Kangkang" "SayAsSupport"="spell=NativeSupported; cardinal=GlobalSupported; ordinal=NativeSupported; date=GlobalSupported; time=GlobalSupported; telephone=NativeSupported; computer=NativeSupported; address=NativeSupported; percentage=NativeSupported; currency=NativeSupported; message=NativeSupported; url=NativeSupported; alphanumeric=NativeSupported" "SharedPronunciation"="" "Vendor"="Microsoft" "Version"="11.0"
导入注册表后,通过以下代码枚举语音:
ULONG len; m_pIEnumSpObjectTokens->GetCount(&len); for (auto i = 0; i < len; ++i) { ISpObjectToken* token; m_pIEnumSpObjectTokens->Item(i, &token); WCHAR* name; token->GetId(&name); OutputDebugStringW(name); }
输出可见Kangkang已被识别:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_ZH-CN_HUIHUI_11.0 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_ZIRA_11.0 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_ZH-CN_KANGKANG_11.0
但使用以下代码设置男声后,仍播放默认语音:
if (iGender == 1){ if (SUCCEEDED(SpFindBestToken(SPCAT_VOICES, L"gender=male", NULL, &pSpToken))) pVoice->SetVoice(pSpToken); }
解决方案
检查语音文件是否存在
注册表中VoicePath指向的文件%windir%\Speech_OneCore\Engines\TTS\zh-CN\M2052Yayaao需要实际存在。如果文件缺失,即使注册表项正确,语音也无法加载,会自动 fallback 到默认语音。明确指定语言筛选条件
SpFindBestToken可能优先匹配与当前系统语言或语音合成器默认语言一致的语音。添加语言筛选器,确保找到中文男声:if (iGender == 1){ // 添加语言筛选(804对应中文简体) if (SUCCEEDED(SpFindBestToken(SPCAT_VOICES, L"gender=male;language=804", NULL, &pSpToken))) pVoice->SetVoice(pSpToken); }验证
SetVoice调用是否成功
不要只检查SpFindBestToken的返回值,也要确认SetVoice是否成功:if (iGender == 1){ if (SUCCEEDED(SpFindBestToken(SPCAT_VOICES, L"gender=male;language=804", NULL, &pSpToken))) { HRESULT hr = pVoice->SetVoice(pSpToken); if (FAILED(hr)) { // 输出错误码,排查问题 wchar_t errMsg[256]; swprintf_s(errMsg, L"SetVoice failed: 0x%08X", hr); OutputDebugStringW(errMsg); } } }重启语音合成服务或应用
导入注册表后,部分情况下需要重启应用或Windows语音服务(SpeechSynthesizer相关服务)才能让新的语音项生效。检查语音位数兼容性
如果你的应用是32位,需要确保注册表项也写入了HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Speech\Voices\Tokens路径(64位系统下32位程序会读取这个路径的注册表)。可以把相同的注册表项复制到该路径下。
内容的提问来源于stack exchange,提问作者Ice Wind
相关产品推荐
相关产品推荐

