当前位置: 首页>>代码示例>>C++>>正文


C++ ISpVoice::SetVoice方法代码示例

本文整理汇总了C++中ISpVoice::SetVoice方法的典型用法代码示例。如果您正苦于以下问题:C++ ISpVoice::SetVoice方法的具体用法?C++ ISpVoice::SetVoice怎么用?C++ ISpVoice::SetVoice使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ISpVoice的用法示例。


在下文中一共展示了ISpVoice::SetVoice方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: RequireLanguage

//请求指定语言的语音
bool SpBox::RequireLanguage(LPCWSTR langid)
{
	IEnumSpObjectTokens*    pEnum;				//语音总选择
	ISpObjectToken*			pVoiceToken;		//当前语音选择
	ULONG					ulCount = 0;		//选择个数
	WCHAR*					pVoiceLang;			//语音LangId
	WCHAR*					pVoiceText;			//语音说明文字

	HRESULT hr = SpEnumTokens(SPCAT_VOICES, NULL, NULL, &pEnum);
	if (SUCCEEDED(hr))
	{
		hr = pEnum->GetCount(&ulCount);
	}

	while (SUCCEEDED(hr) && ulCount--){

		if (SUCCEEDED(hr))
			pEnum->Next(1, &pVoiceToken, 0);
		
		if (SUCCEEDED(hr))
			hr = SpGetLanguage(pVoiceToken, &pVoiceLang);

		if (SUCCEEDED(hr) && !_wcsnicmp(pVoiceLang, langid, 3))
		{
			Token = pVoiceToken;
			VoiceObj->SetVoice(Token);
			SpGetDescription(Token, &pVoiceText, 0);
			Description = pVoiceText;
			return true;
		}
	}
	return false;
}
开发者ID:df32,项目名称:TTS,代码行数:34,代码来源:main.cpp

示例2: speak

bool speak(wchar_t * text, wchar_t * pszReqAttribs)
{
	ISpVoice * pVoice = NULL;
	HRESULT stInitializing = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice);
	if (SUCCEEDED(stInitializing))
	{
		ISpObjectToken* cpToken(NULL);
		HRESULT stTokenFinding = SpFindBestToken(SPCAT_VOICES, pszReqAttribs, L"", &cpToken);
		if (SUCCEEDED(stTokenFinding))
		{
			HRESULT stVoiceSetting = pVoice->SetVoice(cpToken);
			if (SUCCEEDED(stVoiceSetting))
			{
				HRESULT stSpoken = pVoice->Speak(text, 0, NULL);
				if (SUCCEEDED(stSpoken))
				{
					cpToken->Release();
					cpToken = NULL;

					pVoice->Release();
					pVoice = NULL;

					return true;
				}
				else
				{
					cpToken->Release();
					cpToken = NULL;

					pVoice->Release();
					pVoice = NULL;

					wcout << "Error, I couldn't play this text " << text << endl;
					return false;
				}
			}
			else
			{
				cpToken->Release();
				cpToken = NULL;

				pVoice->Release();
				pVoice = NULL;

				wcout << "Error, I can't set this voice " << pszReqAttribs << endl;
				return false;
			}
		}
		else
		{
			pVoice->Release();
			pVoice = NULL;

			wcout << "Error, I can't find this voice " << pszReqAttribs << endl;
			return false;
		}
	}
	else {
		wcout << "Error, I can't create Voice instance" << endl;
		return false;
	}
}
开发者ID:shikaiwen,项目名称:TextToSpeech,代码行数:62,代码来源:speak.cpp

示例3: test


//.........这里部分代码省略.........
				//hr = SPERR_UNITIALIZED;
			}
		}
		// Set up an audio input stream using a .wav file and set the recognizer's input.
		CComPtr<ISpStream> cpInputStream;

		if (SUCCEEDED(hr))
		{
			hr = SPBindToFile(L"Test.wav", SPFM_OPEN_READONLY, &cpInputStream);
		}

		if (SUCCEEDED(hr))
		{
			hr = cpRecognizer->SetInput(cpInputStream, TRUE);
		}

		// Create a new grammar and load an SRGS grammar from file.
		//CComPtr<ISpRecoGrammar> cpGrammar;

		if (SUCCEEDED(hr))
		{
			hr = cpContext->CreateGrammar(0, &cpGrammar);
		}

		if (SUCCEEDED(hr))
		{
			hr = cpGrammar->LoadCmdFromFile(L"grammar.grxml", SPLO_STATIC);
		}

		// Set all top-level rules in the new grammar to the active state.
		if (SUCCEEDED(hr))
		{
			hr = cpGrammar->SetRuleState(NULL, NULL, SPRS_ACTIVE);
		}

		// Finally, set the recognizer state to active to begin recognition.
		if (SUCCEEDED(hr))
		{
			hr = cpRecognizer->SetRecoState(SPRST_ACTIVE_ALWAYS);
		}

		 hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void     **)&pVoice);
		if (SUCCEEDED(hr)) {
			hr = SpEnumTokens(SPCAT_VOICES, L"Gender=Female", NULL, &pEnum);
			if (SUCCEEDED(hr))
			{
				// Get the number of voices.
				hr = pEnum->GetCount(&ulCount);
			}

			// Obtain a list of available voice tokens, set
			// the voice to the token, and call Speak.
			while (SUCCEEDED(hr) && ulCount--)			{
				if (pVoiceToken != nullptr) {
					pVoiceToken->Release();
				}

				if (SUCCEEDED(hr))
				{
					hr = pEnum->Next(1, &pVoiceToken, NULL);
				}

				if (SUCCEEDED(hr))
				{
					hr = pVoice->SetVoice(pVoiceToken);
				}

				if (SUCCEEDED(hr))
				{
					wchar_t* start = L"<?xml version=\"1.0\" encoding=\"ISO - 8859 - 1\"?><speak version = \"1.0\" xmlns = \"http://www.w3.org/2001/10/synthesis\"	xml:lang = \"en-US\">";
					wchar_t* end = L"</speak>";
					const wchar_t *xml = L"<voice required = \"Gender=Male\"> hi! <prosody pitch=\"fast\"> This is low pitch. </prosody><prosody volume=\"x - loud\"> This is extra loud volume. </prosody>";
					wstring s = start;
					s += xml;
					s += end;
					
					hr = pVoice->Speak(xml, SPF_IS_XML| SPF_ASYNC, 0);
					//hr = pVoice->Speak(L"How are you?", SPF_DEFAULT, NULL);
				}

			}
			/*
			if (SUCCEEDED(hr)) {
				hr = pEnum->Next(1, &pVoiceToken, NULL);
				if (SUCCEEDED(hr)) {
					hr = pVoice->SetVoice(pVoiceToken);
					// Set the output to the default audio device.
					if (SUCCEEDED(hr)) {
						hr = pVoice->SetOutput(NULL, TRUE);
						if (SUCCEEDED(hr)) {
							hr = pVoice->Speak(L"Hello, world!", SPF_DEFAULT, 0);
						}
					}
				}
			}
			*/
			pVoice->Release();
		}
		::CoUninitialize();
	}
开发者ID:shavmark,项目名称:MainSketch,代码行数:101,代码来源:2552software.cpp


注:本文中的ISpVoice::SetVoice方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。