-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCSpeechSynth.cpp
127 lines (106 loc) · 4.36 KB
/
CSpeechSynth.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* +---------------------------------------------------------------------------+
| Open MORA (MObile Robot Arquitecture) |
| |
| http://babel.isa.uma.es/mora/ |
| |
| Copyright (C) 2010 University of Malaga |
| |
| This software was written by the Machine Perception and Intelligent |
| Robotics (MAPIR) Lab, University of Malaga (Spain). |
| Contact: Jose-Luis Blanco <[email protected]> |
| |
| This file is part of the MORA project. |
| |
| MORA is free software: you can redistribute it and/or modify |
| it under the terms of the GNU General Public License as published by |
| the Free Software Foundation, either version 3 of the License, or |
| (at your option) any later version. |
| |
| MORA is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of the GNU General Public License |
| along with MORA. If not, see <http://www.gnu.org/licenses/>. |
| |
+---------------------------------------------------------------------------+ */
/** @moos_module A simple module to provide easy text to speech.
* The module gets the text to synthesize via the OpenMORA variable SAY, and copy it to the OS clipboard.
* It is designed to work with applications such as IVONE that reproduces all text present in the clipboard.
*/
#include "CSpeechSynth.hpp"
#include <sstream>
#include <iomanip>
#include <iostream>
using namespace std;
using namespace mrpt;
using namespace mrpt::utils;
CSpeechSynthApp::CSpeechSynthApp()
{
}
CSpeechSynthApp::~CSpeechSynthApp()
{
}
bool CSpeechSynthApp::OnStartUp()
{
// Read parameters (if any) from the mission configuration file.
return DoRegistrations();
}
bool CSpeechSynthApp::Iterate()
{
return true;
}
bool CSpeechSynthApp::OnConnectToServer()
{
DoRegistrations();
return true;
}
bool CSpeechSynthApp::OnCommandMsg( CMOOSMsg Msg )
{
if(Msg.IsSkewed(MOOSTime())) return true;
if(!Msg.IsString()) return MOOSFail("This module only accepts string command messages\n");
const std::string sCmd = Msg.GetString();
//MOOSTrace("COMMAND RECEIVED: %s\n",sCmd.c_str());
// Process the command "sCmd".
return true;
}
bool CSpeechSynthApp::DoRegistrations()
{
//! @moos_subscribe SAY
AddMOOSVariable("SAY","SAY","SAY",0);
//! @moos_subscribe SHUTDOWN
AddMOOSVariable("SHUTDOWN","SHUTDOWN","SHUTDOWN",0);
RegisterMOOSVariables();
return true;
}
bool CSpeechSynthApp::OnNewMail(MOOSMSG_LIST &NewMail)
{
std::string cad;
for(MOOSMSG_LIST::iterator i=NewMail.begin();i!=NewMail.end();++i)
{
if (i->GetName()=="SAY")
{
MOOSTrace("[SpeechSynth]: Received text: %s\n",i->GetString().c_str());
const size_t len = strlen(i->GetString().c_str()) + 1;
HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, len);
memcpy(GlobalLock(hMem), i->GetString().c_str(), len);
GlobalUnlock(hMem);
OpenClipboard(0);
EmptyClipboard();
SetClipboardData(CF_TEXT, hMem);
CloseClipboard();
// Is it necessary to free the memory allocated????
// GlobalFree(hMem);
m_Comms.Notify("VOICE_EVENT_DONE","");
}
if( (i->GetName()=="SHUTDOWN") && (MOOSStrCmp(i->GetString(),"true")) )
{
// Disconnect comms:
MOOSTrace("Closing Module \n");
this->RequestQuit();
}
}
UpdateMOOSVariables(NewMail);
return true;
}