YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
SpeechTranscription_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(SPEECHTR_NWC, "yarp.devices.speechTranscription_nwc_yarp")
14}
15
20
22{
23 return closeMain();
24}
25
27{
28 if (!parseParams(config)) { return false; }
29
30 std::string thriftClientPortName = m_local + "/thrift:c";
31 std::string thriftServerPortName = m_remote + "/rpc";
32
33 if(!m_thriftClientPort.open(thriftClientPortName))
34 {
35 yCError(SPEECHTR_NWC) << "open() failed: could not open" << thriftClientPortName <<"check the network";
36
37 return false;
38 }
39
40 if(!yarp::os::Network::connect(thriftClientPortName, thriftServerPortName))
41 {
42 yCError(SPEECHTR_NWC) << "Network::connect() failed: could not connect" << thriftClientPortName << "with" << thriftServerPortName;
43
44 return false;
45 }
46
47 if(!m_thriftClient.yarp().attachAsClient(m_thriftClientPort))
48 {
49 yCError(SPEECHTR_NWC) << "Error! Cannot attach the m_thriftClientPort (" << thriftClientPortName << ") port as a client";
50
51 return false;
52 }
53
54 return true;
55}
56
57bool SpeechTranscription_nwc_yarp::closeMain()
58{
59 // Close thrift client port
61
62 return true;
63}
64
66{
67 return_set_language result = m_thriftClient.set_language(language);
68 if(!result.ret)
69 {
70 yCError(SPEECHTR_NWC) << "Error while setting language to" << language;
71 }
72 else
73 {
74 }
75 return result.ret;
76}
77
79{
80 return_get_language result = m_thriftClient.get_language();
81 if(!result.ret)
82 {
83 yCError(SPEECHTR_NWC) << "Error while retrieving language";
84 }
85 else
86 {
87 language = result.language;
88 }
89 return result.ret;
90}
91
92yarp::dev::ReturnValue SpeechTranscription_nwc_yarp::transcribe(const yarp::sig::Sound& sound, std::string& transcription, double& score)
93{
94 YARP_UNUSED(sound);
95 YARP_UNUSED(transcription);
96 YARP_UNUSED(score);
97
98 return_transcribe result = m_thriftClient.transcribe(sound);
99
100 if(!result.ret)
101 {
102 yCError(SPEECHTR_NWC) << "Error while transcribing the audio signal";
103 }
104 else
105 {
106 transcription = result.transcription;
107 score = result.score;
108 }
109 return result.ret;
110}
virtual return_transcribe transcribe(const yarp::sig::Sound &sound)
virtual return_set_language set_language(const std::string &language)
virtual return_get_language get_language()
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
yarp::dev::ReturnValue setLanguage(const std::string &language="auto") override
Sets the language for speech transcription.
bool close() override
Close the DeviceDriver.
yarp::dev::ReturnValue getLanguage(std::string &language) override
Gets the current language set for speech transcription.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
yarp::dev::ReturnValue transcribe(const yarp::sig::Sound &sound, std::string &transcription, double &score) override
Performs the speech transcription.
yarp::dev::ReturnValue ret
yarp::dev::ReturnValue ret
std::string transcription
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,...)
#define YARP_UNUSED(var)
Definition api.h:162