YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
TtsDevice.h
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
6#ifndef YARP_TTSDEVICE_H
7#define YARP_TTSDEVICE_H
8
11#include <curl/curl.h>
12#include <vector>
13#include <algorithm>
14#include <yarp/os/all.h>
15#include <yarp/sig/Sound.h>
16#include <iomanip> // for std::setw, std::hex, std::setfill
17
19
31const std::vector<std::string> VOICES{
32 "alloy",
33 "echo",
34 "fable",
35 "nova",
36 "onyx",
37 "shimmer"};
38
39class TtsDevice :
43{
44public:
45 TtsDevice();
46 TtsDevice(const TtsDevice&) = delete;
47 TtsDevice(TtsDevice&&) noexcept = delete;
48 TtsDevice& operator=(const TtsDevice&) = delete;
49 TtsDevice& operator=(TtsDevice&&) noexcept = delete;
50 ~TtsDevice() override = default;
51
52 // DeviceDriver
53 bool open(yarp::os::Searchable& config) override;
54 bool close() override;
55
56 // ISpeechSynthesizer
57 yarp::dev::ReturnValue setLanguage(const std::string& language="auto") override;
58 yarp::dev::ReturnValue getLanguage(std::string& language) override;
59 yarp::dev::ReturnValue setVoice(const std::string& voice_name = "auto") override;
60 yarp::dev::ReturnValue getVoice(std::string& voice_name) override;
61 yarp::dev::ReturnValue setSpeed(const double speed=0) override;
62 yarp::dev::ReturnValue getSpeed(double& speed) override;
63 yarp::dev::ReturnValue setPitch(const double pitch) override;
64 yarp::dev::ReturnValue getPitch(double& pitch) override;
65 yarp::dev::ReturnValue synthesize(const std::string& text, yarp::sig::Sound& sound) override;
66
67private:
68 std::string m_voiceName{VOICES[3]};
69 std::string m_url;
70 std::string m_apiKey;
71 struct curl_slist *headers{nullptr};
72 static size_t _writeCallback(void *contents, size_t size, size_t nmemb, std::vector<uint8_t> *output);
73 std::string _escapeJsonString(const std::string &input);
74 bool _voiceNameIsValid(const std::string& voice_name);
75};
76
77#endif // YARP_TTSDEVICE_H
This class is the parameters parser for class TtsDevice.
yarp::dev::ReturnValue setVoice(const std::string &voice_name="auto") override
Sets the voice set for speech synthesis.
Definition TtsDevice.cpp:84
bool close() override
Close the DeviceDriver.
Definition TtsDevice.cpp:66
yarp::dev::ReturnValue synthesize(const std::string &text, yarp::sig::Sound &sound) override
Performs the speech synthesis.
TtsDevice(const TtsDevice &)=delete
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
Definition TtsDevice.cpp:33
yarp::dev::ReturnValue setLanguage(const std::string &language="auto") override
Sets the language for speech synthesis.
Definition TtsDevice.cpp:72
yarp::dev::ReturnValue setPitch(const double pitch) override
Sets the pitch for speech synthesis.
yarp::dev::ReturnValue getVoice(std::string &voice_name) override
Gets the current voice set for speech synthesis.
yarp::dev::ReturnValue getLanguage(std::string &language) override
Gets the current language set for speech synthesis.
Definition TtsDevice.cpp:78
TtsDevice(TtsDevice &&) noexcept=delete
yarp::dev::ReturnValue getSpeed(double &speed) override
Gets the current voice speed.
yarp::dev::ReturnValue setSpeed(const double speed=0) override
Sets the voice speed for speech synthesis.
yarp::dev::ReturnValue getPitch(double &pitch) override
Gets the current pitch set for speech synthesis.
Interface implemented by all device drivers.
A generic interface for speech synthesis.
const std::vector< std::string > VOICES
ttsDevice: A yarp device for speech synthesis using azure openai APIs
Definition TtsDevice.h:31
STL namespace.
The main, catch-all namespace for YARP.
Definition dirs.h:16