文本转语音字符串或变量值 (PicoTTS)

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

我正在研究文本转语音并尝试生成音频文件。我目前正在 linux (Raspberry Pi) 上开发 PicoTTS。 以下命令:

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

上面的代码确实起到了"Hello to all of you"的作用。但是我想播放存储在string、wstring(读取一个变量)中的内容。

我试过了

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

它播放的是buf,而不是buf中存储的值。 有人可以对此有所了解或建议我使用接受字符串值的 Pico 以外的 TTS。如果它也能发挥价值,那对我来说将是一个很大的帮助。 我正在研究 Raspberry Pi 2 并使用 C++。

您需要在调用系统之前连接字符串,然后将连接后的字符串用于系统调用。它看起来像

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(command.c_str());
system("aplay res.wav");

如果 whatever the user entered 需要用引号引起来,例如 "whatever the user entered" 那么

command += text_to_say;

变成

command += "\"" + text_to_say + "\"";

我想可以工作(注意:代码未经测试)

// command string
std::string cmd("pico2wave -w res.wav ");

// create the message in some way
std::string msg("Hello to all of you");

// call to system
system((cmd+"\""+msg+"\"").c_str());