赞
踩
- 微软官方例子,枚举所有输出设备,并且设置给ISpVoice:
- // Declare local identifiers:
- HRESULT hr = S_OK;
- CComPtr<ISpObjectToken> cpAudioOutToken;
- CComPtr<IEnumSpObjectTokens> cpEnum;
- CComPtr<ISpVoice> cpVoice;
- ULONG ulCount = 0;
-
- // Create the SAPI voice.
- hr = cpVoice.CoCreateInstance(CLSID_SpVoice);
-
- if (SUCCEEDED (hr))
- {
- // Enumerate the available audio output devices.
- hr = SpEnumTokens( SPCAT_AUDIOOUT, NULL, NULL, &cpEnum; );
- }
-
- if (SUCCEEDED (hr))
- {
- // Get the number of audio output devices.
- hr = cpEnum->GetCount( &ulCount; );
- }
-
- // Obtain a list of available audio output tokens,
- // set the output to the token, and call Speak.
- while (SUCCEEDED(hr) && ulCount--)
- {
- if (SUCCEEDED (hr))
- {
- hr = cpEnum->Next( 1, &cpAudioOutToken;, NULL );
- }
-
- if (SUCCEEDED (hr))
- {
- hr = cpVoice->SetOutput( cpAudioOutToken, TRUE );
- }
-
- if (SUCCEEDED (hr))
- {
- hr = cpVoice->Speak( L"How are you?", SPF_DEFAULT, NULL );
- }
- }
-
- if (SUCCEEDED (hr))
- {
- // Do more stuff here.
- }
- 把输出设备显示到ComboBox里:
- HRESULT hr = SpInitTokenComboBox( hWndComboAudioOut , SPCAT_AUDIOOUT);
- VERIFY(SUCCEEDED(hr))
-
- CComPtr<ISpVoice> cpVoice;
- cpVoice.CoCreateInstance( CLSID_SpVoice );
- VERIFY(SUCCEEDED(hr))
- ISpObjectToken *pTokenAudioOut=nullptr;
- VERIFY(SUCCEEDED(new_voice.cpVoice->GetOutputObjectToken(&pTokenAudioOut)));
- CSpDynamicString dstrDesc;
- VERIFY(SUCCEEDED(SpGetDescription(pTokenAudioOut, &dstrDesc)));
- ::SendMessageW(hWndComboAudioOut, CB_SELECTSTRING, 0, (LPARAM)dstrDesc.m_psz);
-
-
-
- 从ComboBox里的选中文字设置TTS输出设备
- ISpObjectToken* pToken = SpGetCurSelComboBoxToken( hWndCombo );
- ISpVoice->SetOutPut(pToken)直接使用
-
-
- 还可以通过Token获得ID
- WCHAR wszTolenName[256] = L"";
- WCHAR *pWsz = NULL ;
- pToken->GetId( &pWsz ) ;
-
-
- //再把ID还原成Token
- CComPtr<IEnumSpObjectTokens> cpEnum;
- CStringW strIdW( pWsz ) ;
- CComPtr<ISpObjectToken> cpVoiceToken
- HRESULT hr = SpGetTokenFromId(strIdW, &cpVoiceToken);
- ISpVoice->SetOutPut(cpVoiceToken)直接使用
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。