6#ifndef _USE_MATH_DEFINES
7#define _USE_MATH_DEFINES
22namespace texttospeech = ::google::cloud::texttospeech_v1;
39 if(m_synthVoices.size() == 0)
41 yCError(
GOOGLESPEECHSYNTH) <<
"You haven't set the language code yet. Voice name cannot be set without a language code";
44 google::protobuf::RepeatedPtrField<google::cloud::texttospeech::v1::Voice>::iterator
it;
45 for(
it = m_synthVoices.begin();
it != m_synthVoices.end();
it++)
59 if(config.
check(
"__offline"))
61 m_offline = config.
find(
"__offline").asInt32() == 1;
66 m_synthClient = std::make_shared<texttospeech::TextToSpeechClient>(texttospeech::MakeTextToSpeechConnection());
67 m_synthVoiceSelParams = std::make_shared<google::cloud::texttospeech::v1::VoiceSelectionParams>();
68 m_synthInput = std::make_shared<google::cloud::texttospeech::v1::SynthesisInput>();
69 m_synthAudioConfig = std::make_shared<google::cloud::texttospeech::v1::AudioConfig>();
76 if(config.
check(
"voice_name"))
93 m_synthAudioConfig->set_audio_encoding(google::cloud::texttospeech::v1::MP3);
107 m_synthVoiceSelParams->set_language_code(language);
110 if(language ==
"auto")
116 if(language == m_synthVoiceSelParams->language_code() && m_synthVoices.size() != 0)
121 google::cloud::StatusOr<google::cloud::texttospeech::v1::ListVoicesResponse> response = m_synthClient->ListVoices(language);
123 yCError(
GOOGLESPEECHSYNTH) <<
"Error in getting the list of available voices. Google status:\n\t" << response.status().message() <<
"\n";
126 m_synthVoices = response->voices();
127 m_synthVoiceSelParams->set_language_code(language);
136 language = m_synthVoiceSelParams->language_code();
145 m_synthVoiceSelParams->set_name(m_synthVoices[0].name());
146 yCInfo(
GOOGLESPEECHSYNTH) <<
"auto option selected. Setting the voice name to:" << m_synthVoiceSelParams->name();
176 m_synthAudioConfig->set_speaking_rate(speed);
188 speed = m_synthAudioConfig->speaking_rate();
195 m_synthAudioConfig->set_pitch(pitch);
207 pitch = m_synthAudioConfig->pitch();
214 m_synthInput->set_text(text);
215 google::cloud::StatusOr<google::cloud::texttospeech::v1::SynthesizeSpeechResponse> response = m_synthClient->SynthesizeSpeech(*m_synthInput,*m_synthVoiceSelParams,*m_synthAudioConfig);
217 yCError(
GOOGLESPEECHSYNTH) <<
"Error synthesizing speech. Google status:\n\t" << response.status().message() <<
"\n";
const yarp::os::LogComponent & GOOGLESPEECHSYNTH()
const std::pair PITCH_RANGE
const std::pair SPEED_RANGE
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
std::string m_language_code
GoogleSpeechSynthesizer()
bool _voiceSupported(const std::string &voice_name)
Checks whether or not a particular voice name is supported by the currently selected language code.
yarp::dev::ReturnValue getPitch(double &pitch) override
Gets the current pitch set for speech synthesis.
yarp::dev::ReturnValue getLanguage(std::string &language) override
Gets the current language set for speech synthesis.
yarp::dev::ReturnValue setSpeed(const double speed=0) override
Sets the voice speed for speech synthesis.
yarp::dev::ReturnValue getSpeed(double &speed) override
Gets the current voice speed.
yarp::dev::ReturnValue setPitch(const double pitch) override
Sets the pitch for speech synthesis.
yarp::dev::ReturnValue setVoice(const std::string &voice_name="auto") override
Sets the voice set for speech synthesis.
bool close() override
Close the DeviceDriver.
yarp::dev::ReturnValue setLanguage(const std::string &language="auto") override
Sets the language for speech synthesis.
yarp::dev::ReturnValue synthesize(const std::string &text, yarp::sig::Sound &sound) override
Performs the speech synthesis.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
yarp::dev::ReturnValue getVoice(std::string &voice_name) override
Gets the current voice set for speech synthesis.
@ return_value_error_generic
Method was successfully executed.
A mini-server for performing network communication in the background.
A base class for nested structures that can be searched.
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
Class for storing sounds See Audio in YARP for additional documentation on YARP audio.
void clear()
set all the samples to zero (silence)
#define yCInfo(component,...)
#define yCError(component,...)
#define yCWarning(component,...)
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.
bool read_bytestream(Sound &data, const char *filename, size_t streamsize, std::string format)
Read a sound from a byte array.