Note

Please see Azure Cognitive Services for Speech documentation for the latest supported speech solutions.

Microsoft Speech Platform

ISpVoice::SetVoice

ISpVoice::SetVoice specifies the voice token to use for speech synthesis.

<pre IsFakePre="true" xmlns="http://www.w3.org/1999/xhtml"> <strong>HRESULT SetVoice(</strong><a runat="server" href="jj127672(v=msdn.10).md"><strong>ISpObjectToken</strong></a> *<em>pToken</em> <strong>);</strong> </pre>

Parameters

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

Return Values

Value Description
S_OK Function completed successfully.
E_INVALIDARG One or more parameters are invalid.

Remarks

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

If no voice is specified, synthesis operations use the default voice, which is specified at the following registry key: HKEY_CURRENT_USER\Software\Microsoft\Speech Server\v11.0\Voices\DefaultTokenId.

Example

The following example enumerates all the installed voices registered under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech Server\v11.0\Voices.

`

// Declare local identifiers:
HRESULT                        hr = S_OK;
CComPtr<ISpObjectToken>        cpVoiceToken;
CComPtr<IEnumSpObjectTokens>   cpEnum;
CComPtr<ISpVoice>              cpVoice;
ULONG                          ulCount = 0;

// Create the voice. hr = cpVoice.CoCreateInstance(CLSID_SpVoice);

if (SUCCEEDED (hr)) { // Enumerate the installed voices. hr = SpEnumTokens(SPCAT_VOICES, NULL, NULL, &cpEnum;); }

if (SUCCEEDED (hr)) { // Get the number of voices. hr = cpEnum->GetCount(&ulCount;); }

// Obtain a list of installed 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 ); }

}

if (SUCCEEDED (hr)) { // Do more stuff here. }

`