icub-client
subSystem_speech.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2014 WYSIWYD Consortium, European Commission FP7 Project ICT-612139
3 * Authors: Stéphane Lallée
4 * email: stephane.lallee@gmail.com
5 * website: https://github.com/robotology/icub-client/
6 * Permission is granted to copy, distribute, and/or modify this program
7 * under the terms of the GNU General Public License, version 2 or any
8 * later version published by the Free Software Foundation.
9 *
10 * A copy of the license can be found at
11 * icub-client/license/gpl.txt
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16 * Public License for more details
17 */
18 
19 #ifndef __ICUBCLIENT_SUBSYSTEM_SPEECH_H__
20 #define __ICUBCLIENT_SUBSYSTEM_SPEECH_H__
21 
22 #define SUBSYSTEM_SPEECH "speech"
23 #define SUBSYSTEM_SPEECH_ESPEAK "speech_espeak"
24 
25 #include <iostream>
26 #include <iterator>
27 #include <algorithm>
28 
30 #include "icubclient/functions.h"
31 
32 namespace icubclient{
39 {
40 protected:
41  yarp::os::Port tts;
43 public:
48  SubSystem_Speech(const std::string &masterName);
49  virtual bool connect();
50 
56  virtual void TTS(const std::string &text, bool shouldWait = true);
57 
62  void SetOptions(const std::string &custom);
63 
67  bool isSpeaking();
68 
69  virtual void Close();
70 };
71 
72 //--------------------------------------------------------------------------------------------
73 
80 {
81 protected:
82  int m_speed;
83  int m_pitch;
84 
85 public:
86 
87  SubSystem_Speech_eSpeak(std::string &masterName) :SubSystem_Speech(masterName) {
89  m_speed = 100;
90  m_pitch = 50;
91  }
92 
93  void SetVoiceParameters(int speed = 100, int pitch = 50, std::string voice = "en") {
94  speed = (std::max)(80, speed);
95  speed = (std::min)(450, speed);
96  pitch = (std::max)(0, pitch);
97  pitch = (std::min)(99, pitch);
98  m_speed = speed;
99  m_pitch = pitch;
100  std::stringstream ss;
101  ss << "-s " << speed << " -p " << pitch << " -v " << voice;
102  yarp::os::Bottle param;
103  param.addString("set");
104  param.addString("opt");
105  param.addString(ss.str().c_str());
106  portRPC.write(param);
107  }
108 };
109 }//Namespace
110 #endif
111 
112 
std::string m_type
Definition: subSystem.h:47
Abstract subSystem for speech management (Text to Speech)
virtual void TTS(const std::string &text, bool shouldWait=true)
Produce text to speech output.
yarp::os::RpcClient portRPC
Definition: subSystem.h:48
Abstract class to handle sub-systems of the icub-client.
Definition: subSystem.h:43
SubSystem_Speech(const std::string &masterName)
Default constructor.
yarp::os::Port tts
Port to /iSpeak.
void SetVoiceParameters(int speed=100, int pitch=50, std::string voice="en")
SubSystem for speech synthesis with emotional tuning of speed and pitch using eSpeak.
void SetOptions(const std::string &custom)
Set the command line options sent by iSpeak.
bool isSpeaking()
Check if iSpeak is currently speaking.
#define SUBSYSTEM_SPEECH_ESPEAK
virtual void Close()
Clean up resources.
SubSystem_Speech_eSpeak(std::string &masterName)