YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
KokoroSpeechSynthesizer_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.2)
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_GENERATION is ON.
10
11// Generated on: Tue Oct 13 15:09:21 2026
12
13
15#include <yarp/os/LogStream.h>
16#include <yarp/os/Value.h>
17
18namespace {
19 YARP_LOG_COMPONENT(KokoroSpeechSynthesizerParamsCOMPONENT, "yarp.device.KokoroSpeechSynthesizer")
20}
21
22
26
27
29{
30 std::vector<std::string> params;
31 params.push_back("python_executable");
32 params.push_back("worker_script");
33 params.push_back("model_repository");
34 params.push_back("torch_device");
35 params.push_back("language");
36 params.push_back("voice");
37 params.push_back("speed");
38 params.push_back("pitch");
39 return params;
40}
41
42
43bool KokoroSpeechSynthesizer_ParamsParser::getParamValue(const std::string& paramName, std::string& paramValue) const
44{
45 if (paramName =="python_executable")
46 {
47 paramValue = m_python_executable;
48 return true;
49 }
50 if (paramName =="worker_script")
51 {
52 paramValue = m_worker_script;
53 return true;
54 }
55 if (paramName =="model_repository")
56 {
57 paramValue = m_model_repository;
58 return true;
59 }
60 if (paramName =="torch_device")
61 {
62 paramValue = m_torch_device;
63 return true;
64 }
65 if (paramName =="language")
66 {
67 paramValue = m_language;
68 return true;
69 }
70 if (paramName =="voice")
71 {
72 paramValue = m_voice;
73 return true;
74 }
75 if (paramName =="speed")
76 {
77 paramValue = std::to_string(m_speed);
78 return true;
79 }
80 if (paramName =="pitch")
81 {
82 paramValue = std::to_string(m_pitch);
83 return true;
84 }
85
86 yError() <<"parameter '" << paramName << "' was not found";
87 return false;
88
89}
90
91
93{
94 //This is a sub-optimal solution.
95 //Ideally getConfiguration() should return all parameters but it is currently
96 //returning only user provided parameters (excluding default values)
97 //This behaviour will be fixed in the near future.
98 std::string s_cfg = m_provided_configuration;
99 return s_cfg;
100}
101
103{
104 //Check for --help option
105 if (config.check("help"))
106 {
107 yCInfo(KokoroSpeechSynthesizerParamsCOMPONENT) << getDocumentationOfDeviceParams();
108 }
109
112 //Parser of parameter python_executable
113 {
114 if (config.check("python_executable"))
115 {
116 m_python_executable = config.find("python_executable").asString();
117 yCInfo(KokoroSpeechSynthesizerParamsCOMPONENT) << "Parameter 'python_executable' using value:" << m_python_executable;
118 }
119 else
120 {
121 yCInfo(KokoroSpeechSynthesizerParamsCOMPONENT) << "Parameter 'python_executable' using DEFAULT value:" << m_python_executable;
122 }
123 prop_check.unput("python_executable");
124 }
125
126 //Parser of parameter worker_script
127 {
128 if (config.check("worker_script"))
129 {
130 m_worker_script = config.find("worker_script").asString();
131 yCInfo(KokoroSpeechSynthesizerParamsCOMPONENT) << "Parameter 'worker_script' using value:" << m_worker_script;
132 }
133 else
134 {
135 yCInfo(KokoroSpeechSynthesizerParamsCOMPONENT) << "Parameter 'worker_script' using DEFAULT value:" << m_worker_script;
136 }
137 prop_check.unput("worker_script");
138 }
139
140 //Parser of parameter model_repository
141 {
142 if (config.check("model_repository"))
143 {
144 m_model_repository = config.find("model_repository").asString();
145 yCInfo(KokoroSpeechSynthesizerParamsCOMPONENT) << "Parameter 'model_repository' using value:" << m_model_repository;
146 }
147 else
148 {
149 yCInfo(KokoroSpeechSynthesizerParamsCOMPONENT) << "Parameter 'model_repository' using DEFAULT value:" << m_model_repository;
150 }
151 prop_check.unput("model_repository");
152 }
153
154 //Parser of parameter torch_device
155 {
156 if (config.check("torch_device"))
157 {
158 m_torch_device = config.find("torch_device").asString();
159 yCInfo(KokoroSpeechSynthesizerParamsCOMPONENT) << "Parameter 'torch_device' using value:" << m_torch_device;
160 }
161 else
162 {
163 yCInfo(KokoroSpeechSynthesizerParamsCOMPONENT) << "Parameter 'torch_device' using DEFAULT value:" << m_torch_device;
164 }
165 prop_check.unput("torch_device");
166 }
167
168 //Parser of parameter language
169 {
170 if (config.check("language"))
171 {
172 m_language = config.find("language").asString();
173 yCInfo(KokoroSpeechSynthesizerParamsCOMPONENT) << "Parameter 'language' using value:" << m_language;
174 }
175 else
176 {
177 yCInfo(KokoroSpeechSynthesizerParamsCOMPONENT) << "Parameter 'language' using DEFAULT value:" << m_language;
178 }
179 prop_check.unput("language");
180 }
181
182 //Parser of parameter voice
183 {
184 if (config.check("voice"))
185 {
186 m_voice = config.find("voice").asString();
187 yCInfo(KokoroSpeechSynthesizerParamsCOMPONENT) << "Parameter 'voice' using value:" << m_voice;
188 }
189 else
190 {
191 yCInfo(KokoroSpeechSynthesizerParamsCOMPONENT) << "Parameter 'voice' using DEFAULT value:" << m_voice;
192 }
193 prop_check.unput("voice");
194 }
195
196 //Parser of parameter speed
197 {
198 if (config.check("speed"))
199 {
200 m_speed = config.find("speed").asFloat64();
201 yCInfo(KokoroSpeechSynthesizerParamsCOMPONENT) << "Parameter 'speed' using value:" << m_speed;
202 }
203 else
204 {
205 yCInfo(KokoroSpeechSynthesizerParamsCOMPONENT) << "Parameter 'speed' using DEFAULT value:" << m_speed;
206 }
207 prop_check.unput("speed");
208 }
209
210 //Parser of parameter pitch
211 {
212 if (config.check("pitch"))
213 {
214 m_pitch = config.find("pitch").asFloat64();
215 yCInfo(KokoroSpeechSynthesizerParamsCOMPONENT) << "Parameter 'pitch' using value:" << m_pitch;
216 }
217 else
218 {
219 yCInfo(KokoroSpeechSynthesizerParamsCOMPONENT) << "Parameter 'pitch' using DEFAULT value:" << m_pitch;
220 }
221 prop_check.unput("pitch");
222 }
223
224 /*
225 //This code check if the user set some parameter which are not check by the parser
226 //If the parser is set in strict mode, this will generate an error
227 if (prop_check.size() > 0)
228 {
229 bool extra_params_found = false;
230 for (auto it=prop_check.begin(); it!=prop_check.end(); it++)
231 {
232 if (m_parser_is_strict)
233 {
234 yCError(KokoroSpeechSynthesizerParamsCOMPONENT) << "User asking for parameter: "<<it->name <<" which is unknown to this parser!";
235 extra_params_found = true;
236 }
237 else
238 {
239 yCWarning(KokoroSpeechSynthesizerParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!";
240 }
241 }
242
243 if (m_parser_is_strict && extra_params_found)
244 {
245 return false;
246 }
247 }
248 */
249 return true;
250}
251
252
254{
255 std::string doc;
256 doc = doc + std::string("\n=============================================\n");
257 doc = doc + std::string("This is the help for device: KokoroSpeechSynthesizer\n");
258 doc = doc + std::string("\n");
259 doc = doc + std::string("This is the list of the parameters accepted by the device:\n");
260 doc = doc + std::string("'python_executable': Python interpreter containing the kokoro package.\n");
261 doc = doc + std::string("'worker_script': Path to kokoro_worker.py. If omitted, the build or installed worker is used.\n");
262 doc = doc + std::string("'model_repository': Hugging Face model repository used by Kokoro.\n");
263 doc = doc + std::string("'torch_device': PyTorch execution device, for example cpu or cuda. The empty value lets PyTorch/Kokoro choose automatically.\n");
264 doc = doc + std::string("'language': Speech language: en, en-gb, es, fr, hi, it, ja, pt-br, zh, or a Kokoro language code.\n");
265 doc = doc + std::string("'voice': Kokoro voice name, for example af_heart or bf_emma.\n");
266 doc = doc + std::string("'speed': Speech speed in the range (0, 4].\n");
267 doc = doc + std::string("'pitch': Stored for ISpeechSynthesizer compatibility. Kokoro currently does not apply pitch.\n");
268 doc = doc + std::string("\n");
269 doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n");
270 doc = doc + " yarpdev --device kokoroSpeechSynthesizer --python_executable python3 --worker_script <optional_value> --model_repository hexgrad/Kokoro-82M --torch_device <optional_value> --language en --voice auto --speed 1 --pitch 0\n";
271 doc = doc + std::string("Using only mandatory params:\n");
272 doc = doc + " yarpdev --device kokoroSpeechSynthesizer\n";
273 doc = doc + std::string("=============================================\n\n"); return doc;
274}
#define yError(...)
Definition Log.h:361
std::string getDocumentationOfDeviceParams() const override
Get the documentation of the DeviceDriver's parameters.
bool getParamValue(const std::string &paramName, std::string &paramValue) const override
Return the value (represented as a string) of the requested parameter.
std::vector< std::string > getListOfParams() const override
Return a list of all params used by the device.
std::string getConfiguration() const override
Return the configuration of the device.
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
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.
#define yCInfo(component,...)
#define YARP_LOG_COMPONENT(name,...)