Note
Please see Azure Cognitive Services for Speech documentation for the latest supported speech solutions.
Microsoft Speech Platform
ISpVoice::SetOutput
ISpVoice::SetOutput sets the current output object. The object may either be a stream, an audio device, or an object token for an output audio device. If pUnkOutput is NULL, the default audio device will be used.
<pre IsFakePre="true" xmlns="http://www.w3.org/1999/xhtml"> <strong>HRESULT SetOutput(</strong><a runat="server" href="https://msdn.microsoft.com/en-us/library/ms680509(v=vs.85).aspx"><strong>IUnknown</strong></a> *<em>pUnkOutput</em>, <strong> BOOL</strong> <em>fAllowFormatChanges</em> <strong>);</strong> </pre>
Parameters
- pUnkOutput
[in] IUnknown pointer to output object. The pointer must point to an object that implements ISpStreamFormat (a stream or audio device), or an object that implements ISpObjectToken. If a token is provided, this method will create the object described by the token and use it. If pUnkOutput is NULL, the default audio out device will be used. - fAllowFormatChanges
[in] Flag specifying whether the voice is allowed to change the format of the audio output object to match that of the engine, or a WAV stream being spoken. If FALSE, the voice will use the the Speech Platform's format converter to translate between the data being rendered and the format of the output object. This should be set to TRUE if using the default audio device and the output format is of no consequence. If pUnkOutput is an ISpStreamFormat object, fAllowFormatChanges is ignored. In this case, the voice instance will render the output audio data in the format of the specified stream to the application.
Return Values
Value | Description |
---|---|
S_OK | Function completed successfully. |
E_INVALIDARG | One or more parameters are invalid. |
SPERR_UNINITIALIZED | pUnkOutput is an uninitialized ISpStream object. |
E_OUTOFMEMORY | Exceeded available memory. |
Example:
The following is an example of how to enumerate all the available audio output devices registered under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech Server\v11.0\AudioOutput.
`
// Declare local identifiers: HRESULT hr = S_OK; CComPtr<ISpObjectToken> cpAudioOutToken; CComPtr<IEnumSpObjectTokens> cpEnum; CComPtr<ISpVoice> cpVoice; ULONG ulCount = 0;`// Create the Speech Platform 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. }