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


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

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


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

示例1: main

int main(int argc, char* argv[])
{
	ISpVoice * pVoice = NULL;

	if (FAILED(::CoInitialize(NULL)))
		return FALSE;

	HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice);
	if (SUCCEEDED(hr))
	{
		hr = pVoice->Speak(L"Здравствуйте", 0, NULL);

		// Change pitch
		hr = pVoice->Speak(L"Вы меня  <pitch middle = '-10'/> слышите?", SPF_IS_XML, NULL);
		pVoice->Release();
		pVoice = NULL;
	}
	::CoUninitialize();
	return TRUE;
}
开发者ID:ohotass,项目名称:SAPI_example,代码行数:20,代码来源:ConsoleApplication2.cpp

示例2: main

int main(int argc, char* argv[])
{
	ISpVoice * pVoice = NULL;

	if (FAILED(::CoInitialize(NULL)))
		return FALSE;

	HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice);
	if (SUCCEEDED(hr))
	{
		//hr = pVoice->Speak(L"Hello Brad <pitch middle = '-10'/> gwaps", SPF_IS_XML, NULL);
		hr = pVoice->Speak(L"Myca needs vog", 0, NULL);
		//hr = pVoice->Speak(L"cliff golem tashed", 0, NULL);
		//hr = pVoice->Speak(L"Invis failing, invis failing", 0, NULL);

		//hr = pVoice->Speak(L"charm break, <pitch middle = '-10'/> beat down imminent", SPF_IS_XML, NULL);
		hr = pVoice->Speak(L"pet is loose, <pitch middle = '+10'/> pet is loose", 8, NULL);
		pVoice->Release();
		pVoice = NULL;
	}

	::CoUninitialize();
	return TRUE;
}
开发者ID:kocubinski,项目名称:yaqp,代码行数:24,代码来源:cli.cpp

示例3: speechOutput

void Speech::speechOutput(const char* str) {

	ISpVoice* pVoice = NULL;
	ISpObjectToken* cpAudioOutToken;
	IEnumSpObjectTokens* cpEnum;
	ULONG ulCount = 0;

    if (FAILED(::CoInitialize(NULL)))
        return;

    HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice);   

	if (SUCCEEDED (hr))	{
	   hr = SpEnumTokens( SPCAT_AUDIOOUT, NULL, NULL, &cpEnum);
	}
	if (SUCCEEDED (hr))	{
	   hr = cpEnum->GetCount( &ulCount);
	}

	while (SUCCEEDED(hr) && ulCount--) {
		hr = cpEnum->Next( 1, &cpAudioOutToken, NULL );
		wchar_t* deviceId = nullptr;
		if(SUCCEEDED(hr)) {
			hr = cpAudioOutToken->GetStringValue(L"DeviceId", &deviceId);
			if(wcscmp(outputDevice, deviceId) == 0) break;
		}
	}

	if (SUCCEEDED (hr))	{
		hr = pVoice->SetOutput( cpAudioOutToken, TRUE );
	}

	if(SUCCEEDED(hr)) {		
		const size_t cSize = strlen(str)+1;
		wchar_t* wc = new wchar_t[cSize];
		size_t ret;
		mbstowcs_s (&ret, wc, cSize, str, cSize);

		hr = pVoice->Speak(wc, NULL, NULL);        
	
		pVoice->Release();
        pVoice = NULL;
	}
	
	cpEnum->Release();
	cpAudioOutToken->Release();
    ::CoUninitialize();
}
开发者ID:xeedness,项目名称:Arma2PlayerMonitor,代码行数:48,代码来源:speech.cpp

示例4: Speak

/**********************************************************************
* CTextRun::Speak *
*-----------------*
*	Description:  
*		Speaks the text associated with this CTextRun using TTS.
*
* 	Return:
*		S_OK
*       Return value of ITextRange::GetText()
*       Return value of ISpVoice::Speak()
**********************************************************************/
HRESULT CTextRun::Speak( ISpVoice &rVoice )
{
    _ASSERTE( m_cpTextRange );
    if ( !m_cpTextRange )
    {
        return E_UNEXPECTED;
    }

    // Get the text and speak it.
    BSTR bstrText;
    HRESULT hr = m_cpTextRange->GetText( &bstrText );
    if( SUCCEEDED( hr ) )
    {
        hr = rVoice.Speak( bstrText, SPF_ASYNC, NULL );

        ::SysFreeString( bstrText );
    }
    return hr;
} /* CTextRun::Speak */
开发者ID:DavidEzell,项目名称:source-sdk-2013,代码行数:30,代码来源:textrun.cpp

示例5: say

bool TextToSpeech::say(string wordToSay)
{
	//convert string to wstring to use with speech function
	wstring wstr(wordToSay.begin(), wordToSay.end());

	ISpVoice * pVoice = NULL;

	if (FAILED(::CoInitialize(NULL)))
		return FALSE;

	HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice);
	if (SUCCEEDED(hr))
	{
		long rate = -5;
		pVoice->SetRate(rate);
		hr = pVoice->Speak(wstr.c_str(), 0, NULL);
		pVoice->Release();
		pVoice = NULL;
	}

	::CoUninitialize();
	return TRUE;
}
开发者ID:Nes-Gonzalez,项目名称:Vocabulary-Game,代码行数:23,代码来源:TextToSpeech.cpp

示例6: 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

示例7: main

int main(int argc, char **argv)
{
    ISpVoice *pVoice = NULL;
    WCHAR line_buffer[LINE_LENGTH];
    bool exitflag = FALSE;
    int counter = 0;

    if (FAILED(::CoInitialize(NULL)))
    {
        printf("ERROR: Couldn't initialise COM.\n");
        return FALSE;
    }

    HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice);
    if( SUCCEEDED( hr ) )
    {
        // For some reason, if you don't do this, speech cuts out
        // (only on first announcement)...
        pVoice->Speak(L" ", SPF_IS_NOT_XML, NULL);

        // Main loop...
        while( ! exitflag )
        {
            for(counter = 0; counter < LINE_LENGTH; counter++ )
            {
                // Fill up the buffer...
                line_buffer[counter] = getwchar();

                // Check for exit condition...
                if( line_buffer[counter] == WEOF )
                {
                    line_buffer[counter] = 0;
                    exitflag = TRUE;
                    break;
                }

                // Break at end of line...
                if( line_buffer[counter] == L'\n' )
                {
                    line_buffer[counter] = 0;
                    break;
                }
            }

            counter = 0;

            // Should the synth's UI be displayed?
            if ( line_buffer == L"DisplayUI" )
            {
                int supported = 0;
                hr = pVoice->IsUISupported(SPDUI_EngineProperties, NULL, NULL, &supported);
                if( SUCCEEDED( hr ) && supported )
                {
                    hr = pVoice->DisplayUI(NULL, NULL, SPDUI_EngineProperties, NULL, NULL);
                    if( ! SUCCEEDED( hr ) )
                    {
                        pVoice->Speak(L"There was an error displaying the properties window.\n", SPF_IS_NOT_XML|SPF_ASYNC|SPF_PURGEBEFORESPEAK, NULL);
                    }
                }
                else
                {
                    pVoice->Speak(L"Your current voice doesn't support a properties window.\n", SPF_IS_NOT_XML|SPF_ASYNC|SPF_PURGEBEFORESPEAK, NULL);
                }
            }

            // Was the message high-priority?
            if( line_buffer[0] == L'!' )
            {
                line_buffer[0] = L' ';
                pVoice->Speak(line_buffer, SPF_IS_NOT_XML|SPF_ASYNC|SPF_PURGEBEFORESPEAK, NULL);
            }
            else
            {
                pVoice->Speak(line_buffer, SPF_IS_NOT_XML|SPF_ASYNC, NULL);
            }
        }

        // Allow the user to hear the rest of the speech buffer...
        pVoice->Speak(L" ", SPF_IS_NOT_XML, NULL);

        pVoice->Release();
        pVoice = NULL;
    }
    else
    {
        printf("ERROR: Couldn't initialise SAPI 5.1.\n");
    }

    ::CoUninitialize();
    return TRUE;
}
开发者ID:philogus,项目名称:agrip,代码行数:91,代码来源:ag_say.cpp

示例8: say

void TextToSpeechPrivate::say(const QString &text) {
	if (pVoice) {
		pVoice->Speak((const wchar_t *) text.utf16(), SPF_ASYNC, NULL);
	}
}
开发者ID:ArminW,项目名称:re-whisper,代码行数:5,代码来源:TextToSpeech_win.cpp

示例9: test


//.........这里部分代码省略.........
					switch (spevent.eEventId)
					{
					case SPEI_RECOGNITION:
					{
						// Retrieve the recognition result and output the text of that result.
						ISpRecoResult* pResult = spevent.RecoResult();

						LPWSTR pszCoMemResultText = NULL;
						hr = pResult->GetText(SP_GETWHOLEPHRASE, SP_GETWHOLEPHRASE, TRUE, &pszCoMemResultText, NULL);

						if (SUCCEEDED(hr))
						{
							wprintf(L"Recognition event received, text=\"%s\"\r\n", pszCoMemResultText);
						}

						// Also retrieve the retained audio we requested.
						CComPtr<ISpStreamFormat> cpRetainedAudio;

						if (SUCCEEDED(hr))
						{
							hr = pResult->GetAudio(0, 0, &cpRetainedAudio);
						}

						// To demonstrate, we'll speak the retained audio back using ISpVoice.
						CComPtr<ISpVoice> cpVoice;

						if (SUCCEEDED(hr))
						{
							hr = cpVoice.CoCreateInstance(CLSID_SpVoice);
						}

						if (SUCCEEDED(hr))
						{
							hr = cpVoice->SpeakStream(cpRetainedAudio, SPF_DEFAULT, 0);
						}

						if (NULL != pszCoMemResultText)
						{
							CoTaskMemFree(pszCoMemResultText);
						}

						break;
					}
					}
				}

				break;
			}
			case WAIT_OBJECT_0 + 1:
			case WAIT_TIMEOUT:
			{
				// Exit event or timeout; discontinue the speech loop.
				fContinue = FALSE;
				//break;
			}
			}
		}

	CoUninitialize();

		CComPtr <ISpVoice>		cpVoice;
		CComPtr <ISpStream>		cpStream;
		CSpStreamFormat			cAudioFmt;

		//Create a SAPI Voice
		hr = cpVoice.CoCreateInstance(CLSID_SpVoice);
开发者ID:shavmark,项目名称:MainSketch,代码行数:67,代码来源:2552software.cpp

示例10: Speak

	HRESULT Speak(LPCWSTR pwcs)
	{
		UnPause();
		return VoiceObj->Speak(pwcs, Flags, 0);
	}
开发者ID:df32,项目名称:TTS,代码行数:5,代码来源:main.cpp

示例11: main

int main(int argc, char* argv[])
{
	Arguments arguments(argc, argv);

	//Initialize Pocketsphinx
	mic_data_t mic;

	continuous_init(arguments, mic);

	//Initialize Voice
	ISpVoice * pVoice = NULL;

	if (FAILED(::CoInitialize(NULL)))
		return FALSE;

	HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice);

	if (SUCCEEDED(hr))
		std::cout << "Speech Initialized" << std::endl;

	//Initialize Rebecca
	AimlFacade aiml;
	GraphBuilder &builder = aiml.getGraphBuilder();
	myCallBacks callback;
	builder.setCallBacks(&callback);

	rebecca_init(arguments, builder);

	//Main code
	try
	{
		/*
		* Send a initial conversation of "connect" to
		* annotated alice and get the response.
		*/
		StringPimpl response = builder.getResponse("connect");

		/*
		* Get the botName which should be Rebecca since that is
		* the name give in the configuration file properties.xml
		* which we parsed above.
		*/
		string botName = builder.getBotPredicate("name").c_str();

		//Send the initial opening line of the bot
		cout << botName << " says: " << response.c_str() << endl;
		hr = pVoice->Speak(s2ws(response.c_str()).c_str(), 0, NULL);
		pVoice->WaitUntilDone(15000);

		/*
		* The main loop to get the input
		* from the user until the user types '/exit'
		*/
		while (true)
		{
			//getUtterance(mic);
			//string input = string(mic.hyp);
			string input;
			getline(cin, input);

			if (input == "/exit" || input == "GOOD NIGHT")
			{
				/*
				* The user wants to exit so break
				* out of the while(true) loop
				*/
				continuous_exit(mic);
				pVoice->Release();
				pVoice = NULL;
				::CoUninitialize();
				break;
			}
			else //The user gave an input to the bot
			{
				//Here we get some internal Rebecca information.
				cout << endl
					<< "Internal information:" << endl
					<< "=====================" << endl
					<< input << " : "
					<< builder.getThat().c_str() << " : "
					<< builder.getTopic().c_str() << endl;

				/*
				* Ahhh finally.  We give the user input to Rebecca Aiml's loaded
				* AIML and get the response back.
				*/
				StringPimpl response = builder.getResponse(input.c_str());

				cout << "=====================" << endl << endl;

				//Print out what Rebecca says.
				cout << botName << " says: " << response.c_str() << endl;
				hr = pVoice->Speak(s2ws(response.c_str()).c_str(), 0, NULL);
				pVoice->WaitUntilDone(15000);
			}
		}
	}
	catch (Exception &e)
	{
		cout << "[An unknown exception occured, Terminating program]" << endl;
//.........这里部分代码省略.........
开发者ID:sleimanf,项目名称:aibot,代码行数:101,代码来源:aibot.cpp


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