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 //Check the protocol version
55 if (!m_thriftClient.checkProtocolVersion()) { return false; }
56
57 yCInfo(SPEECHTR_NWC) << "Opening of NWC successful";
58 return true;
59}
60
61bool SpeechTranscription_nwc_yarp::closeMain()
62{
63 // Close thrift client port
65
66 return true;
67}
68
70{
71 return_set_language result = m_thriftClient.set_language(language);
72 if(!result.ret)
73 {
74 yCError(SPEECHTR_NWC) << "Error while setting language to" << language;
75 }
76 else
77 {
78 }
79 return result.ret;
80}
81
83{
84 return_get_language result = m_thriftClient.get_language();
85 if(!result.ret)
86 {
87 yCError(SPEECHTR_NWC) << "Error while retrieving language";
88 }
89 else
90 {
91 language = result.language;
92 }
93 return result.ret;
94}
95
96yarp::dev::ReturnValue SpeechTranscription_nwc_yarp::transcribe(const yarp::sig::Sound& sound, std::string& transcription, double& score)
97{
98 YARP_UNUSED(sound);
99 YARP_UNUSED(transcription);
100 YARP_UNUSED(score);
101
102 return_transcribe result = m_thriftClient.transcribe(sound);
103
104 if(!result.ret)
105 {
106 yCError(SPEECHTR_NWC) << "Error while transcribing the audio signal";
107 }
108 else
109 {
110 transcription = result.transcription;
111 score = result.score;
112 }
113 return result.ret;
114}
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: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,...)
#define YARP_UNUSED(var)
Definition api.h:162