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 return true;
57}
58
59bool SpeechSynthesizer_nwc_yarp::closeMain()
60{
61 // Close thrift client port
63
64 return true;
65}
66
68{
69 auto result = m_thriftClient.set_language(language);
70 if(!result.ret)
71 {
72 yCError(SPEECHSYNTH_NWC) << "Error while setting language to" << language;
73 return result.ret;
74 }
75
76 return result.ret;
77}
78
80{
81 auto result = m_thriftClient.get_language();
82 if(!result.ret)
83 {
84 yCError(SPEECHSYNTH_NWC) << "Error while retrieving language";
85 return result.ret;
86 }
87
88 language = result.language;
89
90 return result.ret;
91}
92
94{
95 auto result = m_thriftClient.set_voice(voice_name);
96 if(!result.ret)
97 {
98 yCError(SPEECHSYNTH_NWC) << "Error while setting voice to" << voice_name;
99 return result.ret;
100 }
101
102 return result.ret;
103}
104
106{
107 auto result = m_thriftClient.get_voice();
108 if(!result.ret)
109 {
110 yCError(SPEECHSYNTH_NWC) << "Error while retrieving the voice name";
111 return result.ret;
112 }
113
114 voice_name = result.voice;
115
116 return result.ret;
117}
118
120{
121 auto result = m_thriftClient.set_speed(speed);
122 if(!result.ret)
123 {
124 yCError(SPEECHSYNTH_NWC) << "Error while setting voice speed to" << speed;
125 return result.ret;
126 }
127
128 return result.ret;
129}
130
132{
133 auto result = m_thriftClient.get_speed();
134 if(!result.ret)
135 {
136 yCError(SPEECHSYNTH_NWC) << "Error while retrieving the voice speed";
137 return result.ret;
138 }
139
140 speed = result.speed;
141
142 return result.ret;
143}
144
146{
147 auto result = m_thriftClient.set_pitch(pitch);
148 if(!result.ret)
149 {
150 yCError(SPEECHSYNTH_NWC) << "Error while setting voice pitch to" << pitch;
151 return result.ret;
152 }
153
154 return result.ret;
155}
156
158{
159 auto result = m_thriftClient.get_pitch();
160 if(!result.ret)
161 {
162 yCError(SPEECHSYNTH_NWC) << "Error while retrieving the voice pitch";
163 return result.ret;
164 }
165
166 pitch = result.pitch;
167
168 return result.ret;
169}
170
172{
173 auto result = m_thriftClient.synthesize(text);
174 if(!result.ret)
175 {
176 yCError(SPEECHSYNTH_NWC) << "Error while performing voice synthesis";
177 return result.ret;
178 }
179 sound = result.sound;
180
181 return result.ret;
182}
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:363
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 yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.