如何将代码更改为英语而不是日语?
How can I change the code to English text to speak instead of Japanese?
目前,我有一个文本到语音的代码,但我想更改代码,以便输出为英语,而不是目前的日语母语者。有没有熟悉这方面的人可以帮助我
// SAPIの初期化
if (FAILED(CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice)))
{
throw;
}
// Register events to detect
pVoice->SetInterest(SPFEI(SPEI_PHONEME) | SPFEI(SPEI_END_INPUT_STREAM),
SPFEI(SPEI_PHONEME) | SPFEI(SPEI_END_INPUT_STREAM));
pVoice->SetNotifyWindowMessage(hWnd, WM_USER, 0, 0); // subscribe message
// preprocessing to speak
pVoice->Speak( NULL , SPF_PURGEBEFORESPEAK , 0 );
}
XML模式
hr = voice->Speak(
L"<sapi><voice required=\"Language=409\">Hello World</voice></sapi>",
SPF_IS_XML,
0 );
或
hr = voice->Speak(
L"<sapi><lang langid=\"409\">Hello World</lang></sapi>",
SPF_IS_XML,
0 );
手写模式
bool SetFirstFitNarrator( ISpVoice* voice, const WCHAR* language )
{
HRESULT hr;
ISpObjectToken* token;
CComPtr<IEnumSpObjectTokens> cpEnum;
hr = SpEnumTokens( SPCAT_VOICES, language, 0, &cpEnum );
if ( hr != S_OK )
return false;
while ( cpEnum->Next( 1, &token, NULL ) == S_OK )
{
// We have narrator handling this language, try it
HRESULT hr = voice->SetVoice( token );
if ( hr == S_OK )
{
// Some sanity tests, in most cases not nessesary.
// I'm using them to detect broken narrators.
// You can just
// return true;
// instead.
hr = voice->Speak( 0, SPF_PURGEBEFORESPEAK, 0 );
if ( hr == S_OK )
{
hr = voice->Speak( L" ", SPF_ASYNC | SPF_IS_NOT_XML, 0 );
if ( hr == S_OK )
{
// Narrator seems to work OK
retrun true;
}
}
}
// Alternatively you can collect narrators in some table
// and offer them to user for selection.
//
// This is how you can obtain user friendly description, eg.
// "Microsoft David Desktop - English (United States)"
//
// CSpDynamicString dstrDesc;
// hr = SpGetDescription( token, &dstrDesc );
// if ( hr == S_OK )
// {
// const WCHAR* user_friendly_description = dstrDesc;
}
// None of the narrators can handle given language
return false;
}
void Test()
{
// "Language=409" - means US English
if ( SetFirstFitNarrator( voice, L"Language=409" ) )
voice->Speak( L"hello world ", SPF_IS_NOT_XML, 0 );
else
{
MessageBox(
hwnd,
L"Unfortunately there is no narrator handling US English language.",
L"No narrator",
MB_OK | MB_ICONEXCLAMATION );
}
}
对于语言 ID,从 [MS-LCID]: Windows Language Code Identifier (LCID) Reference
下载 PDF
目前,我有一个文本到语音的代码,但我想更改代码,以便输出为英语,而不是目前的日语母语者。有没有熟悉这方面的人可以帮助我
// SAPIの初期化
if (FAILED(CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice)))
{
throw;
}
// Register events to detect
pVoice->SetInterest(SPFEI(SPEI_PHONEME) | SPFEI(SPEI_END_INPUT_STREAM),
SPFEI(SPEI_PHONEME) | SPFEI(SPEI_END_INPUT_STREAM));
pVoice->SetNotifyWindowMessage(hWnd, WM_USER, 0, 0); // subscribe message
// preprocessing to speak
pVoice->Speak( NULL , SPF_PURGEBEFORESPEAK , 0 );
}
XML模式
hr = voice->Speak(
L"<sapi><voice required=\"Language=409\">Hello World</voice></sapi>",
SPF_IS_XML,
0 );
或
hr = voice->Speak(
L"<sapi><lang langid=\"409\">Hello World</lang></sapi>",
SPF_IS_XML,
0 );
手写模式
bool SetFirstFitNarrator( ISpVoice* voice, const WCHAR* language )
{
HRESULT hr;
ISpObjectToken* token;
CComPtr<IEnumSpObjectTokens> cpEnum;
hr = SpEnumTokens( SPCAT_VOICES, language, 0, &cpEnum );
if ( hr != S_OK )
return false;
while ( cpEnum->Next( 1, &token, NULL ) == S_OK )
{
// We have narrator handling this language, try it
HRESULT hr = voice->SetVoice( token );
if ( hr == S_OK )
{
// Some sanity tests, in most cases not nessesary.
// I'm using them to detect broken narrators.
// You can just
// return true;
// instead.
hr = voice->Speak( 0, SPF_PURGEBEFORESPEAK, 0 );
if ( hr == S_OK )
{
hr = voice->Speak( L" ", SPF_ASYNC | SPF_IS_NOT_XML, 0 );
if ( hr == S_OK )
{
// Narrator seems to work OK
retrun true;
}
}
}
// Alternatively you can collect narrators in some table
// and offer them to user for selection.
//
// This is how you can obtain user friendly description, eg.
// "Microsoft David Desktop - English (United States)"
//
// CSpDynamicString dstrDesc;
// hr = SpGetDescription( token, &dstrDesc );
// if ( hr == S_OK )
// {
// const WCHAR* user_friendly_description = dstrDesc;
}
// None of the narrators can handle given language
return false;
}
void Test()
{
// "Language=409" - means US English
if ( SetFirstFitNarrator( voice, L"Language=409" ) )
voice->Speak( L"hello world ", SPF_IS_NOT_XML, 0 );
else
{
MessageBox(
hwnd,
L"Unfortunately there is no narrator handling US English language.",
L"No narrator",
MB_OK | MB_ICONEXCLAMATION );
}
}
对于语言 ID,从 [MS-LCID]: Windows Language Code Identifier (LCID) Reference
下载 PDF