YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
kokoroSpeechSynthesizer_test.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2026 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::kokoroSpeechSynthesizer_test", "[yarp::dev]")
23{
24 YARP_REQUIRE_PLUGIN("kokoroSpeechSynthesizer", "device");
25
26 Network::setLocalMode(true);
27
28 SECTION("Checking kokoroSpeechSynthesizer device")
29 {
30 ISpeechSynthesizer* iSynth{nullptr};
31 PolyDriver dd;
32
33 //"Checking opening device"
34 {
36 pcfg.put("device", "kokoroSpeechSynthesizer");
37 pcfg.put("language", "en");
38 pcfg.put("voice", "auto");
39 pcfg.put("speed", 1.0);
40 REQUIRE(dd.open(pcfg));
41 REQUIRE(dd.view(iSynth));
42 }
43
44 // Interface-level state checks (fast; keep the model out of it).
45 const std::string lang_to_set{"en-gb"};
46 const std::string voice_to_set{"bf_emma"};
47 std::string lang_code;
48 std::string voice_name;
49
50 CHECK(iSynth->setLanguage(lang_to_set));
51 CHECK(iSynth->getLanguage(lang_code));
53
54 // Put the language back to a stable default before continuing.
55 CHECK(iSynth->setLanguage("en"));
56 CHECK(iSynth->getLanguage(lang_code));
57 CHECK(lang_code == "en");
58
59 CHECK(iSynth->setVoice(voice_to_set));
60 CHECK(iSynth->getVoice(voice_name));
62
63 double speed = 0.0;
64 CHECK(iSynth->setSpeed(1.5));
65 CHECK(iSynth->getSpeed(speed));
66 CHECK(speed == 1.5);
67
68 double pitch = 1.0;
69 CHECK(iSynth->setPitch(0.0));
70 CHECK(iSynth->getPitch(pitch));
71 CHECK(pitch == 0.0);
72
73 // Error handling: invalid ranges and unknown language must fail.
74 CHECK_FALSE(iSynth->setSpeed(0.0));
75 CHECK_FALSE(iSynth->setSpeed(5.0));
76 CHECK_FALSE(iSynth->setLanguage("zz"));
77
78 // The synthesis test is heavy (downloads/loads the Kokoro model), so it
79 // is opt-in via KOKORO_TEST_SYNTHESIZE.
80 const char* synthFlag = std::getenv("KOKORO_TEST_SYNTHESIZE");
81 if (!(synthFlag != nullptr && std::string(synthFlag) == "1")) {
82 // YARP_SKIP_TEST marks the test skipped; the goto keeps the compiler
83 // happy about the label while being unreachable at runtime.
84 YARP_SKIP_TEST("Kokoro synthesis test skipped (set KOKORO_TEST_SYNTHESIZE=1 to enable)");
85 goto skip_synthesis;
86 }
87 {
88 const std::string toSynthesize{"This is a Kokoro synthesis test from YARP"};
90 CHECK(iSynth->synthesize(toSynthesize, outputSound));
91 CHECK(outputSound.getSamples() > 0);
92 CHECK(outputSound.getFrequency() > 0);
93 }
95
96 //"Close all polydrivers and check"
97 {
98 CHECK(dd.close());
99 }
100 }
101
102 Network::setLocalMode(false);
103}
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:32
Class for storing sounds See Audio in YARP for additional documentation on YARP audio.
Definition Sound.h:39
TEST_CASE("dev::kokoroSpeechSynthesizer_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.