YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
GoogleSpeechSynthesizer_ParamsParser.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
6
7// Generated by yarpDeviceParamParserGenerator (2.0)
8// This is an automatically generated file. Please do not edit it.
9// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON.
10
11// Generated on: Wed Jan 21 10:47:25 2026
12
13
15#include <yarp/os/LogStream.h>
16#include <yarp/os/Value.h>
17
18namespace {
19 YARP_LOG_COMPONENT(GoogleSpeechSynthesizerParamsCOMPONENT, "yarp.device.GoogleSpeechSynthesizer")
20}
21
22
26
27
29{
30 std::vector<std::string> params;
31 params.push_back("language_code");
32 params.push_back("voice_name");
33 params.push_back("voice_speed");
34 params.push_back("voice_pitch");
35 params.push_back("default_voices");
36 params.push_back("voice_fallback");
37 return params;
38}
39
40
41bool GoogleSpeechSynthesizer_ParamsParser::getParamValue(const std::string& paramName, std::string& paramValue) const
42{
43 if (paramName =="language_code")
44 {
45 paramValue = m_language_code;
46 return true;
47 }
48 if (paramName =="voice_name")
49 {
50 paramValue = m_voice_name;
51 return true;
52 }
53 if (paramName =="voice_speed")
54 {
55 paramValue = std::to_string(m_voice_speed);
56 return true;
57 }
58 if (paramName =="voice_pitch")
59 {
60 paramValue = std::to_string(m_voice_pitch);
61 return true;
62 }
63 if (paramName =="default_voices")
64 {
65 return false;
66 }
67 if (paramName =="voice_fallback")
68 {
69 paramValue = std::to_string(m_voice_fallback);
70 return true;
71 }
72
73 yError() <<"parameter '" << paramName << "' was not found";
74 return false;
75
76}
77
78
80{
81 //This is a sub-optimal solution.
82 //Ideally getConfiguration() should return all parameters but it is currently
83 //returning only user provided parameters (excluding default values)
84 //This behaviour will be fixed in the near future.
85 std::string s_cfg = m_provided_configuration;
86 return s_cfg;
87}
88
90{
91 //Check for --help option
92 if (config.check("help"))
93 {
94 yCInfo(GoogleSpeechSynthesizerParamsCOMPONENT) << getDocumentationOfDeviceParams();
95 }
96
99 //Parser of parameter language_code
100 {
101 if (config.check("language_code"))
102 {
103 m_language_code = config.find("language_code").asString();
104 yCInfo(GoogleSpeechSynthesizerParamsCOMPONENT) << "Parameter 'language_code' using value:" << m_language_code;
105 }
106 else
107 {
108 yCError(GoogleSpeechSynthesizerParamsCOMPONENT) << "Mandatory parameter 'language_code' not found!";
109 yCError(GoogleSpeechSynthesizerParamsCOMPONENT) << "Description of the parameter: Language for speech synthesis (e.g. \"it-IT\", \"en-US\")";
110 return false;
111 }
112 prop_check.unput("language_code");
113 }
114
115 //Parser of parameter voice_name
116 {
117 if (config.check("voice_name"))
118 {
119 m_voice_name = config.find("voice_name").asString();
120 yCInfo(GoogleSpeechSynthesizerParamsCOMPONENT) << "Parameter 'voice_name' using value:" << m_voice_name;
121 }
122 else
123 {
124 yCInfo(GoogleSpeechSynthesizerParamsCOMPONENT) << "Parameter 'voice_name' using DEFAULT value:" << m_voice_name;
125 }
126 prop_check.unput("voice_name");
127 }
128
129 //Parser of parameter voice_speed
130 {
131 if (config.check("voice_speed"))
132 {
133 m_voice_speed = config.find("voice_speed").asFloat64();
134 yCInfo(GoogleSpeechSynthesizerParamsCOMPONENT) << "Parameter 'voice_speed' using value:" << m_voice_speed;
135 }
136 else
137 {
138 yCInfo(GoogleSpeechSynthesizerParamsCOMPONENT) << "Parameter 'voice_speed' using DEFAULT value:" << m_voice_speed;
139 }
140 prop_check.unput("voice_speed");
141 }
142
143 //Parser of parameter voice_pitch
144 {
145 if (config.check("voice_pitch"))
146 {
147 m_voice_pitch = config.find("voice_pitch").asFloat64();
148 yCInfo(GoogleSpeechSynthesizerParamsCOMPONENT) << "Parameter 'voice_pitch' using value:" << m_voice_pitch;
149 }
150 else
151 {
152 yCInfo(GoogleSpeechSynthesizerParamsCOMPONENT) << "Parameter 'voice_pitch' using DEFAULT value:" << m_voice_pitch;
153 }
154 prop_check.unput("voice_pitch");
155 }
156
157 //Parser of parameter default_voices
158 {
159 if (config.check("default_voices"))
160 {
161 {
162 m_default_voices.clear();
163 yarp::os::Bottle* tempBot = config.find("default_voices").asList();
164 if (tempBot)
165 {
166 std::string tempBots = tempBot->toString();
167 for (size_t i=0; i<tempBot->size(); i++)
168 {
169 m_default_voices.push_back(tempBot->get(i).asString());
170 }
171 }
172 else
173 {
174 yCError(GoogleSpeechSynthesizerParamsCOMPONENT) <<"parameter 'default_voices' is not a properly formatted bottle";
175 }
176 }
177 yCInfo(GoogleSpeechSynthesizerParamsCOMPONENT) << "Parameter 'default_voices' using value:" << m_default_voices;
178 }
179 else
180 {
181 yCInfo(GoogleSpeechSynthesizerParamsCOMPONENT) << "Parameter 'default_voices' using DEFAULT value:" << m_default_voices;
182 }
183 prop_check.unput("default_voices");
184 }
185
186 //Parser of parameter voice_fallback
187 {
188 if (config.check("voice_fallback"))
189 {
190 m_voice_fallback = config.find("voice_fallback").asInt64();
191 yCInfo(GoogleSpeechSynthesizerParamsCOMPONENT) << "Parameter 'voice_fallback' using value:" << m_voice_fallback;
192 }
193 else
194 {
195 yCInfo(GoogleSpeechSynthesizerParamsCOMPONENT) << "Parameter 'voice_fallback' using DEFAULT value:" << m_voice_fallback;
196 }
197 prop_check.unput("voice_fallback");
198 }
199
200 /*
201 //This code check if the user set some parameter which are not check by the parser
202 //If the parser is set in strict mode, this will generate an error
203 if (prop_check.size() > 0)
204 {
205 bool extra_params_found = false;
206 for (auto it=prop_check.begin(); it!=prop_check.end(); it++)
207 {
208 if (m_parser_is_strict)
209 {
210 yCError(GoogleSpeechSynthesizerParamsCOMPONENT) << "User asking for parameter: "<<it->name <<" which is unknown to this parser!";
211 extra_params_found = true;
212 }
213 else
214 {
215 yCWarning(GoogleSpeechSynthesizerParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!";
216 }
217 }
218
219 if (m_parser_is_strict && extra_params_found)
220 {
221 return false;
222 }
223 }
224 */
225 return true;
226}
227
228
230{
231 std::string doc;
232 doc = doc + std::string("\n=============================================\n");
233 doc = doc + std::string("This is the help for device: GoogleSpeechSynthesizer\n");
234 doc = doc + std::string("\n");
235 doc = doc + std::string("This is the list of the parameters accepted by the device:\n");
236 doc = doc + std::string("'language_code': Language for speech synthesis (e.g. \"it-IT\", \"en-US\")\n");
237 doc = doc + std::string("'voice_name': The voice set for speech synthesis. If not set, the device will pick the first available voice for the selected language code (This page holds the complete list of the available voices: https://cloud.google.com/text-to-speech/docs/voices)\n");
238 doc = doc + std::string("'voice_speed': Speaking rate/speed, in the range [0.25, 4.0]. 1.0 is the normal native speed supported by the specific voice. 2.0 is twice as fast, and 0.5 is half as fast.\n");
239 doc = doc + std::string("'voice_pitch': Speaking pitch, in the range [-20.0, 20.0]. 20 means increase 20 semitones from the original pitch. -20 means decrease 20 semitones from the original pitch.\n");
240 doc = doc + std::string("'default_voices': A set of default voices to be automatically set when you change language. (This page holds the complete list of the available voices: https://cloud.google.com/text-to-speech/docs/voices)\n");
241 doc = doc + std::string("'voice_fallback': It enables/disables the automatic setting of the voice name to the first available one if the selected voice is not valid\n");
242 doc = doc + std::string("\n");
243 doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n");
244 doc = doc + " yarpdev --device googleSpeechSynthesizer --language_code <mandatory_value> --voice_name <optional_value> --voice_speed 1 --voice_pitch 0 --default_voices <optional_value> --voice_fallback 1\n";
245 doc = doc + std::string("Using only mandatory params:\n");
246 doc = doc + " yarpdev --device googleSpeechSynthesizer --language_code <mandatory_value>\n";
247 doc = doc + std::string("=============================================\n\n"); return doc;
248}
#define yError(...)
Definition Log.h:361
bool getParamValue(const std::string &paramName, std::string &paramValue) const override
Return the value (represented as a string) of the requested parameter.
std::string getConfiguration() const override
Return the configuration of the device.
std::vector< std::string > getListOfParams() const override
Return a list of all params used by the device.
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
std::string getDocumentationOfDeviceParams() const override
Get the documentation of the DeviceDriver's parameters.
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:65
size_type size() const
Gets the number of elements in the bottle.
Definition Bottle.cpp:257
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition Bottle.cpp:252
std::string toString() const override
Gives a human-readable textual representation of the bottle.
Definition Bottle.cpp:217
A class for storing options and configuration information.
Definition Property.h:33
void unput(const std::string &key)
Remove the association from the given key to a value, if present.
A base class for nested structures that can be searched.
Definition Searchable.h:31
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
virtual std::string asString() const
Get string value.
Definition Value.cpp:246
#define yCInfo(component,...)
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)