다음을 통해 공유


ISpVoice::SetVoice (Windows Embedded CE 6.0)

1/6/2010

This method sets the identity of the voice used for text synthesis. ISpVoice typically uses the default voice, which is set through the Speech Control Panel.

Syntax

HRESULT SetVoice(
  ISpObjectToken* pToken
);

Parameters

  • pToken
    [in] Pointer to an ISpObjectToken implementation representing the token that describes the requested voice. If pToken is NULL, the system default voice is used.

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.

Remarks

Changing the voice selection will preserve the same volume and rate levels for a ISpVoice object.

Example

The following is an example to enumerate all the available voices registered under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices.

HRESULT                             hr = S_OK;
CComPtr<ISpObjectToken>             cpVoiceToken;
CComPtr<IEnumSpObjectTokens>        cpEnum;
CComPtr<ISpVoice>                   cpVoice;
ULONG                               ulCount = 0;
// Create the SAPI voice
if(SUCCEEDED(hr))
    hr = cpVoice.CoCreateInstance( CLSID_SpVoice ); 
//Enumerate the available voices 
if(SUCCEEDED(hr))
    hr = SpEnumTokens(SPCAT_VOICES, NULL, NULL, &cpEnum);
//Get the number of voices
if(SUCCEEDED(hr))
    hr = cpEnum->GetCount(&ulCount);
// Obtain a list of available voice tokens, set the voice to the token, and
call Speak
while (SUCCEEDED(hr) && ulCount -- )
{
    cpVoiceToken.Release();
    if(SUCCEEDED(hr))
        hr = cpEnum->Next( 1, &cpVoiceToken, NULL );
    if(SUCCEEDED(hr))
        hr = cpVoice->SetVoice(cpVoiceToken);
    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