Share via


ISpVoice::SetOutput

Other versions of this page are also available for the following:

Windows Mobile Not SupportedWindows Embedded CE Supported

8/28/2008

This method sets the current output object. The object can either be a stream, audio device, or an object token for an output audio device. If pUnkOutput is NULL then the default audio device will be used.

Syntax

HRESULT SetOutput(
  IUnknown* pUnkOutput,
  BOOL fAllowFormatChanges
);

Parameters

  • pUnkOutput
    [in] Pointer to IUnknown for the output object. This object must implement ISpStreamFormat (a stream or audio device) or ISpObjectToken. If a token is provided, this method creates the object described by the token and uses it. If pUnkOutput is NULL, the default audio out device will be used.
  • fAllowFormatChanges
    [in] Pointer to a value specifying if 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. Set this value to TRUE if using the default audio device and the output format is of no consequence. Set the value to FALSE to indicate that the voice will use the SAPI format converter to translate between the data being rendered and the format of the output object. If pUnkOutput is an ISpStreamFormat object, then 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 Value

The following table shows the possible return values.

Value Description

S_OK

Function completed successfully.

E_INVALIDARG

One or more arguments 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\AudioOutput.

HRESULT                  hr = S_OK;
CComPtr        cpAudioOutToken;
CComPtr        cpEnum;
CComPtr        cpVoice;
ULONG          ulCount = 0;
// Create the SAPI voice
if(SUCCEEDED(hr))
    hr = cpVoice.CoCreateInstance( CLSID_SpVoice ); 
//Enumerate the available audio output devices 
if(SUCCEEDED(hr))
    hr = SpEnumTokens( SPCAT_AUDIOOUT, NULL, NULL, &cpEnum );
//Get the number of audio output devices
if(SUCCEEDED(hr))
    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 ); 
}

Requirements

Header sapi.h, sapi.idl
Library sapilib.lib
Windows Embedded CE Windows CE .NET 4.1 and later

See Also

Reference

ISpVoice
SAPI Interfaces