YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
googleSpeechTranscription_test.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2023 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
7#include <yarp/os/Network.h>
8#include <yarp/os/LogStream.h>
10#include <yarp/dev/PolyDriver.h>
12
13#include <yarp/sig/Sound.h>
14#include <yarp/sig/SoundFile.h>
15
16#include <catch2/catch_amalgamated.hpp>
17#include <harness.h>
18
19using namespace yarp::dev;
20using namespace yarp::os;
21
22TEST_CASE("dev::googleSpeechTranscription", "[yarp::dev]")
23{
24 YARP_REQUIRE_PLUGIN("googleSpeechTranscription", "device");
25
26 Network::setLocalMode(true);
27
28 SECTION("Checking googleSpeechTranscription device")
29 {
32
33 //read a test sound file from disk
36
37 rf.setQuiet(false);
38 rf.setVerbose(true);
39
40 rf.setDefaultContext("googleSpeechTranscription_demo");
41 std::string ss = rf.findFile("test_audio.wav");
42 CHECK(!ss.empty());
43 yarp::sig::file::read(snd,ss.c_str());
44 CHECK(snd.getSamples()>0);
45
46 //open the device
47 {
49 pdev_cfg.put("device", "googleSpeechTranscription");
50 pdev_cfg.put("language_code", "it-IT");
52 REQUIRE(ddfake.view(istr));
53 }
54
55 std::string lang = "en-US";
56 CHECK(istr->setLanguage(lang));
57
58 CHECK(istr->getLanguage(lang));
59 CHECK(lang == "en-US");
60
61 // Disabled to avoid wasting money in unnecessary calls to google APIs
62 //std::string transcript;
63 //double score;
64 //CHECK(istr->transcribe(snd,transcript, score));
65 //CHECK(transcript=="This is a text to speech test");
66 //CHECK(score > 0.99);
67
68 //"Close all polydrivers and check"
69 {
72 }
73 }
74
75 Network::setLocalMode(false);
76}
A generic interface for speech transcription.
A container for a device driver.
Definition PolyDriver.h:23
A mini-server for performing network communication in the background.
void close() override
Stop port activity.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
A class for storing options and configuration information.
Definition Property.h:33
Helper class for finding config files and other external resources.
bool setDefaultContext(const std::string &contextName)
Sets the context for the current ResourceFinder object.
std::string findFile(const std::string &name)
Find the full path to a file.
bool setQuiet(bool quiet=true)
Request that information be suppressed from the console.
bool setVerbose(bool verbose=true)
Request that information be printed to the console on how resources are being found.
Class for storing sounds See Audio in YARP for additional documentation on YARP audio.
Definition Sound.h:25
size_t getSamples() const
Get the number of samples contained in the sound.
Definition Sound.cpp:598
TEST_CASE("dev::googleSpeechTranscription", "[yarp::dev]")
For streams capable of holding different kinds of content, check what they actually have.
void delay(double seconds)
Wait for a certain number of seconds.
Definition Time.cpp:111
An interface to the operating system, including Port based communication.
bool read(ImageOf< PixelRgb > &dest, const std::string &src, image_fileformat format=FORMAT_ANY)