通过SSML使用Microsoft SAPI文本语音转换

时间:2019-06-21 16:18:42

标签: c++ windows sapi

我知道SAPI可以将SSML与SPF_PARSE_SSML一起使用,但是我无法使其正常工作,总是出现SPERR_UNSUPPORTED_FORMAT错误。需要启用其他功能吗?特殊的声音,一些额外的标志?

我尝试显式设置不同的声音(我的Win 10机器似乎具有“ Microsoft Hazel Desktop”和“ Microsoft Zira Desktop”),不同的标记,带有/不带有XML声明。

#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;
}

0 个答案:

没有答案