RDoonds RDoonds - 1 year ago 93
Linux Question

Text-To-Speech a String or Varable value (PicoTTS)

I am working on Text-To-Speech and trying to generate audio file. I am currently working on PicoTTS on linux (Raspberry Pi).
The following command :

system("pico2wave -w res.wav "Hello to all of you");
system("aplay res.wav");

The above code does play "Hello to all of you". But I want to play content stored in string, wstring (reading a variable).

I tried

sprintf(buf, "Hello to all of you");
system("pico2wave -w res.wav buf);
system("aplay res.wav");

It played buf and not the value stored in buf.
Can someone please throw some light on this or recommend me to use TTS other than Pico that accepts string value. It would be a great help for me if it can play value as well.
I am working on Raspberry Pi 2 and using C++. Any input is valuable.

Answer Source

You need to concatenate the string before the call to system and then use that concatenated string for the system call. It would look something like

std::string command = "pico2wave -w res.wav ";
std::string text_to_say;
// get input from user and store it into text_to_say
command += text_to_say;
// now command is pico2wave -w res.wav whatever the user entered
system("aplay res.wav");

If whatever the user entered needs to be wrapped in quotes like "whatever the user entered" then

command += text_to_say;


command += "\"" + text_to_say + "\"";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download