YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
SpeechSynthesizer_nwc_yarp.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
7
9#include <yarp/os/LogStream.h>
10#include <yarp/os/Os.h>
11
12namespace {
13YARP_LOG_COMPONENT(SPEECHSYNTH_NWC, "yarp.devices.speechSynthesizer_nwc_yarp")
14}
15
16using namespace yarp::dev;
17
22
24{
25 return closeMain();
26}
27
29{
30 if (!parseParams(config)) { return false; }
31
32 std::string thriftClientPortName = m_local + "/thrift:c";
33 std::string thriftServerPortName = m_remote + "/rpc";
34
35 if(!m_thriftClientPort.open(thriftClientPortName))
36 {
37 yCError(SPEECHSYNTH_NWC) << "open() failed: could not open" << thriftClientPortName <<"check the network";
38
39 return false;
40 }
41
42 if(!yarp::os::Network::connect(thriftClientPortName, thriftServerPortName))
43 {
44 yCError(SPEECHSYNTH_NWC) << "Network::connect() failed: could not connect" << thriftClientPortName << "with" << thriftServerPortName;
45
46 return false;
47 }
48
49 if(!m_thriftClient.yarp().attachAsClient(m_thriftClientPort))
50 {
51 yCError(SPEECHSYNTH_NWC) << "Error! Cannot attach the m_thriftClientPort (" << thriftClientPortName << ") port as a client";
52
53 return false;
54 }
55
56 //Check the protocol version
57 if (!m_thriftClient.checkProtocolVersion()) { return false; }
58
59 yCInfo(SPEECHSYNTH_NWC) << "Opening of NWC successful";
60 return true;
61}
62
63bool SpeechSynthesizer_nwc_yarp::closeMain()
64{
65 // Close thrift client port
67
68 return true;
69}
70
72{
73 auto result = m_thriftClient.set_language(language);
74 if(!result.ret)
75 {
76 yCError(SPEECHSYNTH_NWC) << "Error while setting language to" << language;
77 return result.ret;
78 }
79
80 return result.ret;
81}
82
84{
85 auto result = m_thriftClient.get_language();
86 if(!result.ret)
87 {
88 yCError(SPEECHSYNTH_NWC) << "Error while retrieving language";
89 return result.ret;
90 }
91
92 language = result.language;
93
94 return result.ret;
95}
96
98{
99 auto result = m_thriftClient.set_voice(voice_name);
100 if(!result.ret)
101 {
102 yCError(SPEECHSYNTH_NWC) << "Error while setting voice to" << voice_name;
103 return result.ret;
104 }
105
106 return result.ret;
107}
108
110{
111 auto result = m_thriftClient.get_voice();
112 if(!result.ret)
113 {
114 yCError(SPEECHSYNTH_NWC) << "Error while retrieving the voice name";
115 return result.ret;
116 }
117
118 voice_name = result.voice;
119
120 return result.ret;
121}
122
124{
125 auto result = m_thriftClient.set_speed(speed);
126 if(!result.ret)
127 {
128 yCError(SPEECHSYNTH_NWC) << "Error while setting voice speed to" << speed;
129 return result.ret;
130 }
131
132 return result.ret;
133}
134
136{
137 auto result = m_thriftClient.get_speed();
138 if(!result.ret)
139 {
140 yCError(SPEECHSYNTH_NWC) << "Error while retrieving the voice speed";
141 return result.ret;
142 }
143
144 speed = result.speed;
145
146 return result.ret;
147}
148
150{
151 auto result = m_thriftClient.set_pitch(pitch);
152 if(!result.ret)
153 {
154 yCError(SPEECHSYNTH_NWC) << "Error while setting voice pitch to" << pitch;
155 return result.ret;
156 }
157
158 return result.ret;
159}
160
162{
163 auto result = m_thriftClient.get_pitch();
164 if(!result.ret)
165 {
166 yCError(SPEECHSYNTH_NWC) << "Error while retrieving the voice pitch";
167 return result.ret;
168 }
169
170 pitch = result.pitch;
171
172 return result.ret;
173}
174
176{
177 auto result = m_thriftClient.synthesize(text);
178 if(!result.ret)
179 {
180 yCError(SPEECHSYNTH_NWC) << "Error while performing voice synthesis";
181 return result.ret;
182 }
183 sound = result.sound;
184
185 return result.ret;
186}
virtual return_set_speed set_speed(const double speed)
virtual return_get_speed get_speed()
virtual return_set_pitch set_pitch(const double pitch)
virtual return_set_voice set_voice(const std::string &language)
virtual return_synthesize synthesize(const std::string &text)
virtual return_get_pitch get_pitch()
virtual return_get_language get_language()
virtual return_get_voice get_voice()
virtual return_set_language set_language(const std::string &language)
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
yarp::dev::ReturnValue synthesize(const std::string &text, yarp::sig::Sound &sound) override
Performs the speech synthesis.
yarp::dev::ReturnValue setSpeed(const double speed=0) override
Sets the voice speed for speech synthesis.
yarp::dev::ReturnValue getPitch(double &pitch) override
Gets the current pitch set for speech synthesis.
yarp::dev::ReturnValue getSpeed(double &speed) override
Gets the current voice speed.
yarp::dev::ReturnValue setLanguage(const std::string &language="auto") override
Sets the language for speech synthesis.
yarp::dev::ReturnValue setPitch(const double pitch) override
Sets the pitch for speech synthesis.
bool close() override
Close the DeviceDriver.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
yarp::dev::ReturnValue setVoice(const std::string &voice_name="auto") override
Sets the voice set for speech synthesis.
yarp::dev::ReturnValue getLanguage(std::string &language) override
Gets the current language set for speech synthesis.
yarp::dev::ReturnValue getVoice(std::string &voice_name) override
Gets the current voice set for speech synthesis.
yarp::dev::ReturnValue ret
yarp::dev::ReturnValue ret
yarp::dev::ReturnValue ret
yarp::dev::ReturnValue ret
yarp::dev::ReturnValue ret
yarp::dev::ReturnValue ret
yarp::dev::ReturnValue ret
yarp::dev::ReturnValue ret
yarp::dev::ReturnValue ret
static bool connect(const std::string &src, const std::string &dest, const std::string &carrier="", bool quiet=true)
Request that an output port connect to an input port.
Definition Network.cpp:682
void close() override
Stop port activity.
Definition Port.cpp:330
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
Definition Port.cpp:79
A base class for nested structures that can be searched.
Definition Searchable.h:31
yarp::os::WireLink & yarp()
Get YARP state associated with this object.
Definition Wire.h:28
Class for storing sounds See Audio in YARP for additional documentation on YARP audio.
Definition Sound.h:25
#define yCInfo(component,...)
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.