Pregunta

So, I have a program where I use SAPI like this:

ISpVoice * pVoice = NULL;

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

HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void     **)&pVoice);
if( SUCCEEDED( hr ) )
{
    hr = pVoice->Speak(L"I can talk!", SPF_IS_XML, NULL);
}

But I want to declare a variable and then have the sapi say them. How do I do that?

Thanks

¿Fue útil?

Solución

Use a std::wstring. Assuming you want the user to input what to say (barring a textbox and a button):

std::cout << "Enter lines of text to speak:\n";
for (std::wstring text; std::wcin >> text;) {
    if (FAILED(hr = pVoice->Speak(text.c_str(), SPF_IS_XML, NULL))) {
        std::cout << "Sorry, the text could not be spoken. The error code is " << hr << '\n';
    }
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top