Pregunta

I don't realise how i can set some different voice? Yes! I read MSDN, and it didn't help

ISpVoice * pVoice = NULL, * pv1 = NULL;

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


HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice);
if( SUCCEEDED( hr ) )
{
    pVoice->SetVolume(100);
    //pVoice->SetVoice();
    hr = pVoice->Speak(L"Hello papa", SPF_IS_XML, NULL);
    pVoice->Release();
    pVoice = NULL;
}
¿Fue útil?

Solución

Voices in SAPI are selected via ISpObjectToken. Typically one uses the helper function SpFindBestToken to find the best token, and then use ISpVoice::SetVoice() to select that token:

ISpObjectToken* cpToken(NULL);
SpFindBestToken(SPCAT_VOICES, szRequiredAttribs, L"", &cpToken);
pVoice->SetVoice(cpToken);
cpToken->Release();

Now, the only issue is what you need to pass for szRequiredAttribs. This needs to be a semicolon-delimited list of attributes. The best documentation for SAPI voice attributes is in the Object Tokens and Registry Settings whitepaper, specifically, the Voices section. There, it says that all voices must support the following attributes:

  • Vendor (TTS engine Vendor name)
  • Language (The LCID in hex of language this engine speaks)
  • Gender (Value should be "Male" if Male voice, "Female" if female)
  • VendorPreferred (If this is the Default voice for the vendor named in vendor)
  • Name (String representing language independent name)

This is not an exclusive listing of attributes; other attributes may be defined by the vendor.

So, if you wanted the preferred voice from Microsoft, you would set szRequiredAttribs = L"vendor=microsoft;vendorpreferred". If you wanted a male voice (from any vendor), set szRequiredAttribs = L"gender=male".

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top