This repository has been archived by the owner on Feb 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspeechdspeaker.c
246 lines (187 loc) · 5.67 KB
/
speechdspeaker.c
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/*
* GNOME Speech - Speech services for the GNOME desktop
*
* Copyright 2002 Sun Microsystems Inc.
* Copyright 2005 Brailcom, o.p.s.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* speechdspeaker.c.c: Implementation of the SpeechdSynthesisDriver
* object-- a GNOME Speech driver for the Speechd
* Speech Synthesis System
*
*/
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <libbonobo.h>
#include "speechdsynthesisdriver.h"
#include "speechdspeaker.h"
#include "libspeechd.h"
/* Put a message into the logfile (stderr currently) */
#define DBG(arg...) \
{ \
fprintf(stderr," SpeechdSpeaker: "); \
fprintf(stderr,arg); \
fprintf(stderr,"\n"); \
fflush(stderr); \
}
#define RET_STATUS(status) \
if (status == 0) return TRUE; \
else return FALSE;
#define GET_SPEAKER() \
SpeechdSpeaker *speaker = speechd_speaker_from_servant (servant); \
#define GET_DRIVER() \
Speaker *s = SPEAKER (speaker); \
SpeechdSynthesisDriver *d = SPEECHD_SYNTHESIS_DRIVER(s->driver);
static GObjectClass *parent_class;
static SpeechdSpeaker *
speechd_speaker_from_servant (PortableServer_Servant *servant)
{
return SPEECHD_SPEAKER(bonobo_object_from_servant (servant));
}
static CORBA_long
speechd_say (PortableServer_Servant servant,
const CORBA_char *text,
CORBA_Environment *ev)
{
static int counter = 1;
int ret;
GET_SPEAKER();
GET_DRIVER();
/* Refresh if needded */
if (d->last_speaker != speaker || speaker_needs_parameter_refresh (SPEAKER(speaker)))
{
/* if (!d->last_speaker || strcmp (d->last_speaker->voice, s->voice))*/
spd_set_voice_type(speaker->conn, speaker->voice);
speaker_refresh_parameters (SPEAKER(s));
d->last_speaker = speaker;
}
ret = spd_say(speaker->conn, SPD_MESSAGE, text);
if (ret < 0) return -1;
return counter++;
}
static CORBA_boolean
speechd_stop (PortableServer_Servant servant,
CORBA_Environment *ev)
{
int ret;
GET_SPEAKER();
ret = spd_cancel(speaker->conn);
RET_STATUS(ret);
}
static CORBA_boolean
speechd_isSpeaking (PortableServer_Servant servant,
CORBA_Environment *ev)
{
/* Speech Dispatcher is currently not able to provide this
capability */
return FALSE;
}
static CORBA_boolean
speechd_registerSpeechCallback (PortableServer_Servant servant,
const GNOME_Speech_SpeechCallback callback,
CORBA_Environment *ev)
{
/* Speech Dispatcher is currently not able to provide this
capability */
return FALSE;
}
static gboolean
festival_set_rate (Speaker *speaker,
gdouble new_value)
{
fprintf(stderr, "festival_set_rate\n");
fflush(stderr);
return TRUE;
}
#define SPEECHD_SET_NUM(name) \
static gboolean \
speechd_set_ ## name (Speaker *speaker, \
gdouble new_value) \
{ \
DBG("Setting parameter " #name " to value %d", (int) new_value); \
int ret; \
SpeechdSpeaker *speechd_speaker = SPEECHD_SPEAKER (speaker); \
ret = spd_set_ ## name (speechd_speaker->conn, (int) new_value); \
RET_STATUS(ret); \
}
SPEECHD_SET_NUM(rate);
SPEECHD_SET_NUM(pitch);
SPEECHD_SET_NUM(volume);
static void
speechd_speaker_init (SpeechdSpeaker *s)
{
int ret;
s->voice = NULL;
SPEAKER(s)->clb_list = NULL;
s->conn = spd_open("gnomespeech", "main", "unknown");
ret = spd_set_voice_type(s->conn, s->voice);
}
static void
speechd_speaker_finalize (GObject *obj)
{
SpeechdSpeaker *s = SPEECHD_SPEAKER (obj);
Speaker *speaker = SPEAKER (s);
if (speaker->driver)
g_object_unref (speaker->driver);
if (s->voice)
g_free (s->voice);
if (parent_class->finalize)
parent_class->finalize (obj);
}
static void
speechd_speaker_class_init (SpeechdSpeakerClass *klass)
{
SpeakerClass *class = SPEAKER_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS(klass);
parent_class = g_type_class_peek_parent (klass);
object_class->finalize = speechd_speaker_finalize;
/* Initialize parent class epv table */
class->epv.say = speechd_say;
class->epv.stop = speechd_stop;
class->epv.isSpeaking = speechd_isSpeaking;
class->epv.registerSpeechCallback = speechd_registerSpeechCallback;
}
BONOBO_TYPE_FUNC (SpeechdSpeaker,
speaker_get_type (),
speechd_speaker);
#define ADD_PARAM(name, min, def, max) \
speaker_add_parameter (s, \
#name, \
min, \
def, \
max, \
speechd_set_ ## name);
SpeechdSpeaker *
speechd_speaker_new (GObject *driver,
const GNOME_Speech_VoiceInfo *info)
{
SpeechdSpeaker *speaker;
Speaker *s;
speaker = g_object_new (SPEECHD_SPEAKER_TYPE, NULL);
s = SPEAKER (speaker);
s->driver = g_object_ref (driver);
DBG("Adding parameters");
/* Add supported parameters */
ADD_PARAM(rate, -100, 0, 100);
ADD_PARAM(pitch, -100, 0, 100);
ADD_PARAM(volume, -100, 0, 100);
if (info != NULL && info->name != NULL) speaker->voice = strdup(info->name);
return speaker;
}