Skip to content

Commit

Permalink
New class for return values of interface methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
randaz81 committed Jan 21, 2025
1 parent aaa7d49 commit 7ca7ff6
Show file tree
Hide file tree
Showing 18 changed files with 555 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,31 @@ bool FakeSpeechTranscription::close()
return true;
}

bool FakeSpeechTranscription::setLanguage(const std::string& language)
yarp::dev::yarp_ret_value FakeSpeechTranscription::setLanguage(const std::string& language)
{
m_language=language;
yCInfo(FAKE_SPEECHTR) << "Language set to" << language;
return true;
return yarp_ret_value_ok;
}

bool FakeSpeechTranscription::getLanguage(std::string& language)
yarp::dev::yarp_ret_value FakeSpeechTranscription::getLanguage(std::string& language)
{
language = m_language;
return true;
return yarp_ret_value_ok;
}

bool FakeSpeechTranscription::transcribe(const yarp::sig::Sound& sound, std::string& transcription, double& score)
yarp::dev::yarp_ret_value FakeSpeechTranscription::transcribe(const yarp::sig::Sound& sound, std::string& transcription, double& score)
{
if (sound.getSamples() == 0 ||
sound.getChannels() == 0)
{
yCError(FAKE_SPEECHTR) << "Invalid Sound sample received";
transcription = "";
score = 0.0;
return false;
return yarp_ret_value::return_code::return_value_error_method_failed;
}

transcription = "hello world";
score = 1.0;
return true;
return yarp_ret_value_ok;
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ class FakeSpeechTranscription :
bool open(yarp::os::Searchable& config) override;
bool close() override;

virtual bool setLanguage(const std::string& language) override;
virtual bool getLanguage(std::string& language) override;
virtual bool transcribe(const yarp::sig::Sound& sound, std::string& transcription, double& score) override;
virtual yarp::dev::yarp_ret_value setLanguage(const std::string& language) override;
virtual yarp::dev::yarp_ret_value getLanguage(std::string& language) override;
virtual yarp::dev::yarp_ret_value transcribe(const yarp::sig::Sound& sound, std::string& transcription, double& score) override;
};

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,67 @@ struct yarp_sig_Sound {
yarp.includefile = "yarp/sig/Sound.h"
)

struct yReturnValue {
} (
yarp.name = "yarp::dev::yarp_ret_value"
yarp.includefile = "yarp/dev/ReturnValue.h"
)

struct return_set_language {
1: yReturnValue ret;
}

struct return_set_voice {
1: yReturnValue ret;
}

struct return_set_speed {
1: yReturnValue ret;
}

struct return_set_pitch {
1: yReturnValue ret;
}

struct return_synthesize {
1: yReturnValue ret;
2: yarp_sig_Sound sound;
}

struct return_get_language {
1: bool ret = false;
1: yReturnValue ret;
2: string language;
}

struct return_get_voice {
1: bool ret = false;
1: yReturnValue ret;
2: string voice;
}

struct return_get_speed {
1: bool ret = false;
1: yReturnValue ret;
2: double speed;
}

struct return_get_pitch {
1: bool ret = false;
1: yReturnValue ret;
2: double pitch;
}

struct return_synthesize {
1: bool ret = false;
1: yReturnValue ret;
2: yarp_sig_Sound sound;
}

service ISpeechSynthesizerMsgs
{
bool set_language (1:string language);
return_set_language set_language (1:string language);
return_get_language get_language ();
bool set_voice (1:string language);
return_set_language set_voice (1:string language);
return_get_voice get_voice ();
bool set_speed (1:double speed);
return_set_language set_speed (1:double speed);
return_get_speed get_speed ();
bool set_pitch (1:double pitch);
return_set_language set_pitch (1:double pitch);
return_get_pitch get_pitch ();
return_synthesize synthesize (1:string text);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,30 @@ struct yarp_sig_Sound {
yarp.includefile = "yarp/sig/Sound.h"
)

struct yReturnValue {
} (
yarp.name = "yarp::dev::yarp_ret_value"
yarp.includefile = "yarp/dev/ReturnValue.h"
)

struct return_set_language {
1: yReturnValue ret;
}

struct return_get_language {
1: bool ret = false;
1: yReturnValue ret;
2: string language;
}

struct return_transcribe {
1: bool ret = false;
1: yReturnValue ret;
2: string transcription;
3: double score;
}

service ISpeechTranscriptionMsgs
{
bool set_language (1:string language);
return_set_language set_language (1:string language);
return_get_language get_language ();
return_transcribe transcribe (1:yarp_sig_Sound sound);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ namespace {
YARP_LOG_COMPONENT(SPEECHSYNTH_NWC, "yarp.devices.speechSynthesizer_nwc_yarp")
}

using namespace yarp::dev;

SpeechSynthesizer_nwc_yarp::~SpeechSynthesizer_nwc_yarp()
{
closeMain();
Expand Down Expand Up @@ -62,115 +64,116 @@ bool SpeechSynthesizer_nwc_yarp::closeMain()
return true;
}

bool SpeechSynthesizer_nwc_yarp::setLanguage(const std::string& language)
yarp_ret_value SpeechSynthesizer_nwc_yarp::setLanguage(const std::string& language)
{
if(!m_thriftClient.set_language(language))
return_set_language result = m_thriftClient.set_language(language);
if(!result.ret)
{
yCError(SPEECHSYNTH_NWC) << "Error while setting language to" << language;
return false;
return result.ret;
}

return true;
return result.ret;
}

bool SpeechSynthesizer_nwc_yarp::getLanguage(std::string& language)
yarp_ret_value SpeechSynthesizer_nwc_yarp::getLanguage(std::string& language)
{
return_get_language result = m_thriftClient.get_language();
if(!result.ret)
{
yCError(SPEECHSYNTH_NWC) << "Error while retrieving language";
return false;
return result.ret;
}

language = result.language;

return true;
return result.ret;
}

bool SpeechSynthesizer_nwc_yarp::setVoice(const std::string& voice_name)
yarp_ret_value SpeechSynthesizer_nwc_yarp::setVoice(const std::string& voice_name)
{
if(!m_thriftClient.set_voice(voice_name))
{
yCError(SPEECHSYNTH_NWC) << "Error while setting voice to" << voice_name;
return false;
return result.ret;
}

return true;
return result.ret;
}

bool SpeechSynthesizer_nwc_yarp::getVoice(std::string& voice_name)
yarp_ret_value SpeechSynthesizer_nwc_yarp::getVoice(std::string& voice_name)
{
return_get_voice result = m_thriftClient.get_voice();
if(!result.ret)
{
yCError(SPEECHSYNTH_NWC) << "Error while retrieving the voice name";
return false;
return result.ret;
}

voice_name = result.voice;

return true;
return result.ret;
}

bool SpeechSynthesizer_nwc_yarp::setSpeed(const double speed)
yarp_ret_value SpeechSynthesizer_nwc_yarp::setSpeed(const double speed)
{
if(!m_thriftClient.set_speed(speed))
{
yCError(SPEECHSYNTH_NWC) << "Error while setting voice speed to" << speed;
return false;
return result.ret;
}

return true;
return result.ret;
}

bool SpeechSynthesizer_nwc_yarp::getSpeed(double& speed)
yarp_ret_value SpeechSynthesizer_nwc_yarp::getSpeed(double& speed)
{
return_get_speed result = m_thriftClient.get_speed();
if(!result.ret)
{
yCError(SPEECHSYNTH_NWC) << "Error while retrieving the voice speed";
return false;
return result.ret;
}

speed = result.speed;

return true;
return result.ret;
}

bool SpeechSynthesizer_nwc_yarp::setPitch(const double pitch)
yarp_ret_value SpeechSynthesizer_nwc_yarp::setPitch(const double pitch)
{
if(!m_thriftClient.set_pitch(pitch))
{
yCError(SPEECHSYNTH_NWC) << "Error while setting voice pitch to" << pitch;
return false;
return result.ret;
}

return true;
return result.ret;
}

bool SpeechSynthesizer_nwc_yarp::getPitch(double& pitch)
yarp_ret_value SpeechSynthesizer_nwc_yarp::getPitch(double& pitch)
{
return_get_pitch result = m_thriftClient.get_pitch();
if(!result.ret)
{
yCError(SPEECHSYNTH_NWC) << "Error while retrieving the voice pitch";
return false;
return result.ret;
}

pitch = result.pitch;

return true;
return result.ret;
}

bool SpeechSynthesizer_nwc_yarp::synthesize(const std::string& text, yarp::sig::Sound& sound)
yarp_ret_value SpeechSynthesizer_nwc_yarp::synthesize(const std::string& text, yarp::sig::Sound& sound)
{
return_synthesize result = m_thriftClient.synthesize(text);
if(!result.ret)
{
yCError(SPEECHSYNTH_NWC) << "Error while performing voice synthesis";
return false;
return result.ret;
}
sound = result.sound;

return true;
return result.ret;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <yarp/os/Bottle.h>
#include <yarp/os/RpcServer.h>
#include <yarp/dev/WrapperSingle.h>
#include <yarp/dev/ReturnValue.h>
#include "ISpeechSynthesizerMsgs.h"
#include "SpeechSynthesizer_nwc_yarp_ParamsParser.h"

Expand Down Expand Up @@ -56,15 +57,15 @@ class SpeechSynthesizer_nwc_yarp :
bool close() override;

// yarp::dev::ISpeechSynthesizer
bool setLanguage(const std::string& language="auto") override;
bool getLanguage(std::string& language) override;
bool setVoice(const std::string& voice_name = "auto") override;
bool getVoice(std::string& voice_name) override;
bool setSpeed(const double speed=0) override;
bool getSpeed(double& speed) override;
bool setPitch(const double pitch) override;
bool getPitch(double& pitch) override;
bool synthesize(const std::string& text, yarp::sig::Sound& sound) override;
yarp::dev::yarp_ret_value setLanguage(const std::string& language="auto") override;
yarp::dev::yarp_ret_value getLanguage(std::string& language) override;
yarp::dev::yarp_ret_value setVoice(const std::string& voice_name = "auto") override;
yarp::dev::yarp_ret_value getVoice(std::string& voice_name) override;
yarp::dev::yarp_ret_value setSpeed(const double speed=0) override;
yarp::dev::yarp_ret_value getSpeed(double& speed) override;
yarp::dev::yarp_ret_value setPitch(const double pitch) override;
yarp::dev::yarp_ret_value getPitch(double& pitch) override;
yarp::dev::yarp_ret_value synthesize(const std::string& text, yarp::sig::Sound& sound) override;

// Parameters
private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ class ISpeechSynthesizerMsgsd : public ISpeechSynthesizerMsgs
yarp::os::Port* m_output_port{ nullptr };

public:
virtual bool set_language(const std::string& language) override;
virtual return_set_language set_language(const std::string& language) override;
virtual return_get_language get_language() override;
virtual bool set_voice(const std::string& language) override;
virtual return_set_voice set_voice(const std::string& language) override;
virtual return_get_voice get_voice() override;
virtual bool set_speed(double speed) override;
virtual return_set_speed set_speed(double speed) override;
virtual return_get_speed get_speed() override;
virtual bool set_pitch(double pitch) override;
virtual return_set_pitch set_pitch(double pitch) override;
virtual return_get_pitch get_pitch() override;
virtual return_synthesize synthesize(const std::string& text) override;

Expand Down
Loading

0 comments on commit 7ca7ff6

Please sign in to comment.