c++windowstext-to-speechsapi

How to send mp3 data to ISpTTSEngineSite Write Api


I am trying to implement a TTS Engine using SAPI 5 on Windows. To make it simple, assume that I have a model trained which converts text to an mp3 file. I need to stream/load this mp3 data to the ISpTTSEngineSite Write Api, but i get this error code "-2147024809"

std::ifstream file("C:\\Sample.mp3", std::ios::binary | std::ios::ate);
std::streamsize size = file.tellg();
file.seekg(0, std::ios::beg);

std::vector<char> buffer(size);
file.read(buffer.data(), size))

ULONG pcbWritten = 0;
hr = pOutputSite->Write(buffer.data(), size, &pcbWritten);

return result of Write call I get is -2147024809, I couldn't get the meaning of this and obviously nothing got written and pcbWritten is 0 after the call.


Solution

  • Answering to my question:

    The audio should be raw audio data, which the Write api is expecting. As mentioned by @botje in the comments, .wav file is best suited.

    The above logic still holds good as long it is Sample.wav and not .mp3.

    For others, if mp3 is still the only option, there is a msdn doc on how to decode audio, https://learn.microsoft.com/en-us/windows/win32/medfound/tutorial--decoding-audio