gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:45:17 24 4
gpt4 key购买 nike

我正在研究文本转语音并尝试生成音频文件。我目前正在 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。如果它也能发挥值(value),那对我来说将是一个很大的帮助。我正在使用 C++ 开发 Raspberry Pi 2。

最佳答案

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

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 + "\"";

关于c++ - 文本转语音字符串或变量值 (PicoTTS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37887495/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com