在 SAPI 5 中实施 Microsoft Speech Platform 语言
Implement Microsoft Speech Platform languages in SAPI 5
我使用 SAPI 库用 C++ 创建了一个小程序。在我的代码中,我列出了系统上安装的语音数量。当我编译时,我得到 11,但只安装了 8 个,唯一的语音是 Microsoft Anna。我在注册表中检查过它 (HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices)。
我安装了多种语言,尤其是来自 Microsoft Speech Platform 的语言,但可以使用 none。
此外,当我更改语音ID时,出现未处理的异常错误,我认为这是因为选择的ID不存在。
这是我的代码
#include "stdafx.h"
int main( int argc, char* argv[] )
{
CComPtr<ISpObjectToken> cpVoiceToken;
CComPtr<IEnumSpObjectTokens> cpEnum;
ISpVoice * pVoice = NULL;
ULONG count = 0;
string str;
if( FAILED( ::CoInitialize( NULL ) ) )
return FALSE;
HRESULT hr = CoCreateInstance( CLSID_SpVoice, NULL, CLSCTX_ALL,
IID_ISpVoice, ( void ** )&pVoice );
if( SUCCEEDED( hr ) )
{
//Enumerate Voices
hr = SpEnumTokens( SPCAT_VOICES, NULL /*L"Gender=Female"*/, NULL, &cpEnum);
printf( "Success\n" );
}
else
{
printf( "Failed to initialize SAPI" );
}
if( SUCCEEDED( hr ) )
{
//Get number of voices
hr = cpEnum->GetCount( &count );
printf( "TTS voices found: %i\n", count );
}
else
{
printf( "Failed to enumerate voices" );
hr = S_OK;
}
if( SUCCEEDED( hr ) )
{
cpVoiceToken.Release();
cpEnum->Item( 3, &cpVoiceToken ); //3 represents the ID of the voice
pVoice->SetVoice( cpVoiceToken );
hr = pVoice->Speak( L"You have selected Microsoft Server Speech Text to Speech Voice (en-GB, Hazel) as the computer's default voice.", 0, NULL ); //speak sentence
pVoice->Release();
pVoice = NULL;
}
::CoUninitialize();
system( "PAUSE" );
}
唯一的声音是 Microsoft Anna,我不明白为什么。如果其他语言不可用,该程序将不会向我显示有这么多 (11)。我想知道 Microsoft Speech Platform 语言是否与 SAPI 兼容。
经过多次尝试和失败后,我设法找到了问题的答案。
我在 Win32 中编译了我的程序。所以我决定将其更改为 x64 并重新编译解决方案。我在我的程序中更改了语音 ID,并且来自 Microsoft Speech Platform 的语音有效。这意味着 MS Speech Platform 语言是 64 位语音,而 Microsoft Anna 是 32 位语音。
以下启发了我。
我使用 SAPI 库用 C++ 创建了一个小程序。在我的代码中,我列出了系统上安装的语音数量。当我编译时,我得到 11,但只安装了 8 个,唯一的语音是 Microsoft Anna。我在注册表中检查过它 (HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices)。 我安装了多种语言,尤其是来自 Microsoft Speech Platform 的语言,但可以使用 none。
此外,当我更改语音ID时,出现未处理的异常错误,我认为这是因为选择的ID不存在。
这是我的代码
#include "stdafx.h"
int main( int argc, char* argv[] )
{
CComPtr<ISpObjectToken> cpVoiceToken;
CComPtr<IEnumSpObjectTokens> cpEnum;
ISpVoice * pVoice = NULL;
ULONG count = 0;
string str;
if( FAILED( ::CoInitialize( NULL ) ) )
return FALSE;
HRESULT hr = CoCreateInstance( CLSID_SpVoice, NULL, CLSCTX_ALL,
IID_ISpVoice, ( void ** )&pVoice );
if( SUCCEEDED( hr ) )
{
//Enumerate Voices
hr = SpEnumTokens( SPCAT_VOICES, NULL /*L"Gender=Female"*/, NULL, &cpEnum);
printf( "Success\n" );
}
else
{
printf( "Failed to initialize SAPI" );
}
if( SUCCEEDED( hr ) )
{
//Get number of voices
hr = cpEnum->GetCount( &count );
printf( "TTS voices found: %i\n", count );
}
else
{
printf( "Failed to enumerate voices" );
hr = S_OK;
}
if( SUCCEEDED( hr ) )
{
cpVoiceToken.Release();
cpEnum->Item( 3, &cpVoiceToken ); //3 represents the ID of the voice
pVoice->SetVoice( cpVoiceToken );
hr = pVoice->Speak( L"You have selected Microsoft Server Speech Text to Speech Voice (en-GB, Hazel) as the computer's default voice.", 0, NULL ); //speak sentence
pVoice->Release();
pVoice = NULL;
}
::CoUninitialize();
system( "PAUSE" );
}
唯一的声音是 Microsoft Anna,我不明白为什么。如果其他语言不可用,该程序将不会向我显示有这么多 (11)。我想知道 Microsoft Speech Platform 语言是否与 SAPI 兼容。
经过多次尝试和失败后,我设法找到了问题的答案。 我在 Win32 中编译了我的程序。所以我决定将其更改为 x64 并重新编译解决方案。我在我的程序中更改了语音 ID,并且来自 Microsoft Speech Platform 的语音有效。这意味着 MS Speech Platform 语言是 64 位语音,而 Microsoft Anna 是 32 位语音。
以下