YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
googleSpeechSynthesizer_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::googleSpeechSynthesizer_test", "[yarp::dev]")
23{
24 YARP_REQUIRE_PLUGIN("googleSpeechSynthesizer", "device");
25
26 Network::setLocalMode(true);
27
28 SECTION("Checking googleSpeechSynthesizer device")
29 {
30 ISpeechSynthesizer* iSynth{nullptr};
31 PolyDriver dd;
32
33 //read a test sound file from disk
36
37 rf.setQuiet(false);
38 rf.setVerbose(true);
39
40 rf.setDefaultContext("googleSpeechSynthesizer_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 //"Checking opening device"
47 {
49 const std::string init_lang{"it-IT"};
50 const std::string init_voice{"it-IT-Wavenet-A"};
51 pcfg.put("device", "googleSpeechSynthesizer");
52 pcfg.put("language_code",init_lang);
53 pcfg.put("voice_name",init_voice);
54 pcfg.put("__offline", 1);
55 REQUIRE(dd.open(pcfg));
56 REQUIRE(dd.view(iSynth));
57 }
58
59 const std::string lang_to_set{"en-GB"};
60 const std::string voice_to_set{"en-GB-Neural2-C"};
61 std::string lang_code;
62 std::string voice_name;
63
64 std::string toSynthesize{"This is a text to speech test"};
66 CHECK(iSynth->setLanguage(lang_to_set));
67 CHECK(iSynth->setVoice(voice_to_set));
68 CHECK(iSynth->getLanguage(lang_code));
70 CHECK(iSynth->getVoice(voice_name));
72
73 // For the moment being, actually using the API for test only purposes doesn't seem like a good idea since it will waste money
74 //CHECK(iSynth->synthesize(toSynthesize,outputSound));
75 //CHECK(outputSound == snd);
76
77 //"Close all polydrivers and check"
78 {
79 CHECK(dd.close());
80 }
81 }
82
83 Network::setLocalMode(false);
84}
bool view(T *&x)
Get an interface to the device driver.
A generic interface for speech synthesis.
A container for a device driver.
Definition PolyDriver.h:23
bool close() override
Close the DeviceDriver.
bool open(const std::string &txt)
Construct and configure a device by its common name.
A mini-server for performing network communication in the background.
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::googleSpeechSynthesizer_test", "[yarp::dev]")
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.
bool read(ImageOf< PixelRgb > &dest, const std::string &src, image_fileformat format=FORMAT_ANY)