21int main(
int argc,
char** argv)
26 std::string language =
"en";
27 std::string voice =
"auto";
36 cfg.
put(
"device",
"kokoroSpeechSynthesizer");
37 cfg.
put(
"language", language);
38 cfg.
put(
"voice", voice);
39 cfg.
put(
"speed", 1.0);
40 cfg.
put(
"pitch", 0.0);
42 const char* kokoroPython = std::getenv(
"KOKORO_PYTHON");
43 if (kokoroPython !=
nullptr && *kokoroPython !=
'\0') {
44 cfg.
put(
"python_executable", std::string(kokoroPython));
49 std::cerr <<
"ERROR: Failed to open kokoroSpeechSynthesizer device" << std::endl;
54 if (!dd.
view(iSynth) || iSynth ==
nullptr) {
55 std::cerr <<
"ERROR: Failed to view ISpeechSynthesizer interface" << std::endl;
64 std::cerr <<
"ERROR: getLanguage failed" << std::endl;
68 std::cout <<
"getLanguage -> " << lang << std::endl;
71 std::cerr <<
"ERROR: setLanguage(" << language <<
") failed" << std::endl;
75 if (!iSynth->
getLanguage(lang) || lang != language) {
76 std::cerr <<
"ERROR: getLanguage returned unexpected value: " << lang << std::endl;
85 std::cerr <<
"ERROR: setVoice(" << voice <<
") failed" << std::endl;
90 std::cerr <<
"ERROR: getVoice failed" << std::endl;
94 std::cout <<
"getVoice -> " << v << std::endl;
100 std::cerr <<
"ERROR: setSpeed/getSpeed failed" << std::endl;
104 std::cout <<
"setSpeed(2.0) -> getSpeed " << speed << std::endl;
106 std::cerr <<
"ERROR: getSpeed returned unexpected value: " << speed << std::endl;
115 std::cerr <<
"ERROR: setPitch/getPitch failed" << std::endl;
119 std::cout <<
"setPitch(0.5) -> getPitch " << pitch << std::endl;
123 std::cout <<
"Synthesizing audio (this loads/runs the Kokoro model, may take a while)..." << std::endl;
125 if (!iSynth->
synthesize(
"This is a Kokoro smoke test from YARP.", sound)) {
126 std::cerr <<
"ERROR: synthesize failed" << std::endl;
131 std::cout <<
"SYNTHESIZED freq=" << sound.
getFrequency()
133 <<
" channels=" << sound.
getChannels() << std::endl;
bool view(T *&x)
Get an interface to the device driver.
A generic interface for speech synthesis.
virtual yarp::dev::ReturnValue synthesize(const std::string &text, yarp::sig::Sound &sound)=0
Performs the speech synthesis.
virtual yarp::dev::ReturnValue setPitch(const double pitch)=0
Sets the pitch for speech synthesis.
virtual yarp::dev::ReturnValue setVoice(const std::string &voice_name="auto")=0
Sets the voice set for speech synthesis.
virtual yarp::dev::ReturnValue setSpeed(const double speed=0)=0
Sets the voice speed for speech synthesis.
virtual yarp::dev::ReturnValue getLanguage(std::string &language)=0
Gets the current language set for speech synthesis.
virtual yarp::dev::ReturnValue setLanguage(const std::string &language="auto")=0
Sets the language for speech synthesis.
virtual yarp::dev::ReturnValue getPitch(double &voice)=0
Gets the current pitch set for speech synthesis.
virtual yarp::dev::ReturnValue getSpeed(double &speed)=0
Gets the current voice speed.
virtual yarp::dev::ReturnValue getVoice(std::string &voice_name)=0
Gets the current voice set for speech synthesis.
A container for a device driver.
bool close() override
Close the DeviceDriver.
bool open(const std::string &txt)
Construct and configure a device by its common name.
static void initMinimum()
Basic system initialization, not including plugins.
A class for storing options and configuration information.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
Class for storing sounds See Audio in YARP for additional documentation on YARP audio.
size_t getChannels() const
Get the number of channels of the sound.
int getFrequency() const
Get the frequency of the sound (i.e.
size_t getSamples() const
Get the number of samples contained in the sound.
int main(int argc, char **argv)