Using Microsoft SAPI Text To Speech with SSML

0

I understand that SAPI can use SSML with the SPF_PARSE_SSML however I have not been able to get this to work, always getting a SPERR_UNSUPPORTED_FORMAT error. Is something else needed to enable it? Special voices, some extra flag?

I tried setting different voices explicitly (my Win 10 machine seems to have a "Microsoft Hazel Desktop" and "Microsoft Zira Desktop"), different tags, with/without XML declaration.

#include <Windows.h>
#include <sapi.h>
#include <stdexcept>
int main()
{
    HRESULT hr;
    if (FAILED(hr = CoInitialize(NULL)))
        return 1;
    ISpVoice *voice;
    if (FAILED(hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)& voice)))
        return 1;
    // Works
    const wchar_t *text = L"Testing SAPI support for S S M L";
    if (FAILED(hr = voice->Speak(text, SPF_IS_NOT_XML, NULL)))
        return 1;
    // Fails 0x80045003 SPERR_UNSUPPORTED_FORMAT
    const wchar_t *ssml =
        L"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
        L"<speak xmlns=\"http://www.w3.org/2001/10/synthesis\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" version=\"1.0\">\n"
        L"Testing SAPI support for <break time=\"500ms\"/>S<break time=\"500ms\"/>S<break time=\"500ms\"/>M<break time=\"500ms\"/>L.\n"
        L"</speak>";
    if (FAILED(hr = voice->Speak(ssml, SPF_IS_XML | SPF_PARSE_SSML, NULL)))
        return 1;
    return 0;
}
c++
windows
sapi
asked on Stack Overflow Jun 21, 2019 by Fire Lancer

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0