YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
GoogleSpeechSynthesizer.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_GOOGLESPEECHSYNTH_H
7#define YARP_GOOGLESPEECHSYNTH_H
8
11#include <yarp/sig/Sound.h>
12#include <yarp/os/Network.h>
13#include <algorithm>
14#include <vector>
15#include <map>
16
17#include "google/cloud/texttospeech/v1/text_to_speech_client.h"
18#include "google/protobuf/repeated_ptr_field.h"
19#include "google/cloud/options.h"
20#include "google/cloud/grpc_options.h"
21
23
24// Constants
25const std::pair SPEED_RANGE{0.25, 4.0};
26const std::pair PITCH_RANGE{-20.0, 20.0};
27
43{
44public:
49 GoogleSpeechSynthesizer& operator=(GoogleSpeechSynthesizer&&) noexcept = delete;
50 ~GoogleSpeechSynthesizer() override = default;
51
57 bool _voiceSupported(const std::string& voice_name);
58
59 // DeviceDriver
60 bool open(yarp::os::Searchable& config) override;
61 bool close() override;
62
63 // yarp::dev::ISpeechSynthesizer
64 yarp::dev::ReturnValue setLanguage(const std::string& language="auto") override;
65 yarp::dev::ReturnValue getLanguage(std::string& language) override;
66 yarp::dev::ReturnValue setVoice(const std::string& voice_name = "auto") override;
67 yarp::dev::ReturnValue getVoice(std::string& voice_name) override;
68 yarp::dev::ReturnValue getAvailableVoices(yarp::sig::VectorOfString& voices_list) override;
69 yarp::dev::ReturnValue setSpeed(const double speed=0) override;
70 yarp::dev::ReturnValue getSpeed(double& speed) override;
71 yarp::dev::ReturnValue setPitch(const double pitch) override;
72 yarp::dev::ReturnValue getPitch(double& pitch) override;
73 yarp::dev::ReturnValue synthesize(const std::string& text, yarp::sig::Sound& sound) override;
74
75private:
76
77 std::shared_ptr<google::cloud::texttospeech_v1::TextToSpeechClient> _getClient(google::cloud::Options opts);
78 yarp::dev::ReturnValue _getVoicesList(std::string language_code, google::protobuf::RepeatedPtrField<google::cloud::texttospeech::v1::Voice>& voices_list);
79
80 bool m_offline{false};
81 std::map<std::string, std::string> m_defaultVoicesMap; // map<language_code, default_voice_name>
82 std::shared_ptr<google::cloud::texttospeech_v1::TextToSpeechClient> m_synthClient{nullptr};
83 std::shared_ptr<google::cloud::texttospeech::v1::SynthesisInput> m_synthInput{nullptr};
84 std::shared_ptr<google::cloud::texttospeech::v1::VoiceSelectionParams> m_synthVoiceSelParams{nullptr};
85 std::shared_ptr<google::cloud::texttospeech::v1::AudioConfig> m_synthAudioConfig{nullptr};
86 google::protobuf::RepeatedPtrField<google::cloud::texttospeech::v1::Voice> m_synthVoices{nullptr};
87};
88
89#endif // YARP_GOOGLESPEECHSYNTH_H
const std::pair PITCH_RANGE
const std::pair SPEED_RANGE
This class is the parameters parser for class GoogleSpeechSynthesizer.
googleSpeechSynthesizer: A yarp device for speech synthesis using google cloud cpp libraries
bool _voiceSupported(const std::string &voice_name)
Checks whether or not a particular voice name is supported by the currently selected language code.
yarp::dev::ReturnValue getPitch(double &pitch) override
Gets the current pitch set for speech synthesis.
GoogleSpeechSynthesizer(const GoogleSpeechSynthesizer &)=delete
yarp::dev::ReturnValue getLanguage(std::string &language) override
Gets the current language set for speech synthesis.
GoogleSpeechSynthesizer(GoogleSpeechSynthesizer &&) noexcept=delete
yarp::dev::ReturnValue setSpeed(const double speed=0) override
Sets the voice speed for speech synthesis.
yarp::dev::ReturnValue getAvailableVoices(yarp::sig::VectorOfString &voices_list) override
yarp::dev::ReturnValue getSpeed(double &speed) override
Gets the current voice speed.
yarp::dev::ReturnValue setPitch(const double pitch) override
Sets the pitch for speech synthesis.
yarp::dev::ReturnValue setVoice(const std::string &voice_name="auto") override
Sets the voice set for speech synthesis.
bool close() override
Close the DeviceDriver.
yarp::dev::ReturnValue setLanguage(const std::string &language="auto") override
Sets the language for speech synthesis.
yarp::dev::ReturnValue synthesize(const std::string &text, yarp::sig::Sound &sound) override
Performs the speech synthesis.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
yarp::dev::ReturnValue getVoice(std::string &voice_name) override
Gets the current voice set for speech synthesis.
Interface implemented by all device drivers.
A generic interface for speech synthesis.
STL namespace.
The main, catch-all namespace for YARP.
Definition dirs.h:16