Skip to content

Commit

Permalink
Merge pull request #3051 from randaz81/yarp_ret_value
Browse files Browse the repository at this point in the history
New class for return values of interface methods PART1
  • Loading branch information
randaz81 authored Jan 28, 2025
2 parents e52d732 + d195539 commit 43ba030
Show file tree
Hide file tree
Showing 54 changed files with 1,795 additions and 267 deletions.
9 changes: 9 additions & 0 deletions doc/release/master.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,12 @@ New Features

* added new datatype `yarp::sig::LayeredImage`
* added `yarp::sig::utils::sum()` to transform `yarp::sig::LayeredImage` to `yarp::sig::Image`

#### `libYARP_dev`

* added new class `yarp::dev::ReturnValue`
* modified interfaces `yarp::dev::ISpeechSynthesizer`,`yarp::dev::ISpeechTranscription` to use the new class ReturnValue.

#### `devices`

* modified devices implementing `yarp::dev::ISpeechSynthesizer`,`yarp::dev::ISpeechTranscription` to use the new class ReturnValue.
38 changes: 19 additions & 19 deletions src/devices/fake/fakeSpeechSynthesizer/FakeSpeechSynthesizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,67 +40,67 @@ bool FakeSpeechSynthesizer::close()
return true;
}

bool FakeSpeechSynthesizer::setLanguage(const std::string& language)
ReturnValue FakeSpeechSynthesizer::setLanguage(const std::string& language)
{
m_language=language;
yCInfo(FAKE_SPEECHSYN) << "Language set to" << language;
return true;
return ReturnValue_ok;
}

bool FakeSpeechSynthesizer::getLanguage(std::string& language)
ReturnValue FakeSpeechSynthesizer::getLanguage(std::string& language)
{
language = m_language;
return true;
return ReturnValue_ok;
}

bool FakeSpeechSynthesizer::setVoice(const std::string& voice)
ReturnValue FakeSpeechSynthesizer::setVoice(const std::string& voice)
{
m_voice = voice;
yCInfo(FAKE_SPEECHSYN) << "Voice set to" << voice;
return true;
return ReturnValue_ok;
}

bool FakeSpeechSynthesizer::getVoice(std::string& voice)
ReturnValue FakeSpeechSynthesizer::getVoice(std::string& voice)
{
voice = m_voice;
return true;
return ReturnValue_ok;
}

bool FakeSpeechSynthesizer::setSpeed(const double speed)
ReturnValue FakeSpeechSynthesizer::setSpeed(const double speed)
{
m_speed = speed;
yCInfo(FAKE_SPEECHSYN) << "Speed set to" << speed;
return true;
return ReturnValue_ok;
}

bool FakeSpeechSynthesizer::getSpeed(double& speed)
ReturnValue FakeSpeechSynthesizer::getSpeed(double& speed)
{
speed = m_speed;
return true;
return ReturnValue_ok;
}

bool FakeSpeechSynthesizer::setPitch(const double pitch)
ReturnValue FakeSpeechSynthesizer::setPitch(const double pitch)
{
m_pitch = pitch;
yCInfo(FAKE_SPEECHSYN) << "Pitch set to" << pitch;
return true;
return ReturnValue_ok;
}

bool FakeSpeechSynthesizer::getPitch(double& pitch)
ReturnValue FakeSpeechSynthesizer::getPitch(double& pitch)
{
pitch = m_pitch;
return true;
return ReturnValue_ok;
}

bool FakeSpeechSynthesizer::synthesize(const std::string& text, yarp::sig::Sound& sound)
ReturnValue FakeSpeechSynthesizer::synthesize(const std::string& text, yarp::sig::Sound& sound)
{
if (text == "")
{
yCError(FAKE_SPEECHSYN) << "Text is empty";
return false;
return ReturnValue::return_code::return_value_error_method_failed;
}

sound.resize(100,2);

return true;
return ReturnValue_ok;
}
18 changes: 9 additions & 9 deletions src/devices/fake/fakeSpeechSynthesizer/FakeSpeechSynthesizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ class FakeSpeechSynthesizer :
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 setVoice(const std::string& voice) override;
virtual bool getVoice(std::string& voice) override;
virtual bool setSpeed(const double speed) override;
virtual bool getSpeed(double& voice) override;
virtual bool setPitch(const double pitch) override;
virtual bool getPitch(double& voice) override;
virtual bool synthesize(const std::string& text, yarp::sig::Sound& sound) override;
virtual yarp::dev::ReturnValue setLanguage(const std::string& language) override;
virtual yarp::dev::ReturnValue getLanguage(std::string& language) override;
virtual yarp::dev::ReturnValue setVoice(const std::string& voice) override;
virtual yarp::dev::ReturnValue getVoice(std::string& voice) override;
virtual yarp::dev::ReturnValue setSpeed(const double speed) override;
virtual yarp::dev::ReturnValue getSpeed(double& voice) override;
virtual yarp::dev::ReturnValue setPitch(const double pitch) override;
virtual yarp::dev::ReturnValue getPitch(double& voice) override;
virtual yarp::dev::ReturnValue synthesize(const std::string& text, yarp::sig::Sound& sound) override;
};

#endif
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::ReturnValue FakeSpeechTranscription::setLanguage(const std::string& language)
{
m_language=language;
yCInfo(FAKE_SPEECHTR) << "Language set to" << language;
return true;
return ReturnValue_ok;
}

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

bool FakeSpeechTranscription::transcribe(const yarp::sig::Sound& sound, std::string& transcription, double& score)
yarp::dev::ReturnValue 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 ReturnValue::return_code::return_value_error_method_failed;
}

transcription = "hello world";
score = 1.0;
return true;
return ReturnValue_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::ReturnValue setLanguage(const std::string& language) override;
virtual yarp::dev::ReturnValue getLanguage(std::string& language) override;
virtual yarp::dev::ReturnValue 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,62 @@ struct yarp_sig_Sound {
yarp.includefile = "yarp/sig/Sound.h"
)

struct yReturnValue {
} (
yarp.name = "yarp::dev::ReturnValue"
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_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_voice set_voice (1:string language);
return_get_voice get_voice ();
bool set_speed (1:double speed);
return_set_speed set_speed (1:double speed);
return_get_speed get_speed ();
bool set_pitch (1:double pitch);
return_set_pitch set_pitch (1:double pitch);
return_get_pitch get_pitch ();
return_synthesize synthesize (1:string text);
}
Loading

0 comments on commit 43ba030

Please sign in to comment.