From 7604cac68c53dd3c01cfc0e131e2a7f985b40ff7 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Wed, 30 Jul 2008 08:51:23 -0500 Subject: [PATCH] fixed the garbage characters bug This fixes the bug that was causing garbage characters to be spoken. Also it sets the initial voice to "default". --- espeakup.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/espeakup.c b/espeakup.c index a0daf5d..bffb53c 100644 --- a/espeakup.c +++ b/espeakup.c @@ -43,6 +43,7 @@ struct synth_t { int fd; int pitch; int rate; + char voice[40]; int volume; int len; char *buf; @@ -63,6 +64,11 @@ static void set_rate (struct synth_t *s) espeak_SetParameter(espeakRATE, s->rate * rateMultiplier + rateOffset, 0); } +static void set_voice(struct synth_t *s) +{ + espeak_SetVoiceByName(s->voice); +} + static void set_volume (struct synth_t *s) { espeak_SetParameter(espeakVOLUME, s->volume * volumeMultiplier, 0); @@ -75,9 +81,7 @@ static void stop_speech(void) static void speak_text(struct synth_t *s) { - if (! s->len) - return; - espeak_Synth(s->buf, s->len, 0, POS_CHARACTER, 0, 0, NULL, s); + espeak_Synth(s->buf, s->len + 1, 0, POS_CHARACTER, 0, 0, NULL, NULL); for (s->len = 0; s->len < maxBufferSize; s->len++) *(s->buf+s->len) = 0; s->len = 0; @@ -192,13 +196,16 @@ static void main_loop (struct synth_t *s) int main (int argc, char **argv) { - int opt; - struct synth_t s; + struct synth_t s = { + .debug = 0, + .pitch = 5, + .rate = 5, + .voice = "default", + .volume = 5, + }; + + int opt; - s.debug = 0; - s.pitch = 5; - s.rate = 5; - s.volume = 5; s.buf = malloc(maxBufferSize); if (! s.buf) { printf("Unable to allocate buffer!\n"); @@ -216,6 +223,7 @@ int main (int argc, char **argv) break; } } + /* become a daemon */ if (! s.debug) daemon(0, 1); @@ -232,6 +240,7 @@ int main (int argc, char **argv) espeak_SetSynthCallback(SynthCallback); /* Setup initial voice parameters */ + set_voice(&s); set_pitch (&s); set_rate (&s); set_volume(&s);