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
15#include "google/cloud/texttospeech/v1/text_to_speech_client.h"
16#include "google/protobuf/repeated_ptr_field.h"
17
19
20// Constants
21const std::pair SPEED_RANGE{0.25, 4.0};
22const std::pair PITCH_RANGE{-20.0, 20.0};
23
39{
40public:
45 GoogleSpeechSynthesizer& operator=(GoogleSpeechSynthesizer&&) noexcept = delete;
46 ~GoogleSpeechSynthesizer() override = default;
47
53 bool _voiceSupported(const std::string& voice_name);
54
55 // DeviceDriver
56 bool open(yarp::os::Searchable& config) override;
57 bool close() override;
58
59 // yarp::dev::ISpeechSynthesizer
60 yarp::dev::ReturnValue setLanguage(const std::string& language="auto") override;
61 yarp::dev::ReturnValue getLanguage(std::string& language) override;
62 yarp::dev::ReturnValue setVoice(const std::string& voice_name = "auto") override;
63 yarp::dev::ReturnValue getVoice(std::string& voice_name) override;
64 yarp::dev::ReturnValue setSpeed(const double speed=0) override;
65 yarp::dev::ReturnValue getSpeed(double& speed) override;
66 yarp::dev::ReturnValue setPitch(const double pitch) override;
67 yarp::dev::ReturnValue getPitch(double& pitch) override;
68 yarp::dev::ReturnValue synthesize(const std::string& text, yarp::sig::Sound& sound) override;
69
70private:
71 bool m_offline{false};
72 std::shared_ptr<google::cloud::texttospeech_v1::TextToSpeechClient> m_synthClient{nullptr};
73 std::shared_ptr<google::cloud::texttospeech::v1::SynthesisInput> m_synthInput{nullptr};
74 std::shared_ptr<google::cloud::texttospeech::v1::VoiceSelectionParams> m_synthVoiceSelParams{nullptr};
75 std::shared_ptr<google::cloud::texttospeech::v1::AudioConfig> m_synthAudioConfig{nullptr};
76 google::protobuf::RepeatedPtrField<google::cloud::texttospeech::v1::Voice> m_synthVoices{nullptr};
77};
78
79#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 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