From d373fb2aa7fbf673594cd98225877c6998dc99ad Mon Sep 17 00:00:00 2001 From: Christopher Brannon Date: Fri, 19 Jun 2009 14:37:38 -0500 Subject: [PATCH 001/181] An initial stab at ALSA support. It's very raw right now. --- Makefile | 5 +- alsa.c | 149 +++++++++++++++++++++++++++++++++++++++++++++++++ espeak_sound.c | 9 +++ espeakup.c | 11 +++- espeakup.h | 4 ++ synth.c | 2 + 6 files changed, 178 insertions(+), 2 deletions(-) create mode 100644 alsa.c create mode 100644 espeak_sound.c diff --git a/Makefile b/Makefile index b636930..c45f437 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,18 @@ INSTALL = install +CFLAGS ?= -DUSE_ALSA SRCS = \ cli.c \ + alsa.c \ espeakup.c \ + espeak_sound.c \ queue.c \ softsynth.c \ synth.c OBJS = $(SRCS:.c=.o) -LDLIBS = -lespeak -lpthread +LDLIBS = -lespeak -lasound PREFIX = /usr MANDIR = $(PREFIX)/share/man/man8 diff --git a/alsa.c b/alsa.c new file mode 100644 index 0000000..88af42f --- /dev/null +++ b/alsa.c @@ -0,0 +1,149 @@ +/* + * espeakup - interface which allows speakup to use espeak + * + * Copyright (C) 2008 William Hubbs + * + * This program 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. + * + * This program 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 this program. If not, see . + */ + +/* + * File: alsa.c + * Description: Produce audio by calling the ALSA library directly. +*/ + +#ifdef USE_ALSA +#include +#include +#include +#define ALSA_PCM_NEW_HW_PARAMS_API +#include +#include "espeakup.h" + +int minimum(int x, int y) +{ + if (x <= y) + return x; + else + return y; +} + +static snd_pcm_t *handle; +static snd_pcm_hw_params_t *params; +snd_pcm_status_t *status; +static unsigned int rate = 22050; /* sample rate */ +static int dir = 0; +static snd_pcm_uframes_t frames; + +static int alsa_play_callback(short *audio, int numsamples, + espeak_EVENT * events) +{ + int samples_written = 0; + int avail; + int to_write; + snd_pcm_state_t state; + snd_pcm_status(handle, status); + state = snd_pcm_status_get_state(status); + if (state != SND_PCM_STATE_RUNNING) + snd_pcm_prepare(handle); + + while (numsamples > 0) { + if (stopped) { + snd_pcm_drop(handle); + stopped = 0; + return 1; + } + avail = snd_pcm_avail_update(handle); + if (avail <= 0) + continue; + avail = minimum(avail, 32 * 2); + to_write = minimum(avail, numsamples); + samples_written = snd_pcm_writei(handle, audio, to_write); + if (samples_written == -EPIPE) + snd_pcm_prepare(handle); + else { + numsamples -= samples_written; + audio += samples_written; + } + } + + return 0; +} + +int init_audio(void) +{ + int rc; + unsigned saved_rate; + + rate = 22050; + + /* Open PCM device for playback. */ + rc = snd_pcm_open(&handle, "default", SND_PCM_STREAM_PLAYBACK, 0); + if (rc < 0) { + fprintf(stderr, + "unable to open pcm device: %s\n", snd_strerror(rc)); + return rc; + } + + /* Allocate a hardware parameters object. */ + rc = snd_pcm_hw_params_malloc(¶ms); + if (rc < 0) { + fprintf(stderr, + "Unable to allocate memory to store audio parameters: %s\n", + snd_strerror(rc)); + return rc; + } + rc = snd_pcm_status_malloc(&status); + if (rc < 0) { + fprintf(stderr, + "Unable to allocate memory to store PCM status: %s\n", + snd_strerror(rc)); + return rc; + } + + + /* Fill it in with default values. */ + snd_pcm_hw_params_any(handle, params); + + /* Set the desired hardware parameters. */ + + /* Interleaved mode */ + snd_pcm_hw_params_set_access(handle, params, + SND_PCM_ACCESS_RW_INTERLEAVED); + + /* Signed 16-bit little-endian format */ + snd_pcm_hw_params_set_format(handle, params, SND_PCM_FORMAT_S16_LE); + + /* One channel */ + snd_pcm_hw_params_set_channels(handle, params, 1); + + saved_rate = rate; + snd_pcm_hw_params_set_rate_near(handle, params, &rate, &dir); + + /* Set period size to 32 frames. */ + frames = 32; + snd_pcm_hw_params_set_period_size_near(handle, params, &frames, &dir); + + /* Write the parameters to the driver */ + rc = snd_pcm_hw_params(handle, params); + if (rc < 0) { + fprintf(stderr, + "unable to set hw parameters: %s\n", snd_strerror(rc)); + return rc; + } + + audio_mode = AUDIO_OUTPUT_RETRIEVAL; + audio_callback = alsa_play_callback; + return 0; +} +#endif diff --git a/espeak_sound.c b/espeak_sound.c new file mode 100644 index 0000000..e8a3a03 --- /dev/null +++ b/espeak_sound.c @@ -0,0 +1,9 @@ +#ifndef USE_ALSA +#include "espeakup.h" +int init_audio(void) +{ + audio_mode = AUDIO_OUTPUT_PLAYBACK; + audio_callback = NULL; + return 0; +} +#endif diff --git a/espeakup.c b/espeakup.c index 7157b0a..5aaf818 100644 --- a/espeakup.c +++ b/espeakup.c @@ -42,6 +42,10 @@ const int defaultVolume = 5; char *defaultVoice = NULL; int debug = 0; +volatile int stopped = 0; +espeak_AUDIO_OUTPUT audio_mode; +t_espeak_callback *audio_callback = NULL; + int espeakup_is_running(void) { int rc; @@ -115,6 +119,10 @@ int main(int argc, char **argv) signal(SIGINT, espeakup_sighandler); signal(SIGTERM, espeakup_sighandler); + if (init_audio() < 0) { + return 5; + } + if (!debug) { /* become a daemon */ daemon(0, 1); @@ -127,7 +135,8 @@ int main(int argc, char **argv) } /* initialize espeak */ - espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 0, NULL, 0); + espeak_Initialize(audio_mode, 0, NULL, 0); + espeak_SetSynthCallback(audio_callback); /* Setup initial voice parameters */ if (defaultVoice) { diff --git a/espeakup.h b/espeakup.h index 75292c8..eb67e3d 100644 --- a/espeakup.h +++ b/espeakup.h @@ -78,5 +78,9 @@ extern int open_softsynth(void); extern void close_softsynth(void); extern void main_loop(struct synth_t *s); extern void * queue_runner(void *arg); +extern int init_audio(void); +extern volatile int stopped; +extern espeak_AUDIO_OUTPUT audio_mode; +extern t_espeak_callback *audio_callback; #endif diff --git a/synth.c b/synth.c index fe6ca15..f7f13c3 100644 --- a/synth.c +++ b/synth.c @@ -114,6 +114,7 @@ espeak_ERROR set_volume(struct synth_t * s, int vol, enum adjust_t adj) espeak_ERROR stop_speech(void) { + stopped = 1; return (espeak_Cancel()); } @@ -121,6 +122,7 @@ espeak_ERROR speak_text(struct synth_t * s) { espeak_ERROR rc; + stopped = 0; rc = espeak_Synth(s->buf, s->len + 1, 0, POS_CHARACTER, 0, 0, NULL, NULL); return rc; From 08e46c58a804c380f73a8be3403663af790a48bd Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Sat, 20 Jun 2009 13:09:57 -0500 Subject: [PATCH 002/181] indentation fixes --- espeakup.c | 2 +- espeakup.h | 4 ++-- softsynth.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/espeakup.c b/espeakup.c index 5aaf818..f323d3c 100644 --- a/espeakup.c +++ b/espeakup.c @@ -110,7 +110,7 @@ int main(int argc, char **argv) } /* open the softsynth. */ - if (! open_softsynth()) { + if (!open_softsynth()) { perror("Unable to open the softsynth device"); return 3; } diff --git a/espeakup.h b/espeakup.h index eb67e3d..5a31cdf 100644 --- a/espeakup.h +++ b/espeakup.h @@ -66,7 +66,7 @@ extern espeak_ERROR set_frequency(struct synth_t *s, int freq, extern espeak_ERROR set_pitch(struct synth_t *s, int pitch, enum adjust_t adj); extern espeak_ERROR set_punctuation(struct synth_t *s, int punct, - enum adjust_t adj); + enum adjust_t adj); extern espeak_ERROR set_rate(struct synth_t *s, int rate, enum adjust_t adj); extern espeak_ERROR set_voice(struct synth_t *s, char *voice); @@ -77,7 +77,7 @@ extern espeak_ERROR speak_text(struct synth_t *s); extern int open_softsynth(void); extern void close_softsynth(void); extern void main_loop(struct synth_t *s); -extern void * queue_runner(void *arg); +extern void *queue_runner(void *arg); extern int init_audio(void); extern volatile int stopped; diff --git a/softsynth.c b/softsynth.c index b482ec9..f10f000 100644 --- a/softsynth.c +++ b/softsynth.c @@ -127,12 +127,12 @@ static void process_buffer(struct synth_t *s, char *buf, ssize_t length) int open_softsynth(void) { - int rc; + int rc; softFD = open("/dev/softsynth", O_RDWR | O_NONBLOCK); if (softFD < 0) rc = 0; - else + else rc = 1; return rc; } From 1c440e5a42ef2606c0330f816b00172ab309505c Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Sat, 20 Jun 2009 16:17:42 -0500 Subject: [PATCH 003/181] fixed stop_speech issue The stop_speech function needs to test the return code from espeak_Cancel() to be sure the operation was successful before signaling the callback to stop the audio. --- synth.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/synth.c b/synth.c index f7f13c3..8d5c076 100644 --- a/synth.c +++ b/synth.c @@ -114,8 +114,12 @@ espeak_ERROR set_volume(struct synth_t * s, int vol, enum adjust_t adj) espeak_ERROR stop_speech(void) { - stopped = 1; - return (espeak_Cancel()); + espeak_ERROR rc; + + rc = espeak_Cancel(); + if (rc == EE_OK) + stopped = 1; + return rc; } espeak_ERROR speak_text(struct synth_t * s) From 1d02169aa584ebb8c8739c4b1255abd3ee51e709 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Sat, 20 Jun 2009 16:46:50 -0500 Subject: [PATCH 004/181] alsa support is conditional This commit updates the makefile and the documentation to explain how to build alsa support. It has not been fully tested, so it is not built by default. Also, I was able to remove the conditional compile directives from the source. --- Makefile | 44 ++++++++++++++++++++++++++------------------ README | 11 +++++++++++ alsa.c | 2 -- espeak_sound.c | 2 -- 4 files changed, 37 insertions(+), 22 deletions(-) diff --git a/Makefile b/Makefile index c45f437..059db6b 100644 --- a/Makefile +++ b/Makefile @@ -1,23 +1,30 @@ -INSTALL = install - -CFLAGS ?= -DUSE_ALSA -SRCS = \ - cli.c \ - alsa.c \ - espeakup.c \ - espeak_sound.c \ - queue.c \ - softsynth.c \ - synth.c - -OBJS = $(SRCS:.c=.o) - -LDLIBS = -lespeak -lasound +CFLAGS += -Wall +LDLIBS = -lespeak PREFIX = /usr MANDIR = $(PREFIX)/share/man/man8 BINDIR = $(PREFIX)/bin +INSTALL = install + +ALSA_SRCS = alsa.c +ESPEAK_SRCS = espeak_sound.c +SRCS = \ + cli.c \ + espeakup.c \ + queue.c \ + softsynth.c \ + synth.c + +ifeq ($(AUDIO),alsa) +SRCS += $(ALSA_SRCS) +LDLIBS += -lasound +else +SRCS += $(ESPEAK_SRCS) +endif + +OBJS = $(SRCS:.c=.o) + all: espeakup install: espeakup @@ -27,7 +34,7 @@ install: espeakup $(INSTALL) -m 0644 espeakup.8 $(DESTDIR)$(MANDIR) clean: - $(RM) $(OBJS) + $(RM) *.o distclean: clean $(RM) espeakup @@ -44,5 +51,6 @@ softsynth.o: softsynth.c espeakup.h synth.o: synth.c espeakup.h -%.o: %.c - $(CC) -c -Wall $(CFLAGS) $(CPPFLAGS) -o $@ $< +alsa.o: alsa.c espeakup.h + +espeak_sound.o: espeak_sound.c espeakup.h diff --git a/README b/README index 317db39..c5f6f5e 100644 --- a/README +++ b/README @@ -25,6 +25,17 @@ To install espeakup, first cd into the directory where you unpacked the tarball, then issue make to compile the program. Once this is done, as root, issue make install. This will install espeakup in /usr/bin. +ALSA SUPPORT +============ + +Direct support for alsa was just contributed to this project; I would +like to thank Chris Brannon for his work on this. Currently,, it is in +the early stages, so if you have any suggestions or patches, I am +definitely interested. + +To build with alsa support, add "AUDIO=alsa" to the make command when you +compile the program. + Starting Up =========== diff --git a/alsa.c b/alsa.c index 88af42f..ebfaeab 100644 --- a/alsa.c +++ b/alsa.c @@ -22,7 +22,6 @@ * Description: Produce audio by calling the ALSA library directly. */ -#ifdef USE_ALSA #include #include #include @@ -146,4 +145,3 @@ int init_audio(void) audio_callback = alsa_play_callback; return 0; } -#endif diff --git a/espeak_sound.c b/espeak_sound.c index e8a3a03..f89538a 100644 --- a/espeak_sound.c +++ b/espeak_sound.c @@ -1,4 +1,3 @@ -#ifndef USE_ALSA #include "espeakup.h" int init_audio(void) { @@ -6,4 +5,3 @@ int init_audio(void) audio_callback = NULL; return 0; } -#endif From 0ad70b4eaa35d57867f20c631f60841fde824e20 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Sat, 20 Jun 2009 19:14:42 -0500 Subject: [PATCH 005/181] Revert "fixed stop_speech issue" This reverts commit 1c440e5a42ef2606c0330f816b00172ab309505c. --- synth.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/synth.c b/synth.c index 8d5c076..f7f13c3 100644 --- a/synth.c +++ b/synth.c @@ -114,12 +114,8 @@ espeak_ERROR set_volume(struct synth_t * s, int vol, enum adjust_t adj) espeak_ERROR stop_speech(void) { - espeak_ERROR rc; - - rc = espeak_Cancel(); - if (rc == EE_OK) - stopped = 1; - return rc; + stopped = 1; + return (espeak_Cancel()); } espeak_ERROR speak_text(struct synth_t * s) From 91b8960b6add66a982327e68d51f75d25f828af8 Mon Sep 17 00:00:00 2001 From: Christopher Brannon Date: Sun, 21 Jun 2009 12:46:43 -0500 Subject: [PATCH 006/181] Protect the stopped variable with a mutex. An oversight. Should have done this in the initial commit. volatile does not imply atomic. --- alsa.c | 17 +++++++++++++++++ espeak_sound.c | 15 +++++++++++++++ espeakup.h | 2 ++ synth.c | 4 ++++ 4 files changed, 38 insertions(+) diff --git a/alsa.c b/alsa.c index ebfaeab..48de434 100644 --- a/alsa.c +++ b/alsa.c @@ -25,10 +25,23 @@ #include #include #include +#include #define ALSA_PCM_NEW_HW_PARAMS_API #include #include "espeakup.h" +static pthread_mutex_t audio_mutex = PTHREAD_MUTEX_INITIALIZER; + +void lock_audio_mutex(void) +{ + pthread_mutex_lock(&audio_mutex); +} + +void unlock_audio_mutex(void) +{ + pthread_mutex_unlock(&audio_mutex); +} + int minimum(int x, int y) { if (x <= y) @@ -57,11 +70,15 @@ static int alsa_play_callback(short *audio, int numsamples, snd_pcm_prepare(handle); while (numsamples > 0) { + lock_audio_mutex(); if (stopped) { snd_pcm_drop(handle); stopped = 0; + unlock_audio_mutex(); return 1; } + unlock_audio_mutex(); + avail = snd_pcm_avail_update(handle); if (avail <= 0) continue; diff --git a/espeak_sound.c b/espeak_sound.c index f89538a..c9dcd82 100644 --- a/espeak_sound.c +++ b/espeak_sound.c @@ -5,3 +5,18 @@ int init_audio(void) audio_callback = NULL; return 0; } + +/* + * lock_audio_mutex and unlock_audio_mutex are no-ops if we use native + * sound support. The stopped variable is never read; no need to protect it. + */ + +void lock_audio_mutex(void) +{ + return; +} + +void unlock_audio_mutex(void) +{ + return; +} diff --git a/espeakup.h b/espeakup.h index 5a31cdf..a289e32 100644 --- a/espeakup.h +++ b/espeakup.h @@ -79,6 +79,8 @@ extern void close_softsynth(void); extern void main_loop(struct synth_t *s); extern void *queue_runner(void *arg); extern int init_audio(void); +extern void lock_audio_mutex(void); +extern void unlock_audio_mutex(void); extern volatile int stopped; extern espeak_AUDIO_OUTPUT audio_mode; diff --git a/synth.c b/synth.c index f7f13c3..e19d95e 100644 --- a/synth.c +++ b/synth.c @@ -114,7 +114,9 @@ espeak_ERROR set_volume(struct synth_t * s, int vol, enum adjust_t adj) espeak_ERROR stop_speech(void) { + lock_audio_mutex(); stopped = 1; + unlock_audio_mutex(); return (espeak_Cancel()); } @@ -122,7 +124,9 @@ espeak_ERROR speak_text(struct synth_t * s) { espeak_ERROR rc; + lock_audio_mutex(); stopped = 0; + unlock_audio_mutex(); rc = espeak_Synth(s->buf, s->len + 1, 0, POS_CHARACTER, 0, 0, NULL, NULL); return rc; From a69342fcada7fe6533b81c1ae0bad23f983a399a Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Mon, 22 Jun 2009 19:09:07 -0500 Subject: [PATCH 007/181] removed some blank lines and put the variables at the top of the file --- alsa.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/alsa.c b/alsa.c index 48de434..2f62f20 100644 --- a/alsa.c +++ b/alsa.c @@ -32,6 +32,13 @@ static pthread_mutex_t audio_mutex = PTHREAD_MUTEX_INITIALIZER; +static snd_pcm_t *handle; +static snd_pcm_hw_params_t *params; +snd_pcm_status_t *status; +static unsigned int rate = 22050; /* sample rate */ +static int dir = 0; +static snd_pcm_uframes_t frames; + void lock_audio_mutex(void) { pthread_mutex_lock(&audio_mutex); @@ -50,13 +57,6 @@ int minimum(int x, int y) return y; } -static snd_pcm_t *handle; -static snd_pcm_hw_params_t *params; -snd_pcm_status_t *status; -static unsigned int rate = 22050; /* sample rate */ -static int dir = 0; -static snd_pcm_uframes_t frames; - static int alsa_play_callback(short *audio, int numsamples, espeak_EVENT * events) { @@ -64,6 +64,7 @@ static int alsa_play_callback(short *audio, int numsamples, int avail; int to_write; snd_pcm_state_t state; + snd_pcm_status(handle, status); state = snd_pcm_status_get_state(status); if (state != SND_PCM_STATE_RUNNING) @@ -127,7 +128,6 @@ int init_audio(void) return rc; } - /* Fill it in with default values. */ snd_pcm_hw_params_any(handle, params); From 94e23a3a027dfd887f6713e745a0b97ec09dfbc7 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Mon, 22 Jun 2009 20:44:42 -0500 Subject: [PATCH 008/181] fixed error condition check in alsa.c The check was looking for a specific error when it should have been just checking for failure. --- alsa.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/alsa.c b/alsa.c index 2f62f20..f1f20ef 100644 --- a/alsa.c +++ b/alsa.c @@ -86,14 +86,13 @@ static int alsa_play_callback(short *audio, int numsamples, avail = minimum(avail, 32 * 2); to_write = minimum(avail, numsamples); samples_written = snd_pcm_writei(handle, audio, to_write); - if (samples_written == -EPIPE) + if (samples_written < 0) { snd_pcm_prepare(handle); - else { + } else { numsamples -= samples_written; audio += samples_written; } } - return 0; } From 3bb78df86c3a135660864e1e07c1d5266a575bce Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Mon, 22 Jun 2009 21:36:31 -0500 Subject: [PATCH 009/181] Do not set the period. --- alsa.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/alsa.c b/alsa.c index f1f20ef..8a81342 100644 --- a/alsa.c +++ b/alsa.c @@ -37,7 +37,6 @@ static snd_pcm_hw_params_t *params; snd_pcm_status_t *status; static unsigned int rate = 22050; /* sample rate */ static int dir = 0; -static snd_pcm_uframes_t frames; void lock_audio_mutex(void) { @@ -145,10 +144,6 @@ int init_audio(void) saved_rate = rate; snd_pcm_hw_params_set_rate_near(handle, params, &rate, &dir); - /* Set period size to 32 frames. */ - frames = 32; - snd_pcm_hw_params_set_period_size_near(handle, params, &frames, &dir); - /* Write the parameters to the driver */ rc = snd_pcm_hw_params(handle, params); if (rc < 0) { From a5d1a48f42bbb3de67551113c1f15da10f7b916d Mon Sep 17 00:00:00 2001 From: Christopher Brannon Date: Mon, 22 Jun 2009 22:21:10 -0500 Subject: [PATCH 010/181] Obtain sample rate from the value of espeak_Initialize. espeak uses a sample rate of 22050 HZ, but let's not rely on that knowledge. espeak_Initialize returns the sample rate on success, so rely on that value when selecting a rate. --- alsa.c | 6 +----- espeak_sound.c | 2 +- espeakup.c | 15 +++++++++++---- espeakup.h | 2 +- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/alsa.c b/alsa.c index 8a81342..6ab8b60 100644 --- a/alsa.c +++ b/alsa.c @@ -35,7 +35,6 @@ static pthread_mutex_t audio_mutex = PTHREAD_MUTEX_INITIALIZER; static snd_pcm_t *handle; static snd_pcm_hw_params_t *params; snd_pcm_status_t *status; -static unsigned int rate = 22050; /* sample rate */ static int dir = 0; void lock_audio_mutex(void) @@ -95,12 +94,10 @@ static int alsa_play_callback(short *audio, int numsamples, return 0; } -int init_audio(void) +int init_audio(unsigned int rate) { int rc; - unsigned saved_rate; - rate = 22050; /* Open PCM device for playback. */ rc = snd_pcm_open(&handle, "default", SND_PCM_STREAM_PLAYBACK, 0); @@ -141,7 +138,6 @@ int init_audio(void) /* One channel */ snd_pcm_hw_params_set_channels(handle, params, 1); - saved_rate = rate; snd_pcm_hw_params_set_rate_near(handle, params, &rate, &dir); /* Write the parameters to the driver */ diff --git a/espeak_sound.c b/espeak_sound.c index c9dcd82..92e6017 100644 --- a/espeak_sound.c +++ b/espeak_sound.c @@ -1,5 +1,5 @@ #include "espeakup.h" -int init_audio(void) +int init_audio(unsigned int rate) { audio_mode = AUDIO_OUTPUT_PLAYBACK; audio_callback = NULL; diff --git a/espeakup.c b/espeakup.c index f323d3c..4ec7580 100644 --- a/espeakup.c +++ b/espeakup.c @@ -95,6 +95,7 @@ void espeakup_sighandler(int sig) int main(int argc, char **argv) { + int rate; pthread_t queue_thread_id; struct synth_t s = { .voice = "", @@ -119,9 +120,6 @@ int main(int argc, char **argv) signal(SIGINT, espeakup_sighandler); signal(SIGTERM, espeakup_sighandler); - if (init_audio() < 0) { - return 5; - } if (!debug) { /* become a daemon */ @@ -135,7 +133,16 @@ int main(int argc, char **argv) } /* initialize espeak */ - espeak_Initialize(audio_mode, 0, NULL, 0); + rate = espeak_Initialize(audio_mode, 0, NULL, 0); + if (rate < 0) { + fprintf(stderr, "Unable to initialize espeak.\n"); + return 5; + } + + if (init_audio((unsigned int) rate) < 0) { + return 6; + } + espeak_SetSynthCallback(audio_callback); /* Setup initial voice parameters */ diff --git a/espeakup.h b/espeakup.h index a289e32..afe75ad 100644 --- a/espeakup.h +++ b/espeakup.h @@ -78,7 +78,7 @@ extern int open_softsynth(void); extern void close_softsynth(void); extern void main_loop(struct synth_t *s); extern void *queue_runner(void *arg); -extern int init_audio(void); +extern int init_audio(unsigned int rate); extern void lock_audio_mutex(void); extern void unlock_audio_mutex(void); extern volatile int stopped; From ec9d8b1ee23095afadd07bd05cbf1ca21df11b8f Mon Sep 17 00:00:00 2001 From: Christopher Brannon Date: Mon, 22 Jun 2009 22:53:41 -0500 Subject: [PATCH 011/181] Add error-checking to the snd_pcm_set_* calls. These can fail. They do more than simply manipulate a structure. --- alsa.c | 66 +++++++++++++++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/alsa.c b/alsa.c index 6ab8b60..556cf12 100644 --- a/alsa.c +++ b/alsa.c @@ -47,6 +47,12 @@ void unlock_audio_mutex(void) pthread_mutex_unlock(&audio_mutex); } +int sound_error(int err, const char *msg) +{ + fprintf(stderr, "%s: %s\n", msg, snd_strerror(err)); + return err; +} + int minimum(int x, int y) { if (x <= y) @@ -101,52 +107,56 @@ int init_audio(unsigned int rate) /* Open PCM device for playback. */ rc = snd_pcm_open(&handle, "default", SND_PCM_STREAM_PLAYBACK, 0); - if (rc < 0) { - fprintf(stderr, - "unable to open pcm device: %s\n", snd_strerror(rc)); - return rc; - } + if (rc < 0) + return sound_error(rc, "unable to open pcm device"); /* Allocate a hardware parameters object. */ rc = snd_pcm_hw_params_malloc(¶ms); - if (rc < 0) { - fprintf(stderr, - "Unable to allocate memory to store audio parameters: %s\n", - snd_strerror(rc)); - return rc; - } + if (rc < 0) + return sound_error(rc, + "Unable to allocate memory to store audio parameters"); + rc = snd_pcm_status_malloc(&status); - if (rc < 0) { - fprintf(stderr, - "Unable to allocate memory to store PCM status: %s\n", - snd_strerror(rc)); - return rc; - } + if (rc < 0) + return sound_error(rc, + "Unable to allocate memory to store PCM status"); /* Fill it in with default values. */ - snd_pcm_hw_params_any(handle, params); + rc = snd_pcm_hw_params_any(handle, params); + + if (rc < 0) + return sound_error(rc, + "Unable to establish defaults for hardware parameters."); /* Set the desired hardware parameters. */ /* Interleaved mode */ - snd_pcm_hw_params_set_access(handle, params, - SND_PCM_ACCESS_RW_INTERLEAVED); + rc = snd_pcm_hw_params_set_access(handle, params, + SND_PCM_ACCESS_RW_INTERLEAVED); + + if (rc < 0) + return sound_error(rc, "Error selecting interleaved mode."); /* Signed 16-bit little-endian format */ - snd_pcm_hw_params_set_format(handle, params, SND_PCM_FORMAT_S16_LE); + rc = snd_pcm_hw_params_set_format(handle, params, + SND_PCM_FORMAT_S16_LE); + if (rc < 0) + return sound_error(rc, "Unable to select signed 16-bit samples"); /* One channel */ - snd_pcm_hw_params_set_channels(handle, params, 1); + rc = snd_pcm_hw_params_set_channels(handle, params, 1); - snd_pcm_hw_params_set_rate_near(handle, params, &rate, &dir); + if (rc < 0) + return sound_error(rc, "Unable to use mono output."); + + rc = snd_pcm_hw_params_set_rate_near(handle, params, &rate, &dir); + if (rc < 0) + return sound_error(rc, "Unable to set sample rate"); /* Write the parameters to the driver */ rc = snd_pcm_hw_params(handle, params); - if (rc < 0) { - fprintf(stderr, - "unable to set hw parameters: %s\n", snd_strerror(rc)); - return rc; - } + if (rc < 0) + return sound_error(rc, "unable to set hw parameters"); audio_mode = AUDIO_OUTPUT_RETRIEVAL; audio_callback = alsa_play_callback; From 739d79cff89f2792aa47813e08bdcbb3065c32de Mon Sep 17 00:00:00 2001 From: Christopher Brannon Date: Tue, 23 Jun 2009 10:01:44 -0500 Subject: [PATCH 012/181] Select audio mode before initializing espeak. --- alsa.c | 6 +++++- espeak_sound.c | 7 ++++++- espeakup.c | 1 + espeakup.h | 1 + 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/alsa.c b/alsa.c index 556cf12..daa2adc 100644 --- a/alsa.c +++ b/alsa.c @@ -100,6 +100,11 @@ static int alsa_play_callback(short *audio, int numsamples, return 0; } +void select_audio_mode(void) +{ + audio_mode = AUDIO_OUTPUT_RETRIEVAL; +} + int init_audio(unsigned int rate) { int rc; @@ -158,7 +163,6 @@ int init_audio(unsigned int rate) if (rc < 0) return sound_error(rc, "unable to set hw parameters"); - audio_mode = AUDIO_OUTPUT_RETRIEVAL; audio_callback = alsa_play_callback; return 0; } diff --git a/espeak_sound.c b/espeak_sound.c index 92e6017..826ecff 100644 --- a/espeak_sound.c +++ b/espeak_sound.c @@ -1,7 +1,12 @@ #include "espeakup.h" -int init_audio(unsigned int rate) + +void select_audio_mode(void) { audio_mode = AUDIO_OUTPUT_PLAYBACK; +} + +int init_audio(unsigned int rate) +{ audio_callback = NULL; return 0; } diff --git a/espeakup.c b/espeakup.c index 4ec7580..03760c7 100644 --- a/espeakup.c +++ b/espeakup.c @@ -133,6 +133,7 @@ int main(int argc, char **argv) } /* initialize espeak */ + select_audio_mode(); rate = espeak_Initialize(audio_mode, 0, NULL, 0); if (rate < 0) { fprintf(stderr, "Unable to initialize espeak.\n"); diff --git a/espeakup.h b/espeakup.h index afe75ad..851b597 100644 --- a/espeakup.h +++ b/espeakup.h @@ -78,6 +78,7 @@ extern int open_softsynth(void); extern void close_softsynth(void); extern void main_loop(struct synth_t *s); extern void *queue_runner(void *arg); +extern void select_audio_mode(void); extern int init_audio(unsigned int rate); extern void lock_audio_mutex(void); extern void unlock_audio_mutex(void); From b108764b02e0d6eb1e8a3074cf2f85f10eb01d03 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Tue, 23 Jun 2009 11:02:09 -0500 Subject: [PATCH 013/181] removed the audio_callback variable --- alsa.c | 2 +- espeak_sound.c | 1 - espeakup.c | 3 --- espeakup.h | 1 - 4 files changed, 1 insertion(+), 6 deletions(-) diff --git a/alsa.c b/alsa.c index daa2adc..421cb71 100644 --- a/alsa.c +++ b/alsa.c @@ -163,6 +163,6 @@ int init_audio(unsigned int rate) if (rc < 0) return sound_error(rc, "unable to set hw parameters"); - audio_callback = alsa_play_callback; + espeak_SetSynthCallback(alsa_play_callback); return 0; } diff --git a/espeak_sound.c b/espeak_sound.c index 826ecff..4c2d6d1 100644 --- a/espeak_sound.c +++ b/espeak_sound.c @@ -7,7 +7,6 @@ void select_audio_mode(void) int init_audio(unsigned int rate) { - audio_callback = NULL; return 0; } diff --git a/espeakup.c b/espeakup.c index 03760c7..abcc66b 100644 --- a/espeakup.c +++ b/espeakup.c @@ -44,7 +44,6 @@ int debug = 0; volatile int stopped = 0; espeak_AUDIO_OUTPUT audio_mode; -t_espeak_callback *audio_callback = NULL; int espeakup_is_running(void) { @@ -144,8 +143,6 @@ int main(int argc, char **argv) return 6; } - espeak_SetSynthCallback(audio_callback); - /* Setup initial voice parameters */ if (defaultVoice) { set_voice(&s, defaultVoice); diff --git a/espeakup.h b/espeakup.h index 851b597..feafa6f 100644 --- a/espeakup.h +++ b/espeakup.h @@ -85,5 +85,4 @@ extern void unlock_audio_mutex(void); extern volatile int stopped; extern espeak_AUDIO_OUTPUT audio_mode; -extern t_espeak_callback *audio_callback; #endif From 26ab109bd8e14fd3d26a434cac2e5760b23dbf0a Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Tue, 23 Jun 2009 16:13:52 -0500 Subject: [PATCH 014/181] moved the check for stop out of the loop In the callback, we should check to see if the stopped flag is true whether or not we are processing audio. --- alsa.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/alsa.c b/alsa.c index 421cb71..014bfa6 100644 --- a/alsa.c +++ b/alsa.c @@ -69,21 +69,21 @@ static int alsa_play_callback(short *audio, int numsamples, int to_write; snd_pcm_state_t state; + lock_audio_mutex(); + if (stopped) { + snd_pcm_drop(handle); + stopped = 0; + unlock_audio_mutex(); + return 1; + } + unlock_audio_mutex(); + snd_pcm_status(handle, status); state = snd_pcm_status_get_state(status); if (state != SND_PCM_STATE_RUNNING) snd_pcm_prepare(handle); while (numsamples > 0) { - lock_audio_mutex(); - if (stopped) { - snd_pcm_drop(handle); - stopped = 0; - unlock_audio_mutex(); - return 1; - } - unlock_audio_mutex(); - avail = snd_pcm_avail_update(handle); if (avail <= 0) continue; From 24e7d667bce7568585e1e644b1935c8fe0709b75 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Tue, 23 Jun 2009 20:34:04 -0500 Subject: [PATCH 015/181] queue fixes This adds retry processing back to the queue functions. queue_remove should only be called after the head entry on the queue is processed successfully. --- queue.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/queue.c b/queue.c index 83fb979..5e96c91 100644 --- a/queue.c +++ b/queue.c @@ -67,28 +67,27 @@ static void free_entry(struct queue_entry_t *entry) /* Remove and return the entry at the head of the queue. * Return NULL if queue is empty. */ -static struct queue_entry_t *queue_remove(void) +static void queue_remove(void) { - struct queue_entry_t *temp = NULL; + struct queue_entry_t *temp; if (last) { temp = last; last = temp->next; - if (!last) first = last; + free_entry(temp); } - - return temp; } void queue_clear(void) { + struct queue_entry_t *temp; + pthread_mutex_lock(&queue_guard); while (last) { - struct queue_entry_t *entry = queue_remove(); - if (entry) - free_entry(entry); + temp = last->next; + queue_remove(); } pthread_mutex_unlock(&queue_guard); /* We aren't adding data to the queue, so no need to signal. */ @@ -133,39 +132,39 @@ void queue_add_text(char *txt, size_t length) static void queue_process_entry(struct synth_t *s) { espeak_ERROR error; - struct queue_entry_t *current = queue_remove(); pthread_mutex_unlock(&queue_guard); /* So "reader" can go. */ - if (current) { - switch (current->cmd) { + if (last) { + switch (last->cmd) { case CMD_SET_FREQUENCY: - error = set_frequency(s, current->value, current->adjust); + error = set_frequency(s, last->value, last->adjust); break; case CMD_SET_PITCH: - error = set_pitch(s, current->value, current->adjust); + error = set_pitch(s, last->value, last->adjust); break; case CMD_SET_PUNCTUATION: - error = set_punctuation(s, current->value, current->adjust); + error = set_punctuation(s, last->value, last->adjust); break; case CMD_SET_RATE: - error = set_rate(s, current->value, current->adjust); + error = set_rate(s, last->value, last->adjust); break; case CMD_SET_VOICE: break; case CMD_SET_VOLUME: - error = set_volume(s, current->value, current->adjust); + error = set_volume(s, last->value, last->adjust); break; case CMD_SPEAK_TEXT: - s->buf = current->buf; - s->len = current->len; + s->buf = last->buf; + s->len = last->len; error = speak_text(s); break; default: break; } - free_entry(current); + if (error == EE_OK) + queue_remove(); } } From f58d9984ce6d615158d53a6cf1b5d503296973ab Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Wed, 24 Jun 2009 16:59:23 -0500 Subject: [PATCH 016/181] Now the queue runner/softsynth handler clears the queue Thanks to Chris Brannon for the patch. --- espeakup.c | 2 +- espeakup.h | 2 ++ queue.c | 54 +++++++++++++++++++++++++++++++++++++++-------------- softsynth.c | 3 +-- 4 files changed, 44 insertions(+), 17 deletions(-) diff --git a/espeakup.c b/espeakup.c index abcc66b..34c1257 100644 --- a/espeakup.c +++ b/espeakup.c @@ -81,7 +81,7 @@ void espeakup_sighandler(int sig) printf("Caught signal %i\n", sig); /* clear the queue */ - queue_clear(); + stop_runner(); /* shut down espeak and close the softsynth */ espeak_Terminate(); diff --git a/espeakup.h b/espeakup.h index feafa6f..5433a77 100644 --- a/espeakup.h +++ b/espeakup.h @@ -76,6 +76,7 @@ extern espeak_ERROR stop_speech(void); extern espeak_ERROR speak_text(struct synth_t *s); extern int open_softsynth(void); extern void close_softsynth(void); +extern void stop_runner(void); extern void main_loop(struct synth_t *s); extern void *queue_runner(void *arg); extern void select_audio_mode(void); @@ -83,6 +84,7 @@ extern int init_audio(unsigned int rate); extern void lock_audio_mutex(void); extern void unlock_audio_mutex(void); extern volatile int stopped; +extern volatile int runner_must_stop; extern espeak_AUDIO_OUTPUT audio_mode; #endif diff --git a/queue.c b/queue.c index 5e96c91..002ad61 100644 --- a/queue.c +++ b/queue.c @@ -26,7 +26,9 @@ #include "espeakup.h" pthread_cond_t runner_awake = PTHREAD_COND_INITIALIZER; +pthread_cond_t stop_acknowledged = PTHREAD_COND_INITIALIZER; pthread_mutex_t queue_guard = PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t stop_guard = PTHREAD_MUTEX_INITIALIZER; struct queue_entry_t { enum command_t cmd; @@ -37,6 +39,7 @@ struct queue_entry_t { struct queue_entry_t *next; }; +volatile int runner_must_stop = 0; static struct queue_entry_t *first = NULL; static struct queue_entry_t *last = NULL; @@ -67,7 +70,7 @@ static void free_entry(struct queue_entry_t *entry) /* Remove and return the entry at the head of the queue. * Return NULL if queue is empty. */ -static void queue_remove(void) +static void queue_remove(void) { struct queue_entry_t *temp; @@ -84,12 +87,10 @@ void queue_clear(void) { struct queue_entry_t *temp; - pthread_mutex_lock(&queue_guard); while (last) { temp = last->next; queue_remove(); } - pthread_mutex_unlock(&queue_guard); /* We aren't adding data to the queue, so no need to signal. */ } @@ -132,42 +133,58 @@ void queue_add_text(char *txt, size_t length) static void queue_process_entry(struct synth_t *s) { espeak_ERROR error; + struct queue_entry_t *current = last; pthread_mutex_unlock(&queue_guard); /* So "reader" can go. */ - - if (last) { - switch (last->cmd) { + if (current) { + switch (current->cmd) { case CMD_SET_FREQUENCY: - error = set_frequency(s, last->value, last->adjust); + error = set_frequency(s, current->value, current->adjust); break; case CMD_SET_PITCH: - error = set_pitch(s, last->value, last->adjust); + error = set_pitch(s, current->value, current->adjust); break; case CMD_SET_PUNCTUATION: - error = set_punctuation(s, last->value, last->adjust); + error = set_punctuation(s, current->value, current->adjust); break; case CMD_SET_RATE: - error = set_rate(s, last->value, last->adjust); + error = set_rate(s, current->value, current->adjust); break; case CMD_SET_VOICE: break; case CMD_SET_VOLUME: - error = set_volume(s, last->value, last->adjust); + error = set_volume(s, current->value, current->adjust); break; case CMD_SPEAK_TEXT: - s->buf = last->buf; - s->len = last->len; + s->buf = current->buf; + s->len = current->len; error = speak_text(s); break; default: break; } + pthread_mutex_lock(&queue_guard); if (error == EE_OK) queue_remove(); + pthread_mutex_unlock(&queue_guard); } } +/* + * Tell the runner to stop speech and clear its queue. + */ +void stop_runner(void) +{ + pthread_mutex_lock(&stop_guard); + pthread_mutex_lock(&queue_guard); + runner_must_stop = 1; + pthread_mutex_unlock(&queue_guard); + pthread_cond_signal(&runner_awake); /* Wake runner, if necessary. */ + pthread_cond_wait(&stop_acknowledged, &stop_guard); + pthread_mutex_unlock(&stop_guard); +} + /* queue_runner is the "main" function of our secondary (queue-processing) * thread. * First, lock queue_guard, because it needs to be locked when we call @@ -195,10 +212,19 @@ void *queue_runner(void *arg) while (1) { pthread_cond_wait(&runner_awake, &queue_guard); - while (last) { + while (last && ! runner_must_stop ) { queue_process_entry(synth); pthread_mutex_lock(&queue_guard); } + + if (runner_must_stop) { + pthread_mutex_lock(&stop_guard); + queue_clear(); + stop_speech(); + runner_must_stop = 0; + pthread_mutex_unlock(&stop_guard); + pthread_cond_signal(&stop_acknowledged); + } } return NULL; diff --git a/softsynth.c b/softsynth.c index f10f000..1a93edb 100644 --- a/softsynth.c +++ b/softsynth.c @@ -173,8 +173,7 @@ void main_loop(struct synth_t *s) *(buf + length) = 0; cp = strrchr(buf, synthFlushChar); if (cp) { - queue_clear(); - stop_speech(); + stop_runner(); memmove(buf, cp + 1, strlen(cp + 1) + 1); length = strlen(buf); } From 9d1cabdd0d513c45bafdf7cc9c62b503f4a0f31d Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Wed, 24 Jun 2009 20:03:31 -0500 Subject: [PATCH 017/181] started work on multi-threading more of the program The goal is to create threads for the reader, que runner/espeak processing and signal handling. As of this commit, this code is still being worked on, so it is broken. --- Makefile | 1 + espeakup.c | 77 +++++++++++++++++------------------------------------ espeakup.h | 3 ++- signal.c | 62 ++++++++++++++++++++++++++++++++++++++++++ softsynth.c | 42 +++++++++++++++-------------- 5 files changed, 111 insertions(+), 74 deletions(-) create mode 100644 signal.c diff --git a/Makefile b/Makefile index 059db6b..f784aac 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,7 @@ SRCS = \ cli.c \ espeakup.c \ queue.c \ + signal.c \ softsynth.c \ synth.c diff --git a/espeakup.c b/espeakup.c index 34c1257..db86232 100644 --- a/espeakup.c +++ b/espeakup.c @@ -43,6 +43,7 @@ char *defaultVoice = NULL; int debug = 0; volatile int stopped = 0; +volatile int should_run = 1; espeak_AUDIO_OUTPUT audio_mode; int espeakup_is_running(void) @@ -75,27 +76,14 @@ int create_pid_file(void) return 0; } -void espeakup_sighandler(int sig) -{ - if (debug) - printf("Caught signal %i\n", sig); - - /* clear the queue */ - stop_runner(); - - /* shut down espeak and close the softsynth */ - espeak_Terminate(); - close_softsynth(); - - if (!debug) - unlink(pidPath); - exit(0); -} - int main(int argc, char **argv) { + sigset_t sigset; int rate; + int err; + pthread_t signal_thread_id; pthread_t queue_thread_id; + pthread_t softsynth_thread_id; struct synth_t s = { .voice = "", }; @@ -115,54 +103,37 @@ int main(int argc, char **argv) return 3; } - /* register signal handler */ - signal(SIGINT, espeakup_sighandler); - signal(SIGTERM, espeakup_sighandler); - - +/* + * If we are not in debug mode, become a daemon and store the pid. + */ if (!debug) { - /* become a daemon */ daemon(0, 1); - - /* write our pid file. */ if (create_pid_file() < 0) { perror("Unable to create pid file"); return 2; } } - /* initialize espeak */ - select_audio_mode(); - rate = espeak_Initialize(audio_mode, 0, NULL, 0); - if (rate < 0) { - fprintf(stderr, "Unable to initialize espeak.\n"); - return 5; - } - - if (init_audio((unsigned int) rate) < 0) { - return 6; - } - - /* Setup initial voice parameters */ - if (defaultVoice) { - set_voice(&s, defaultVoice); - free(defaultVoice); - defaultVoice = NULL; - } - set_frequency(&s, defaultFrequency, ADJ_SET); - set_pitch(&s, defaultPitch, ADJ_SET); - set_rate(&s, defaultRate, ADJ_SET); - set_volume(&s, defaultVolume, ADJ_SET); - espeak_SetParameter(espeakCAPITALS, 0, 0); - - /* Spawn our queue-processing thread. */ - int err = pthread_create(&queue_thread_id, NULL, &queue_runner, &s); + /* create the signal processing thread here. */ + err = pthread_create(&signal_thread_id, NULL, &signal_thread, NULL); if (err != 0) { return 4; } - /* run the main loop */ - main_loop(&s); + /* + * Set up the signal mask which will be the default for all threads. + * We are handling sigint and sigterm, so block them. + */ + sigemptyset(&sigset); + sigaddset(&sigset, SIGINT); + sigaddset(&sigset, SIGTERM); + sigprocmask(SIG_BLOCK, &sigset, NULL); + + /* Spawn our queue-processing thread. */ + err = pthread_create(&queue_thread_id, NULL, &queue_runner, &s); + if (err != 0) { + return 4; + } return 0; } diff --git a/espeakup.h b/espeakup.h index 5433a77..dc1f567 100644 --- a/espeakup.h +++ b/espeakup.h @@ -76,9 +76,10 @@ extern espeak_ERROR stop_speech(void); extern espeak_ERROR speak_text(struct synth_t *s); extern int open_softsynth(void); extern void close_softsynth(void); +extern void *reader_thread(void *arg); extern void stop_runner(void); -extern void main_loop(struct synth_t *s); extern void *queue_runner(void *arg); +extern void *signal_thread(void *arg); extern void select_audio_mode(void); extern int init_audio(unsigned int rate); extern void lock_audio_mutex(void); diff --git a/signal.c b/signal.c new file mode 100644 index 0000000..10e0b90 --- /dev/null +++ b/signal.c @@ -0,0 +1,62 @@ +/* + * espeakup - interface which allows speakup to use espeak + * + * Copyright (C) 2008 William Hubbs + * + * This program 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. + * + * This program 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 this program. If not, see . + */ + +#include +#include + +#include "espeakup.h" + +/* + * We install a dummy signal handler to let the o/s know that we + * do not want the default action to be performed since we are + * handling the signal. + */ +static void dummy_handler(int sig) +{ +} + +void *signal_thread(void *arg) +{ + struct sigaction temp; + sigset_t sigset; + int sig; + int should_run = 1; + + /* install dummy handlers for the signals we want to process */ + temp.sa_handler = dummy_handler; + sigemptyset(&temp.sa_mask); + sigaction(SIGINT, &temp, NULL); + sigaction(SIGTERM, &temp, NULL); + + while(should_run) { + sigfillset(&sigset); + sigwait(&sigset, &sig); + switch (sig) { + case SIGINT: + case SIGTERM: + printf("This is where we shut down.\n"); + should_run = 0; + break; + default: + printf("espeakup caught signal %d\n", sig); + break; + } + } + return NULL; +} diff --git a/softsynth.c b/softsynth.c index 1a93edb..d04f6e4 100644 --- a/softsynth.c +++ b/softsynth.c @@ -35,6 +35,23 @@ const int synthFlushChar = 0x18; static int softFD = 0; +int open_softsynth(void) +{ + int rc; + + softFD = open("/dev/softsynth", O_RDWR | O_NONBLOCK); + if (softFD < 0) + rc = 0; + else + rc = 1; + return rc; +} + +void close_softsynth(void) +{ + close(softFD); +} + static int process_command(struct synth_t *s, char *buf, int start) { char *cp; @@ -125,34 +142,18 @@ static void process_buffer(struct synth_t *s, char *buf, ssize_t length) } } -int open_softsynth(void) -{ - int rc; - - softFD = open("/dev/softsynth", O_RDWR | O_NONBLOCK); - if (softFD < 0) - rc = 0; - else - rc = 1; - return rc; -} - -void close_softsynth(void) -{ - close(softFD); -} - -void main_loop(struct synth_t *s) +void *reader_thread(void *arg) { + struct synth_t *s = (struct synth_t *) arg; fd_set set; ssize_t length; char buf[maxBufferSize]; char *cp; - while (1) { - + while (should_run) { FD_ZERO(&set); FD_SET(softFD, &set); + if (select(softFD + 1, &set, NULL, NULL, NULL) < 0) { if (errno == EINTR) continue; @@ -179,4 +180,5 @@ void main_loop(struct synth_t *s) } process_buffer(s, buf, length); } + return NULL; } From dfc9bbff6518b2de6e4464fd348ae460766606fb Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Wed, 24 Jun 2009 20:12:15 -0500 Subject: [PATCH 018/181] fixed should_run declaration Removed the local declaration of should_run and set up the extern. --- espeakup.h | 1 + signal.c | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/espeakup.h b/espeakup.h index dc1f567..36ee159 100644 --- a/espeakup.h +++ b/espeakup.h @@ -84,6 +84,7 @@ extern void select_audio_mode(void); extern int init_audio(unsigned int rate); extern void lock_audio_mutex(void); extern void unlock_audio_mutex(void); +extern volatile int should_run; extern volatile int stopped; extern volatile int runner_must_stop; diff --git a/signal.c b/signal.c index 10e0b90..89d8a93 100644 --- a/signal.c +++ b/signal.c @@ -36,7 +36,6 @@ void *signal_thread(void *arg) struct sigaction temp; sigset_t sigset; int sig; - int should_run = 1; /* install dummy handlers for the signals we want to process */ temp.sa_handler = dummy_handler; From a58f93cd74fead43927093d36fc775a976788a4b Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Wed, 24 Jun 2009 20:19:24 -0500 Subject: [PATCH 019/181] renamed reader_thread to softsynth_thread --- espeakup.h | 2 +- softsynth.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/espeakup.h b/espeakup.h index 36ee159..b00dd69 100644 --- a/espeakup.h +++ b/espeakup.h @@ -76,7 +76,7 @@ extern espeak_ERROR stop_speech(void); extern espeak_ERROR speak_text(struct synth_t *s); extern int open_softsynth(void); extern void close_softsynth(void); -extern void *reader_thread(void *arg); +extern void *softsynth_thread(void *arg); extern void stop_runner(void); extern void *queue_runner(void *arg); extern void *signal_thread(void *arg); diff --git a/softsynth.c b/softsynth.c index d04f6e4..6d6a13d 100644 --- a/softsynth.c +++ b/softsynth.c @@ -142,7 +142,7 @@ static void process_buffer(struct synth_t *s, char *buf, ssize_t length) } } -void *reader_thread(void *arg) +void *softsynth_thread(void *arg) { struct synth_t *s = (struct synth_t *) arg; fd_set set; From c5fce64f259bce473cd3c9371d7b095639a87fe5 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Wed, 24 Jun 2009 20:44:42 -0500 Subject: [PATCH 020/181] removed open_softsynth and close_softsynth The thread can now handle the softsynth device, so main doesn't need to call these functions. --- espeakup.c | 12 ++++++------ espeakup.h | 2 -- softsynth.c | 28 +++++++++------------------- 3 files changed, 15 insertions(+), 27 deletions(-) diff --git a/espeakup.c b/espeakup.c index db86232..7c8c257 100644 --- a/espeakup.c +++ b/espeakup.c @@ -97,12 +97,6 @@ int main(int argc, char **argv) return 1; } - /* open the softsynth. */ - if (!open_softsynth()) { - perror("Unable to open the softsynth device"); - return 3; - } - /* * If we are not in debug mode, become a daemon and store the pid. */ @@ -135,5 +129,11 @@ int main(int argc, char **argv) return 4; } + /* Spawn our softsynth thread. */ + err = pthread_create(&softsynth_thread_id, NULL, &softsynth_thread, &s); + if (err != 0) { + return 4; + } + return 0; } diff --git a/espeakup.h b/espeakup.h index b00dd69..fd22467 100644 --- a/espeakup.h +++ b/espeakup.h @@ -74,8 +74,6 @@ extern espeak_ERROR set_volume(struct synth_t *s, int vol, enum adjust_t adj); extern espeak_ERROR stop_speech(void); extern espeak_ERROR speak_text(struct synth_t *s); -extern int open_softsynth(void); -extern void close_softsynth(void); extern void *softsynth_thread(void *arg); extern void stop_runner(void); extern void *queue_runner(void *arg); diff --git a/softsynth.c b/softsynth.c index 6d6a13d..06d9cc6 100644 --- a/softsynth.c +++ b/softsynth.c @@ -33,25 +33,6 @@ const size_t maxBufferSize = 1025; /* synth flush character */ const int synthFlushChar = 0x18; -static int softFD = 0; - -int open_softsynth(void) -{ - int rc; - - softFD = open("/dev/softsynth", O_RDWR | O_NONBLOCK); - if (softFD < 0) - rc = 0; - else - rc = 1; - return rc; -} - -void close_softsynth(void) -{ - close(softFD); -} - static int process_command(struct synth_t *s, char *buf, int start) { char *cp; @@ -150,6 +131,13 @@ void *softsynth_thread(void *arg) char buf[maxBufferSize]; char *cp; + /* open the softsynth. */ + softFD = open("/dev/softsynth", O_RDWR | O_NONBLOCK); + if (softFD < 0) { + perror("Unable to open the softsynth device"); + should_run = 0; + } + while (should_run) { FD_ZERO(&set); FD_SET(softFD, &set); @@ -180,5 +168,7 @@ void *softsynth_thread(void *arg) } process_buffer(s, buf, length); } + if (softFD) + close(softFD); return NULL; } From 474580b08b32d713ffb6f23c486685f1927e12c0 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Wed, 24 Jun 2009 21:16:30 -0500 Subject: [PATCH 021/181] add pipe to wake up the softsynth thread This adds a pipe to wake up the softsynth thread, in case we receive a signal while it is in a select. Thanks to Chris Brannon. --- espeakup.c | 7 +++++++ espeakup.h | 3 +++ signal.c | 5 +++++ softsynth.c | 9 ++++++++- 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/espeakup.c b/espeakup.c index 7c8c257..5928bc4 100644 --- a/espeakup.c +++ b/espeakup.c @@ -42,6 +42,7 @@ const int defaultVolume = 5; char *defaultVoice = NULL; int debug = 0; +int self_pipe_fds[2]; volatile int stopped = 0; volatile int should_run = 1; espeak_AUDIO_OUTPUT audio_mode; @@ -123,6 +124,12 @@ int main(int argc, char **argv) sigaddset(&sigset, SIGTERM); sigprocmask(SIG_BLOCK, &sigset, NULL); + /* set up the pipe used to wake the reader. */ + if(pipe(self_pipe_fds) < 0) { + perror("Unable to create pipe"); + return 5; + } + /* Spawn our queue-processing thread. */ err = pthread_create(&queue_thread_id, NULL, &queue_runner, &s); if (err != 0) { diff --git a/espeakup.h b/espeakup.h index fd22467..b6ecb4c 100644 --- a/espeakup.h +++ b/espeakup.h @@ -85,6 +85,9 @@ extern void unlock_audio_mutex(void); extern volatile int should_run; extern volatile int stopped; extern volatile int runner_must_stop; +extern int self_pipe_fds[2]; +#define PIPE_READ_FD (self_pipe_fds[0]) +#define PIPE_WRITE_FD (self_pipe_fds[1]) extern espeak_AUDIO_OUTPUT audio_mode; #endif diff --git a/signal.c b/signal.c index 89d8a93..6fdf6bc 100644 --- a/signal.c +++ b/signal.c @@ -19,6 +19,9 @@ #include #include +#include +#include +#define STOP_MSG "s" #include "espeakup.h" @@ -57,5 +60,7 @@ void *signal_thread(void *arg) break; } } + /* Tell the reader to stop, if it is in a select() call. */ + write(PIPE_WRITE_FD, STOP_MSG, strlen(STOP_MSG)); return NULL; } diff --git a/softsynth.c b/softsynth.c index 06d9cc6..9e700c5 100644 --- a/softsynth.c +++ b/softsynth.c @@ -130,6 +130,8 @@ void *softsynth_thread(void *arg) ssize_t length; char buf[maxBufferSize]; char *cp; + int terminalFD = PIPE_READ_FD; + int greatestFD; /* open the softsynth. */ softFD = open("/dev/softsynth", O_RDWR | O_NONBLOCK); @@ -138,11 +140,16 @@ void *softsynth_thread(void *arg) should_run = 0; } + if (terminalFD > softFD) + greatestFD = terminalFD; + else + greatestFD = softFD; while (should_run) { FD_ZERO(&set); FD_SET(softFD, &set); + FD_SET(terminalFD, &set); - if (select(softFD + 1, &set, NULL, NULL, NULL) < 0) { + if (select(greatestFD + 1, &set, NULL, NULL, NULL) < 0) { if (errno == EINTR) continue; perror("Select failed"); From 0fdca827b851fd0beb9f476c52ec5568ed36174e Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Wed, 24 Jun 2009 21:29:46 -0500 Subject: [PATCH 022/181] check for terminalFD after select() If terminalFD has something to read, we break out of the loop in the softsynth thread. --- softsynth.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/softsynth.c b/softsynth.c index 9e700c5..3eb6c7e 100644 --- a/softsynth.c +++ b/softsynth.c @@ -156,6 +156,9 @@ void *softsynth_thread(void *arg) break; } + if (FD_ISSET(terminalFD, &set)) + break; + if (!FD_ISSET(softFD, &set)) continue; From d82bfcd09ccd4145d17473bc9ae60af223a5f66e Mon Sep 17 00:00:00 2001 From: Christopher Brannon Date: Wed, 24 Jun 2009 21:58:18 -0500 Subject: [PATCH 023/181] Make one thread responsible for handling espeak interaction. Most of the idea for this change came from William: Renamed queue_runner to espeak_thread. Moved espeak initialization and termination to espeak_thread. The while loops that process the queue now use the variable should_run. --- espeakup.c | 26 ++++++++++---------------- espeakup.h | 2 +- queue.c | 43 +++++++++++++++++++++++++++++++++++++++---- 3 files changed, 50 insertions(+), 21 deletions(-) diff --git a/espeakup.c b/espeakup.c index 5928bc4..6edaac2 100644 --- a/espeakup.c +++ b/espeakup.c @@ -33,13 +33,6 @@ const char *Version = "0.71"; /* path to our pid file */ const char *pidPath = "/var/run/espeakup.pid"; -/* default voice settings */ -const int defaultFrequency = 5; -const int defaultPitch = 5; -const int defaultRate = 5; -const int defaultVolume = 5; - -char *defaultVoice = NULL; int debug = 0; int self_pipe_fds[2]; @@ -83,7 +76,7 @@ int main(int argc, char **argv) int rate; int err; pthread_t signal_thread_id; - pthread_t queue_thread_id; + pthread_t espeak_thread_id; pthread_t softsynth_thread_id; struct synth_t s = { .voice = "", @@ -125,19 +118,20 @@ int main(int argc, char **argv) sigprocmask(SIG_BLOCK, &sigset, NULL); /* set up the pipe used to wake the reader. */ - if(pipe(self_pipe_fds) < 0) { - perror("Unable to create pipe"); - return 5; - } - - /* Spawn our queue-processing thread. */ - err = pthread_create(&queue_thread_id, NULL, &queue_runner, &s); + if (pipe(self_pipe_fds) < 0) { + perror("Unable to create pipe"); + return 5; + } + + /* Spawn our espeak-interacting thread. */ + err = pthread_create(&espeak_thread_id, NULL, &espeak_thread, &s); if (err != 0) { return 4; } /* Spawn our softsynth thread. */ - err = pthread_create(&softsynth_thread_id, NULL, &softsynth_thread, &s); + err = + pthread_create(&softsynth_thread_id, NULL, &softsynth_thread, &s); if (err != 0) { return 4; } diff --git a/espeakup.h b/espeakup.h index b6ecb4c..1edd35d 100644 --- a/espeakup.h +++ b/espeakup.h @@ -76,7 +76,7 @@ extern espeak_ERROR stop_speech(void); extern espeak_ERROR speak_text(struct synth_t *s); extern void *softsynth_thread(void *arg); extern void stop_runner(void); -extern void *queue_runner(void *arg); +extern void *espeak_thread(void *arg); extern void *signal_thread(void *arg); extern void select_audio_mode(void); extern int init_audio(unsigned int rate); diff --git a/queue.c b/queue.c index 002ad61..1aa5d98 100644 --- a/queue.c +++ b/queue.c @@ -25,6 +25,14 @@ #include "espeakup.h" +/* default voice settings */ +const int defaultFrequency = 5; +const int defaultPitch = 5; +const int defaultRate = 5; +const int defaultVolume = 5; + +char *defaultVoice = NULL; + pthread_cond_t runner_awake = PTHREAD_COND_INITIALIZER; pthread_cond_t stop_acknowledged = PTHREAD_COND_INITIALIZER; pthread_mutex_t queue_guard = PTHREAD_MUTEX_INITIALIZER; @@ -185,7 +193,7 @@ void stop_runner(void) pthread_mutex_unlock(&stop_guard); } -/* queue_runner is the "main" function of our secondary (queue-processing) +/* espeak_thread is the "main" function of our secondary (queue-processing) * thread. * First, lock queue_guard, because it needs to be locked when we call * pthread_cond_wait on the runner_awake condition variable. @@ -205,14 +213,40 @@ void stop_runner(void) * 2. We are processing an entry that has just been removed from the queue. */ -void *queue_runner(void *arg) +void *espeak_thread(void *arg) { struct synth_t *synth = (struct synth_t *) arg; + int rate; + + /* initialize espeak */ + select_audio_mode(); + rate = espeak_Initialize(audio_mode, 0, NULL, 0); + if (rate < 0) { + fprintf(stderr, "Unable to initialize espeak.\n"); + should_run = 0; + } + + if (init_audio((unsigned int) rate) < 0) { + should_run = 0; + } + + /* Setup initial voice parameters */ + if (defaultVoice) { + set_voice(&s, defaultVoice); + free(defaultVoice); + defaultVoice = NULL; + } + set_frequency(&s, defaultFrequency, ADJ_SET); + set_pitch(&s, defaultPitch, ADJ_SET); + set_rate(&s, defaultRate, ADJ_SET); + set_volume(&s, defaultVolume, ADJ_SET); + espeak_SetParameter(espeakCAPITALS, 0, 0); + pthread_mutex_lock(&queue_guard); - while (1) { + while (should_run) { pthread_cond_wait(&runner_awake, &queue_guard); - while (last && ! runner_must_stop ) { + while (should_run && last && !runner_must_stop) { queue_process_entry(synth); pthread_mutex_lock(&queue_guard); } @@ -227,5 +261,6 @@ void *queue_runner(void *arg) } } + espeak_Terminate(); return NULL; } From c6b57885c9479f4d85831b2082206bef685cd74d Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Wed, 24 Jun 2009 22:22:34 -0500 Subject: [PATCH 024/181] removed declaration of rate from main --- espeakup.c | 1 - 1 file changed, 1 deletion(-) diff --git a/espeakup.c b/espeakup.c index 6edaac2..c16341f 100644 --- a/espeakup.c +++ b/espeakup.c @@ -73,7 +73,6 @@ int create_pid_file(void) int main(int argc, char **argv) { sigset_t sigset; - int rate; int err; pthread_t signal_thread_id; pthread_t espeak_thread_id; From af5717b8cb3d9c2232f20f90d32601c0f7021fca Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Wed, 24 Jun 2009 22:23:10 -0500 Subject: [PATCH 025/181] moved queue_add_xxx functions to softsynth thread --- espeakup.h | 14 +++++++++++--- queue.c | 49 ++----------------------------------------------- softsynth.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 50 deletions(-) diff --git a/espeakup.h b/espeakup.h index 1edd35d..72db0d1 100644 --- a/espeakup.h +++ b/espeakup.h @@ -43,6 +43,15 @@ enum adjust_t { ADJ_INC, }; +struct queue_entry_t { + enum command_t cmd; + enum adjust_t adjust; + int value; + char *buf; + int len; + struct queue_entry_t *next; +}; + struct synth_t { int frequency; int pitch; @@ -57,10 +66,9 @@ struct synth_t { extern int debug; extern void process_cli(int argc, char **argv); +extern void queue_add(struct queue_entry_t *entry); +extern void queue_remove(void); extern void queue_clear(void); -extern void queue_add_cmd(enum command_t cmd, enum adjust_t adj, - int value); -extern void queue_add_text(char *txt, size_t length); extern espeak_ERROR set_frequency(struct synth_t *s, int freq, enum adjust_t adj); extern espeak_ERROR set_pitch(struct synth_t *s, int pitch, diff --git a/queue.c b/queue.c index 1aa5d98..b2b5c73 100644 --- a/queue.c +++ b/queue.c @@ -38,20 +38,11 @@ pthread_cond_t stop_acknowledged = PTHREAD_COND_INITIALIZER; pthread_mutex_t queue_guard = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t stop_guard = PTHREAD_MUTEX_INITIALIZER; -struct queue_entry_t { - enum command_t cmd; - enum adjust_t adjust; - int value; - char *buf; - int len; - struct queue_entry_t *next; -}; - volatile int runner_must_stop = 0; static struct queue_entry_t *first = NULL; static struct queue_entry_t *last = NULL; -static void queue_add(struct queue_entry_t *entry) +void queue_add(struct queue_entry_t *entry) { pthread_mutex_lock(&queue_guard); assert(entry); @@ -78,7 +69,7 @@ static void free_entry(struct queue_entry_t *entry) /* Remove and return the entry at the head of the queue. * Return NULL if queue is empty. */ -static void queue_remove(void) +void queue_remove(void) { struct queue_entry_t *temp; @@ -102,42 +93,6 @@ void queue_clear(void) /* We aren't adding data to the queue, so no need to signal. */ } -void queue_add_cmd(enum command_t cmd, enum adjust_t adj, int value) -{ - struct queue_entry_t *entry; - - entry = malloc(sizeof(struct queue_entry_t)); - if (!entry) { - perror("unable to allocate memory for queue entry"); - return; - } - entry->cmd = cmd; - entry->adjust = adj; - entry->value = value; - queue_add(entry); -} - -void queue_add_text(char *txt, size_t length) -{ - struct queue_entry_t *entry; - - entry = malloc(sizeof(struct queue_entry_t)); - if (!entry) { - perror("unable to allocate memory for queue entry"); - return; - } - entry->cmd = CMD_SPEAK_TEXT; - entry->adjust = ADJ_SET; - entry->buf = strdup(txt); - if (!entry->buf) { - perror("unable to allocate space for text"); - free(entry); - return; - } - entry->len = length; - queue_add(entry); -} - static void queue_process_entry(struct synth_t *s) { espeak_ERROR error; diff --git a/softsynth.c b/softsynth.c index 3eb6c7e..b455073 100644 --- a/softsynth.c +++ b/softsynth.c @@ -33,6 +33,42 @@ const size_t maxBufferSize = 1025; /* synth flush character */ const int synthFlushChar = 0x18; +static void queue_add_cmd(enum command_t cmd, enum adjust_t adj, int value) +{ + struct queue_entry_t *entry; + + entry = malloc(sizeof(struct queue_entry_t)); + if (!entry) { + perror("unable to allocate memory for queue entry"); + return; + } + entry->cmd = cmd; + entry->adjust = adj; + entry->value = value; + queue_add(entry); +} + +static void queue_add_text(char *txt, size_t length) +{ + struct queue_entry_t *entry; + + entry = malloc(sizeof(struct queue_entry_t)); + if (!entry) { + perror("unable to allocate memory for queue entry"); + return; + } + entry->cmd = CMD_SPEAK_TEXT; + entry->adjust = ADJ_SET; + entry->buf = strdup(txt); + if (!entry->buf) { + perror("unable to allocate space for text"); + free(entry); + return; + } + entry->len = length; + queue_add(entry); +} + static int process_command(struct synth_t *s, char *buf, int start) { char *cp; From 3e8e7d12ae89b4b2c00596cf88fcb35fd4b5b20e Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Wed, 24 Jun 2009 22:44:18 -0500 Subject: [PATCH 026/181] added back the declaration for softFD --- softsynth.c | 1 + 1 file changed, 1 insertion(+) diff --git a/softsynth.c b/softsynth.c index b455073..8c76f56 100644 --- a/softsynth.c +++ b/softsynth.c @@ -167,6 +167,7 @@ void *softsynth_thread(void *arg) char buf[maxBufferSize]; char *cp; int terminalFD = PIPE_READ_FD; + int softFD; int greatestFD; /* open the softsynth. */ From 42c3f76a083890c49fcb7d92a2f695f69e4882b4 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Thu, 25 Jun 2009 01:21:44 -0500 Subject: [PATCH 027/181] moved include for pthread.h to espeakup.h --- alsa.c | 1 - espeakup.c | 1 - espeakup.h | 1 + queue.c | 1 - 4 files changed, 1 insertion(+), 3 deletions(-) diff --git a/alsa.c b/alsa.c index 014bfa6..ae38798 100644 --- a/alsa.c +++ b/alsa.c @@ -25,7 +25,6 @@ #include #include #include -#include #define ALSA_PCM_NEW_HW_PARAMS_API #include #include "espeakup.h" diff --git a/espeakup.c b/espeakup.c index c16341f..b8913d0 100644 --- a/espeakup.c +++ b/espeakup.c @@ -23,7 +23,6 @@ #include #include #include -#include #include "espeakup.h" diff --git a/espeakup.h b/espeakup.h index 72db0d1..4a13391 100644 --- a/espeakup.h +++ b/espeakup.h @@ -22,6 +22,7 @@ /* This was added for gcc 4.3 */ #include +#include #include diff --git a/queue.c b/queue.c index b2b5c73..ff23f5c 100644 --- a/queue.c +++ b/queue.c @@ -21,7 +21,6 @@ #include #include #include -#include #include "espeakup.h" From a8cad20de898002465fad6f3cf42f381f2a33812 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Thu, 25 Jun 2009 09:05:21 -0500 Subject: [PATCH 028/181] more multithreading work Rearranged the queue handling code so that queue.c is generic. Also rearranged several functions in the threads. --- espeakup.c | 35 ++++++--- espeakup.h | 31 +++----- queue.c | 222 ++++++++++------------------------------------------ softsynth.c | 46 +++++++---- synth.c | 164 ++++++++++++++++++++++++++++++++++++-- 5 files changed, 261 insertions(+), 237 deletions(-) diff --git a/espeakup.c b/espeakup.c index b8913d0..d7f49f8 100644 --- a/espeakup.c +++ b/espeakup.c @@ -39,6 +39,11 @@ volatile int stopped = 0; volatile int should_run = 1; espeak_AUDIO_OUTPUT audio_mode; +pthread_cond_t runner_awake = PTHREAD_COND_INITIALIZER; +pthread_cond_t stop_acknowledged = PTHREAD_COND_INITIALIZER; +pthread_mutex_t queue_guard = PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t stop_guard = PTHREAD_MUTEX_INITIALIZER; + int espeakup_is_running(void) { int rc; @@ -100,8 +105,14 @@ int main(int argc, char **argv) } } + /* set up the pipe used to wake the espeak thread */ + if (pipe(self_pipe_fds) < 0) { + perror("Unable to create pipe"); + return 5; + } + /* create the signal processing thread here. */ - err = pthread_create(&signal_thread_id, NULL, &signal_thread, NULL); + err = pthread_create(&signal_thread_id, NULL, signal_thread, NULL); if (err != 0) { return 4; } @@ -115,24 +126,24 @@ int main(int argc, char **argv) sigaddset(&sigset, SIGTERM); sigprocmask(SIG_BLOCK, &sigset, NULL); - /* set up the pipe used to wake the reader. */ - if (pipe(self_pipe_fds) < 0) { - perror("Unable to create pipe"); - return 5; + /* Spawn our softsynth thread. */ + err = pthread_create(&softsynth_thread_id, NULL, softsynth_thread, &s); + if (err != 0) { + return 4; } /* Spawn our espeak-interacting thread. */ - err = pthread_create(&espeak_thread_id, NULL, &espeak_thread, &s); + err = pthread_create(&espeak_thread_id, NULL, espeak_thread, &s); if (err != 0) { return 4; } - /* Spawn our softsynth thread. */ - err = - pthread_create(&softsynth_thread_id, NULL, &softsynth_thread, &s); - if (err != 0) { - return 4; - } + /* wait for the threads to shut down. */ + pthread_join(signal_thread_id, NULL); + pthread_join(softsynth_thread_id, NULL); + pthread_join(espeak_thread_id, NULL); + if ( ! debug) + unlink(pidPath); return 0; } diff --git a/espeakup.h b/espeakup.h index 4a13391..c529ad4 100644 --- a/espeakup.h +++ b/espeakup.h @@ -44,13 +44,12 @@ enum adjust_t { ADJ_INC, }; -struct queue_entry_t { +struct espeak_entry_t { enum command_t cmd; enum adjust_t adjust; int value; char *buf; int len; - struct queue_entry_t *next; }; struct synth_t { @@ -67,26 +66,12 @@ struct synth_t { extern int debug; extern void process_cli(int argc, char **argv); -extern void queue_add(struct queue_entry_t *entry); +extern void queue_add(void *entry); extern void queue_remove(void); -extern void queue_clear(void); -extern espeak_ERROR set_frequency(struct synth_t *s, int freq, - enum adjust_t adj); -extern espeak_ERROR set_pitch(struct synth_t *s, int pitch, - enum adjust_t adj); -extern espeak_ERROR set_punctuation(struct synth_t *s, int punct, - enum adjust_t adj); -extern espeak_ERROR set_rate(struct synth_t *s, int rate, - enum adjust_t adj); -extern espeak_ERROR set_voice(struct synth_t *s, char *voice); -extern espeak_ERROR set_volume(struct synth_t *s, int vol, - enum adjust_t adj); -extern espeak_ERROR stop_speech(void); -extern espeak_ERROR speak_text(struct synth_t *s); -extern void *softsynth_thread(void *arg); -extern void stop_runner(void); -extern void *espeak_thread(void *arg); +extern void *queue_peek(void); extern void *signal_thread(void *arg); +extern void *softsynth_thread(void *arg); +extern void *espeak_thread(void *arg); extern void select_audio_mode(void); extern int init_audio(unsigned int rate); extern void lock_audio_mutex(void); @@ -99,4 +84,10 @@ extern int self_pipe_fds[2]; #define PIPE_WRITE_FD (self_pipe_fds[1]) extern espeak_AUDIO_OUTPUT audio_mode; + +extern pthread_cond_t runner_awake; +extern pthread_cond_t stop_acknowledged; +extern pthread_mutex_t queue_guard; +extern pthread_mutex_t stop_guard; + #endif diff --git a/queue.c b/queue.c index ff23f5c..dcce07c 100644 --- a/queue.c +++ b/queue.c @@ -1,6 +1,10 @@ /* * espeakup - interface which allows speakup to use espeak * + * Note that these functions are meant to be used in either a single or + * multi-threaded environment, so they know nothing about mutexes, etc. + * Handling this is up to the caller. + * * Copyright (C) 2008 William Hubbs * * This program is free software: you can redistribute it and/or modify @@ -22,199 +26,53 @@ #include #include -#include "espeakup.h" +struct queue_entry_t { + void *data; + struct queue_entry_t *next; +}; -/* default voice settings */ -const int defaultFrequency = 5; -const int defaultPitch = 5; -const int defaultRate = 5; -const int defaultVolume = 5; +static struct queue_entry_t *head = NULL; +static struct queue_entry_t *tail = NULL; -char *defaultVoice = NULL; - -pthread_cond_t runner_awake = PTHREAD_COND_INITIALIZER; -pthread_cond_t stop_acknowledged = PTHREAD_COND_INITIALIZER; -pthread_mutex_t queue_guard = PTHREAD_MUTEX_INITIALIZER; -pthread_mutex_t stop_guard = PTHREAD_MUTEX_INITIALIZER; - -volatile int runner_must_stop = 0; -static struct queue_entry_t *first = NULL; -static struct queue_entry_t *last = NULL; - -void queue_add(struct queue_entry_t *entry) +void queue_add(void *data) { - pthread_mutex_lock(&queue_guard); - assert(entry); - entry->next = NULL; - if (!last) - last = entry; - if (!first) { - first = entry; - } else { - first->next = entry; - first = first->next; +struct queue_entry_t *tmp; + + assert(data); + tmp = malloc(sizeof(struct queue_entry_t)); + if (! tmp) { + printf("Unable to allocate memory for queue entry.\n"); + return; } - pthread_mutex_unlock(&queue_guard); - pthread_cond_signal(&runner_awake); + tmp->data = data; + tmp->next = NULL; + if (! tail) { + tail = tmp; + } else { + tail->next = tmp; + tail = tail->next; + } + if (!head) + head = tmp; } -static void free_entry(struct queue_entry_t *entry) -{ - if (entry->cmd == CMD_SPEAK_TEXT) - free(entry->buf); - free(entry); -} - -/* Remove and return the entry at the head of the queue. - * Return NULL if queue is empty. */ - void queue_remove(void) { - struct queue_entry_t *temp; + struct queue_entry_t *tmp; - if (last) { - temp = last; - last = temp->next; - if (!last) - first = last; - free_entry(temp); + if (head) { + tmp = head; + head = tmp->next; + free(tmp); + if (!head) + tail = head; } } -void queue_clear(void) +void *queue_peek(void) { - struct queue_entry_t *temp; - - while (last) { - temp = last->next; - queue_remove(); - } - /* We aren't adding data to the queue, so no need to signal. */ -} - -static void queue_process_entry(struct synth_t *s) -{ - espeak_ERROR error; - struct queue_entry_t *current = last; - - pthread_mutex_unlock(&queue_guard); /* So "reader" can go. */ - if (current) { - switch (current->cmd) { - case CMD_SET_FREQUENCY: - error = set_frequency(s, current->value, current->adjust); - break; - case CMD_SET_PITCH: - error = set_pitch(s, current->value, current->adjust); - break; - case CMD_SET_PUNCTUATION: - error = set_punctuation(s, current->value, current->adjust); - break; - case CMD_SET_RATE: - error = set_rate(s, current->value, current->adjust); - break; - case CMD_SET_VOICE: - break; - case CMD_SET_VOLUME: - error = set_volume(s, current->value, current->adjust); - break; - case CMD_SPEAK_TEXT: - s->buf = current->buf; - s->len = current->len; - error = speak_text(s); - break; - default: - break; - } - - pthread_mutex_lock(&queue_guard); - if (error == EE_OK) - queue_remove(); - pthread_mutex_unlock(&queue_guard); - } -} - -/* - * Tell the runner to stop speech and clear its queue. - */ -void stop_runner(void) -{ - pthread_mutex_lock(&stop_guard); - pthread_mutex_lock(&queue_guard); - runner_must_stop = 1; - pthread_mutex_unlock(&queue_guard); - pthread_cond_signal(&runner_awake); /* Wake runner, if necessary. */ - pthread_cond_wait(&stop_acknowledged, &stop_guard); - pthread_mutex_unlock(&stop_guard); -} - -/* espeak_thread is the "main" function of our secondary (queue-processing) - * thread. - * First, lock queue_guard, because it needs to be locked when we call - * pthread_cond_wait on the runner_awake condition variable. - * Next, enter an infinite loop. - * The wait call also unlocks queue_guard, so that the other thread can - * manipulate the queue. - * When runner_awake is signaled, the pthread_cond_wait call re-locks - * queue_guard, and the "queue processor" thread has access to the queue. - * While there is an entry in the queue, call queue_process_entry. - * queue_process_entry unlocks queue_guard after removing an item from the - * queue, so that the main thread doesn't have to wait for us to finish - * processing the entry. So re-lock queue_guard after each call to - * queue_process_entry. - * - * The main thread can add items to the queue in exactly two situations: - * 1. We are waiting on runner_awake, or - * 2. We are processing an entry that has just been removed from the queue. -*/ - -void *espeak_thread(void *arg) -{ - struct synth_t *synth = (struct synth_t *) arg; - int rate; - - /* initialize espeak */ - select_audio_mode(); - rate = espeak_Initialize(audio_mode, 0, NULL, 0); - if (rate < 0) { - fprintf(stderr, "Unable to initialize espeak.\n"); - should_run = 0; - } - - if (init_audio((unsigned int) rate) < 0) { - should_run = 0; - } - - /* Setup initial voice parameters */ - if (defaultVoice) { - set_voice(&s, defaultVoice); - free(defaultVoice); - defaultVoice = NULL; - } - set_frequency(&s, defaultFrequency, ADJ_SET); - set_pitch(&s, defaultPitch, ADJ_SET); - set_rate(&s, defaultRate, ADJ_SET); - set_volume(&s, defaultVolume, ADJ_SET); - espeak_SetParameter(espeakCAPITALS, 0, 0); - - pthread_mutex_lock(&queue_guard); - while (should_run) { - pthread_cond_wait(&runner_awake, &queue_guard); - - while (should_run && last && !runner_must_stop) { - queue_process_entry(synth); - pthread_mutex_lock(&queue_guard); - } - - if (runner_must_stop) { - pthread_mutex_lock(&stop_guard); - queue_clear(); - stop_speech(); - runner_must_stop = 0; - pthread_mutex_unlock(&stop_guard); - pthread_cond_signal(&stop_acknowledged); - } - } - - espeak_Terminate(); - return NULL; + if (head) + return head->data; + else + return NULL; } diff --git a/softsynth.c b/softsynth.c index 8c76f56..a78cc23 100644 --- a/softsynth.c +++ b/softsynth.c @@ -35,9 +35,9 @@ const int synthFlushChar = 0x18; static void queue_add_cmd(enum command_t cmd, enum adjust_t adj, int value) { - struct queue_entry_t *entry; + struct espeak_entry_t *entry; - entry = malloc(sizeof(struct queue_entry_t)); + entry = malloc(sizeof(struct espeak_entry_t)); if (!entry) { perror("unable to allocate memory for queue entry"); return; @@ -45,14 +45,17 @@ static void queue_add_cmd(enum command_t cmd, enum adjust_t adj, int value) entry->cmd = cmd; entry->adjust = adj; entry->value = value; - queue_add(entry); + pthread_mutex_lock(&queue_guard); + queue_add((void *) entry); + pthread_mutex_unlock(&queue_guard); + pthread_cond_signal(&runner_awake); } static void queue_add_text(char *txt, size_t length) { - struct queue_entry_t *entry; + struct espeak_entry_t *entry; - entry = malloc(sizeof(struct queue_entry_t)); + entry = malloc(sizeof(struct espeak_entry_t)); if (!entry) { perror("unable to allocate memory for queue entry"); return; @@ -66,7 +69,10 @@ static void queue_add_text(char *txt, size_t length) return; } entry->len = length; - queue_add(entry); + pthread_mutex_lock(&queue_guard); + queue_add((void *) entry); + pthread_mutex_unlock(&queue_guard); + pthread_cond_signal(&runner_awake); } static int process_command(struct synth_t *s, char *buf, int start) @@ -159,6 +165,15 @@ static void process_buffer(struct synth_t *s, char *buf, ssize_t length) } } +static void request_espeak_stop(void) +{ + pthread_mutex_lock(&stop_guard); + runner_must_stop = 1; + pthread_cond_signal(&runner_awake); /* Wake runner, if necessary. */ + pthread_cond_wait(&stop_acknowledged, &stop_guard); + pthread_mutex_unlock(&stop_guard); +} + void *softsynth_thread(void *arg) { struct synth_t *s = (struct synth_t *) arg; @@ -166,9 +181,9 @@ void *softsynth_thread(void *arg) ssize_t length; char buf[maxBufferSize]; char *cp; - int terminalFD = PIPE_READ_FD; + int terminalFD = PIPE_READ_FD; int softFD; - int greatestFD; + int greatestFD; /* open the softsynth. */ softFD = open("/dev/softsynth", O_RDWR | O_NONBLOCK); @@ -177,16 +192,16 @@ void *softsynth_thread(void *arg) should_run = 0; } - if (terminalFD > softFD) - greatestFD = terminalFD; - else - greatestFD = softFD; + if (terminalFD > softFD) + greatestFD = terminalFD; + else + greatestFD = softFD; while (should_run) { FD_ZERO(&set); FD_SET(softFD, &set); - FD_SET(terminalFD, &set); + FD_SET(terminalFD, &set); - if (select(greatestFD + 1, &set, NULL, NULL, NULL) < 0) { + if (select(greatestFD + 1, &set, NULL, NULL, NULL) < 0) { if (errno == EINTR) continue; perror("Select failed"); @@ -209,7 +224,8 @@ void *softsynth_thread(void *arg) *(buf + length) = 0; cp = strrchr(buf, synthFlushChar); if (cp) { - stop_runner(); + request_espeak_stop(); + printf("Returned from stop_runner\n"); memmove(buf, cp + 1, strlen(cp + 1) + 1); length = strlen(buf); } diff --git a/synth.c b/synth.c index e19d95e..39d95ea 100644 --- a/synth.c +++ b/synth.c @@ -17,10 +17,19 @@ * along with this program. If not, see . */ +#include +#include #include #include "espeakup.h" +/* default voice settings */ +const int defaultFrequency = 5; +const int defaultPitch = 5; +const int defaultRate = 5; +const int defaultVolume = 5; +char *defaultVoice = NULL; + /* multipliers and offsets */ const int frequencyMultiplier = 11; const int pitchMultiplier = 11; @@ -28,7 +37,9 @@ const int rateMultiplier = 34; const int rateOffset = 84; const int volumeMultiplier = 22; -espeak_ERROR set_frequency(struct synth_t *s, int freq, enum adjust_t adj) +volatile int runner_must_stop = 0; + +static espeak_ERROR set_frequency(struct synth_t *s, int freq, enum adjust_t adj) { espeak_ERROR rc; @@ -42,7 +53,7 @@ espeak_ERROR set_frequency(struct synth_t *s, int freq, enum adjust_t adj) return rc; } -espeak_ERROR set_pitch(struct synth_t * s, int pitch, enum adjust_t adj) +static espeak_ERROR set_pitch(struct synth_t * s, int pitch, enum adjust_t adj) { espeak_ERROR rc; @@ -56,7 +67,7 @@ espeak_ERROR set_pitch(struct synth_t * s, int pitch, enum adjust_t adj) return rc; } -espeak_ERROR set_punctuation(struct synth_t * s, int punct, +static espeak_ERROR set_punctuation(struct synth_t * s, int punct, enum adjust_t adj) { espeak_ERROR rc; @@ -71,7 +82,7 @@ espeak_ERROR set_punctuation(struct synth_t * s, int punct, return rc; } -espeak_ERROR set_rate(struct synth_t * s, int rate, enum adjust_t adj) +static espeak_ERROR set_rate(struct synth_t * s, int rate, enum adjust_t adj) { espeak_ERROR rc; @@ -86,7 +97,7 @@ espeak_ERROR set_rate(struct synth_t * s, int rate, enum adjust_t adj) return rc; } -espeak_ERROR set_voice(struct synth_t * s, char *voice) +static espeak_ERROR set_voice(struct synth_t * s, char *voice) { espeak_ERROR rc; @@ -96,7 +107,7 @@ espeak_ERROR set_voice(struct synth_t * s, char *voice) return rc; } -espeak_ERROR set_volume(struct synth_t * s, int vol, enum adjust_t adj) +static espeak_ERROR set_volume(struct synth_t * s, int vol, enum adjust_t adj) { espeak_ERROR rc; @@ -112,7 +123,7 @@ espeak_ERROR set_volume(struct synth_t * s, int vol, enum adjust_t adj) return rc; } -espeak_ERROR stop_speech(void) +static espeak_ERROR stop_speech(void) { lock_audio_mutex(); stopped = 1; @@ -120,7 +131,7 @@ espeak_ERROR stop_speech(void) return (espeak_Cancel()); } -espeak_ERROR speak_text(struct synth_t * s) +static espeak_ERROR speak_text(struct synth_t * s) { espeak_ERROR rc; @@ -131,3 +142,140 @@ espeak_ERROR speak_text(struct synth_t * s) NULL); return rc; } + +static void queue_process_entry(struct synth_t *s) +{ + espeak_ERROR error; + struct espeak_entry_t *current; + + pthread_mutex_lock(&queue_guard); + current = (struct espeak_entry_t *) queue_peek(); + pthread_mutex_unlock(&queue_guard); + if (current) { + switch (current->cmd) { + case CMD_SET_FREQUENCY: + error = set_frequency(s, current->value, current->adjust); + break; + case CMD_SET_PITCH: + error = set_pitch(s, current->value, current->adjust); + break; + case CMD_SET_PUNCTUATION: + error = set_punctuation(s, current->value, current->adjust); + break; + case CMD_SET_RATE: + error = set_rate(s, current->value, current->adjust); + break; + case CMD_SET_VOICE: + error = EE_OK; + break; + case CMD_SET_VOLUME: + error = set_volume(s, current->value, current->adjust); + break; + case CMD_SPEAK_TEXT: + s->buf = current->buf; + s->len = current->len; + error = speak_text(s); + break; + default: + break; + } + + pthread_mutex_lock(&queue_guard); + if (error == EE_OK) + queue_remove(); + pthread_mutex_unlock(&queue_guard); + } +} + +static void free_entry(struct espeak_entry_t *entry) +{ + if (entry->cmd == CMD_SPEAK_TEXT) + free(entry->buf); + free(entry); +} + +static void queue_clear() +{ + struct espeak_entry_t *current; + + pthread_mutex_lock(&queue_guard); + current = (struct espeak_entry_t *) queue_peek(); + while (current) { + free_entry(current); + queue_remove(); + current = (struct espeak_entry_t *) queue_peek(); + } + pthread_mutex_unlock(&queue_guard); +} + +/* espeak_thread is the "main" function of our secondary (queue-processing) + * thread. + * First, lock queue_guard, because it needs to be locked when we call + * pthread_cond_wait on the runner_awake condition variable. + * Next, enter an infinite loop. + * The wait call also unlocks queue_guard, so that the other thread can + * manipulate the queue. + * When runner_awake is signaled, the pthread_cond_wait call re-locks + * queue_guard, and the "queue processor" thread has access to the queue. + * While there is an entry in the queue, call queue_process_entry. + * queue_process_entry unlocks queue_guard after removing an item from the + * queue, so that the main thread doesn't have to wait for us to finish + * processing the entry. So re-lock queue_guard after each call to + * queue_process_entry. + * + * The main thread can add items to the queue in exactly two situations: + * 1. We are waiting on runner_awake, or + * 2. We are processing an entry that has just been removed from the queue. +*/ + +void *espeak_thread(void *arg) +{ + struct synth_t *s = (struct synth_t *) arg; + int rate; + + /* initialize espeak */ + select_audio_mode(); + rate = espeak_Initialize(audio_mode, 0, NULL, 0); + if (rate < 0) { + fprintf(stderr, "Unable to initialize espeak.\n"); + should_run = 0; + } + + if (init_audio((unsigned int) rate) < 0) { + should_run = 0; + } + + /* Setup initial voice parameters */ + if (defaultVoice) { + set_voice(s, defaultVoice); + free(defaultVoice); + defaultVoice = NULL; + } + set_frequency(s, defaultFrequency, ADJ_SET); + set_pitch(s, defaultPitch, ADJ_SET); + set_rate(s, defaultRate, ADJ_SET); + set_volume(s, defaultVolume, ADJ_SET); + espeak_SetParameter(espeakCAPITALS, 0, 0); + + pthread_mutex_lock(&queue_guard); + while (should_run) { + pthread_cond_wait(&runner_awake, &queue_guard); + + while (should_run && queue_peek() && !runner_must_stop) { + queue_process_entry(s); + pthread_mutex_lock(&queue_guard); + } + + if (runner_must_stop) { + pthread_mutex_lock(&stop_guard); + queue_clear(); + stop_speech(); + runner_must_stop = 0; + pthread_mutex_unlock(&stop_guard); + pthread_cond_signal(&stop_acknowledged); + } + } + pthread_mutex_unlock(&queue_guard); + espeak_Terminate(); + return NULL; +} From b7f324072f26fa31a8d9772f38bdf1f920504223 Mon Sep 17 00:00:00 2001 From: Christopher Brannon Date: Thu, 25 Jun 2009 11:38:46 -0500 Subject: [PATCH 029/181] Fix concurrency bugs. 1. Don't lock or unlock queue_guard during queue_clear. It is locked when queue_clear is called, and it should remain so. 2. Protect runner_must_stop with queue_guard in the request_espeak_stop function. The following condition should always hold: queue_guard is locked while testing or modifying runner_must_stop. 3. Rename stop_guard to acknowledge_guard. This is a more descriptive name. This mutex simply protects the acknowledgement of the stop request from being lost. 4. Remove the pthread_mutex_lock from the top of queue_process_entry, because queue_guard is already locked when the function is called. --- espeakup.c | 2 +- espeakup.h | 2 +- softsynth.c | 15 ++++++++++++--- synth.c | 7 ++----- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/espeakup.c b/espeakup.c index d7f49f8..0cf3d0b 100644 --- a/espeakup.c +++ b/espeakup.c @@ -42,7 +42,7 @@ espeak_AUDIO_OUTPUT audio_mode; pthread_cond_t runner_awake = PTHREAD_COND_INITIALIZER; pthread_cond_t stop_acknowledged = PTHREAD_COND_INITIALIZER; pthread_mutex_t queue_guard = PTHREAD_MUTEX_INITIALIZER; -pthread_mutex_t stop_guard = PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t acknowledge_guard = PTHREAD_MUTEX_INITIALIZER; int espeakup_is_running(void) { diff --git a/espeakup.h b/espeakup.h index c529ad4..d5d3f18 100644 --- a/espeakup.h +++ b/espeakup.h @@ -88,6 +88,6 @@ extern espeak_AUDIO_OUTPUT audio_mode; extern pthread_cond_t runner_awake; extern pthread_cond_t stop_acknowledged; extern pthread_mutex_t queue_guard; -extern pthread_mutex_t stop_guard; +extern pthread_mutex_t acknowledge_guard; #endif diff --git a/softsynth.c b/softsynth.c index a78cc23..37e70b3 100644 --- a/softsynth.c +++ b/softsynth.c @@ -167,11 +167,20 @@ static void process_buffer(struct synth_t *s, char *buf, ssize_t length) static void request_espeak_stop(void) { - pthread_mutex_lock(&stop_guard); + pthread_mutex_lock(&acknowledge_guard); + pthread_mutex_lock(&queue_guard); runner_must_stop = 1; + pthread_mutex_unlock(&queue_guard); pthread_cond_signal(&runner_awake); /* Wake runner, if necessary. */ - pthread_cond_wait(&stop_acknowledged, &stop_guard); - pthread_mutex_unlock(&stop_guard); + + /* + * Runner will see runner_must_stop == 1 next time it locks + * queue_guard, or when it awakens. + * It will lock acknowledge_guard, acknowledge the stop, and signal + * the reader, which will awaken. + */ + pthread_cond_wait(&stop_acknowledged, &acknowledge_guard); + pthread_mutex_unlock(&acknowledge_guard); } void *softsynth_thread(void *arg) diff --git a/synth.c b/synth.c index 39d95ea..1bfb0ce 100644 --- a/synth.c +++ b/synth.c @@ -148,7 +148,6 @@ static void queue_process_entry(struct synth_t *s) espeak_ERROR error; struct espeak_entry_t *current; - pthread_mutex_lock(&queue_guard); current = (struct espeak_entry_t *) queue_peek(); pthread_mutex_unlock(&queue_guard); if (current) { @@ -198,14 +197,12 @@ static void queue_clear() { struct espeak_entry_t *current; - pthread_mutex_lock(&queue_guard); current = (struct espeak_entry_t *) queue_peek(); while (current) { free_entry(current); queue_remove(); current = (struct espeak_entry_t *) queue_peek(); } - pthread_mutex_unlock(&queue_guard); } /* espeak_thread is the "main" function of our secondary (queue-processing) @@ -267,11 +264,11 @@ void *espeak_thread(void *arg) } if (runner_must_stop) { - pthread_mutex_lock(&stop_guard); + pthread_mutex_lock(&acknowledge_guard); queue_clear(); stop_speech(); runner_must_stop = 0; - pthread_mutex_unlock(&stop_guard); + pthread_mutex_unlock(&acknowledge_guard); pthread_cond_signal(&stop_acknowledged); } } From 554a03d26c147958b99b78690214e195cda65c41 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Thu, 25 Jun 2009 12:06:33 -0500 Subject: [PATCH 030/181] white space fix --- softsynth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/softsynth.c b/softsynth.c index 37e70b3..ca17db4 100644 --- a/softsynth.c +++ b/softsynth.c @@ -174,7 +174,7 @@ static void request_espeak_stop(void) pthread_cond_signal(&runner_awake); /* Wake runner, if necessary. */ /* - * Runner will see runner_must_stop == 1 next time it locks + * Runner will see runner_must_stop == 1 next time it locks * queue_guard, or when it awakens. * It will lock acknowledge_guard, acknowledge the stop, and signal * the reader, which will awaken. From 0bf2cae5a6cd35ea7ee78fbb136ccb58f6937b3e Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Thu, 25 Jun 2009 12:06:51 -0500 Subject: [PATCH 031/181] moved lock/unlock in queue_process_entry The only time queue_process_entry should lock the queue gard is when it is removing the item from the queue. This happens only when the item was successfully processed. --- synth.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/synth.c b/synth.c index 1bfb0ce..f61d529 100644 --- a/synth.c +++ b/synth.c @@ -179,10 +179,11 @@ static void queue_process_entry(struct synth_t *s) break; } - pthread_mutex_lock(&queue_guard); - if (error == EE_OK) + if (error == EE_OK) { + pthread_mutex_lock(&queue_guard); queue_remove(); - pthread_mutex_unlock(&queue_guard); + pthread_mutex_unlock(&queue_guard); + } } } From 1091182f884cb8187ce3cdaf3723243deaa4dcb2 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Thu, 25 Jun 2009 12:57:29 -0500 Subject: [PATCH 032/181] removed a debug print call --- softsynth.c | 1 - 1 file changed, 1 deletion(-) diff --git a/softsynth.c b/softsynth.c index ca17db4..094eab0 100644 --- a/softsynth.c +++ b/softsynth.c @@ -234,7 +234,6 @@ void *softsynth_thread(void *arg) cp = strrchr(buf, synthFlushChar); if (cp) { request_espeak_stop(); - printf("Returned from stop_runner\n"); memmove(buf, cp + 1, strlen(cp + 1) + 1); length = strlen(buf); } From b8c7247feb05a07bab653cab2a6be50a4a17fd5d Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Thu, 25 Jun 2009 14:05:36 -0500 Subject: [PATCH 033/181] removed acknowledge_guard and substituted queue_guard --- espeakup.c | 1 - espeakup.h | 1 - softsynth.c | 13 ++----------- synth.c | 4 ++-- 4 files changed, 4 insertions(+), 15 deletions(-) diff --git a/espeakup.c b/espeakup.c index 0cf3d0b..65570f0 100644 --- a/espeakup.c +++ b/espeakup.c @@ -42,7 +42,6 @@ espeak_AUDIO_OUTPUT audio_mode; pthread_cond_t runner_awake = PTHREAD_COND_INITIALIZER; pthread_cond_t stop_acknowledged = PTHREAD_COND_INITIALIZER; pthread_mutex_t queue_guard = PTHREAD_MUTEX_INITIALIZER; -pthread_mutex_t acknowledge_guard = PTHREAD_MUTEX_INITIALIZER; int espeakup_is_running(void) { diff --git a/espeakup.h b/espeakup.h index d5d3f18..ffe375b 100644 --- a/espeakup.h +++ b/espeakup.h @@ -88,6 +88,5 @@ extern espeak_AUDIO_OUTPUT audio_mode; extern pthread_cond_t runner_awake; extern pthread_cond_t stop_acknowledged; extern pthread_mutex_t queue_guard; -extern pthread_mutex_t acknowledge_guard; #endif diff --git a/softsynth.c b/softsynth.c index 094eab0..258d6e0 100644 --- a/softsynth.c +++ b/softsynth.c @@ -167,20 +167,11 @@ static void process_buffer(struct synth_t *s, char *buf, ssize_t length) static void request_espeak_stop(void) { - pthread_mutex_lock(&acknowledge_guard); pthread_mutex_lock(&queue_guard); runner_must_stop = 1; - pthread_mutex_unlock(&queue_guard); pthread_cond_signal(&runner_awake); /* Wake runner, if necessary. */ - - /* - * Runner will see runner_must_stop == 1 next time it locks - * queue_guard, or when it awakens. - * It will lock acknowledge_guard, acknowledge the stop, and signal - * the reader, which will awaken. - */ - pthread_cond_wait(&stop_acknowledged, &acknowledge_guard); - pthread_mutex_unlock(&acknowledge_guard); + pthread_cond_wait(&stop_acknowledged, &queue_guard); + pthread_mutex_unlock(&queue_guard); } void *softsynth_thread(void *arg) diff --git a/synth.c b/synth.c index f61d529..9fbdf07 100644 --- a/synth.c +++ b/synth.c @@ -265,12 +265,12 @@ void *espeak_thread(void *arg) } if (runner_must_stop) { - pthread_mutex_lock(&acknowledge_guard); + pthread_mutex_lock(&queue_guard); queue_clear(); stop_speech(); runner_must_stop = 0; - pthread_mutex_unlock(&acknowledge_guard); pthread_cond_signal(&stop_acknowledged); + pthread_mutex_unlock(&queue_guard); } } pthread_mutex_unlock(&queue_guard); From 975765289b3348219d0db8b2d64e2f4f7747f9f2 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Thu, 25 Jun 2009 14:17:21 -0500 Subject: [PATCH 034/181] made sure all cond_wait and cond_signal calls are inside lock/unlock calls --- softsynth.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/softsynth.c b/softsynth.c index 258d6e0..35d01fd 100644 --- a/softsynth.c +++ b/softsynth.c @@ -47,8 +47,8 @@ static void queue_add_cmd(enum command_t cmd, enum adjust_t adj, int value) entry->value = value; pthread_mutex_lock(&queue_guard); queue_add((void *) entry); - pthread_mutex_unlock(&queue_guard); pthread_cond_signal(&runner_awake); + pthread_mutex_unlock(&queue_guard); } static void queue_add_text(char *txt, size_t length) @@ -71,8 +71,8 @@ static void queue_add_text(char *txt, size_t length) entry->len = length; pthread_mutex_lock(&queue_guard); queue_add((void *) entry); - pthread_mutex_unlock(&queue_guard); pthread_cond_signal(&runner_awake); + pthread_mutex_unlock(&queue_guard); } static int process_command(struct synth_t *s, char *buf, int start) From 938e10b66a14237cdff734ae5b97525f9c4ae9cc Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Thu, 25 Jun 2009 14:36:25 -0500 Subject: [PATCH 035/181] removed a nested lock/unlock --- synth.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/synth.c b/synth.c index 9fbdf07..2ec8f1e 100644 --- a/synth.c +++ b/synth.c @@ -265,12 +265,10 @@ void *espeak_thread(void *arg) } if (runner_must_stop) { - pthread_mutex_lock(&queue_guard); queue_clear(); stop_speech(); runner_must_stop = 0; pthread_cond_signal(&stop_acknowledged); - pthread_mutex_unlock(&queue_guard); } } pthread_mutex_unlock(&queue_guard); From 3687f16b09d7ff37f73ca0f98acd8dedd4ce18c1 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Thu, 25 Jun 2009 17:05:51 -0500 Subject: [PATCH 036/181] wait for acknowledgements correctly pthread_cond_wait() can have spurious wakeups, so we need to be sure that the condition is actually true when we return from this function. Thanks to Chris Brannon for the patch. --- softsynth.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/softsynth.c b/softsynth.c index 35d01fd..d3fe1b1 100644 --- a/softsynth.c +++ b/softsynth.c @@ -170,7 +170,8 @@ static void request_espeak_stop(void) pthread_mutex_lock(&queue_guard); runner_must_stop = 1; pthread_cond_signal(&runner_awake); /* Wake runner, if necessary. */ - pthread_cond_wait(&stop_acknowledged, &queue_guard); + while(runner_must_stop == 1) + pthread_cond_wait(&stop_acknowledged, &queue_guard); /* wait for acknowledgement. */ pthread_mutex_unlock(&queue_guard); } From 6a15f2cccf4d98e112f09ae64e68773c028b76f6 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Thu, 25 Jun 2009 18:17:14 -0500 Subject: [PATCH 037/181] fixed first wait in softsynth thread The thread should wait if there is nothing in the queue and if there is not a request to stop. Thanks to Chris Brannon for the patch. --- synth.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/synth.c b/synth.c index 2ec8f1e..58e111b 100644 --- a/synth.c +++ b/synth.c @@ -257,7 +257,9 @@ void *espeak_thread(void *arg) pthread_mutex_lock(&queue_guard); while (should_run) { - pthread_cond_wait(&runner_awake, &queue_guard); + + while (should_run && !queue_peek() && !runner_must_stop) + pthread_cond_wait(&runner_awake, &queue_guard); while (should_run && queue_peek() && !runner_must_stop) { queue_process_entry(s); From dd00775695f713667b2fc295feab6a2a2fe1926e Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Thu, 25 Jun 2009 18:30:36 -0500 Subject: [PATCH 038/181] initialization update The main function now initializes espeak and opens the softsynth before starting the threads. This insures that the resources we need are active. --- espeakup.c | 11 +++++++++++ espeakup.h | 5 ++++- softsynth.c | 34 ++++++++++++++++++++------------ synth.c | 56 ++++++++++++++++++++++++++++------------------------- 4 files changed, 67 insertions(+), 39 deletions(-) diff --git a/espeakup.c b/espeakup.c index 65570f0..0eafc2f 100644 --- a/espeakup.c +++ b/espeakup.c @@ -104,6 +104,16 @@ int main(int argc, char **argv) } } +/* Initialize espeak */ + if (initialize_espeak(&s) < 0) { + return 2; + } + +/* open the softsynth */ + if (open_softsynth() < 0) { + return 2; + } + /* set up the pipe used to wake the espeak thread */ if (pipe(self_pipe_fds) < 0) { perror("Unable to create pipe"); @@ -142,6 +152,7 @@ int main(int argc, char **argv) pthread_join(softsynth_thread_id, NULL); pthread_join(espeak_thread_id, NULL); + espeak_Terminate(); if ( ! debug) unlink(pidPath); return 0; diff --git a/espeakup.h b/espeakup.h index ffe375b..2992aa2 100644 --- a/espeakup.h +++ b/espeakup.h @@ -70,8 +70,11 @@ extern void queue_add(void *entry); extern void queue_remove(void); extern void *queue_peek(void); extern void *signal_thread(void *arg); -extern void *softsynth_thread(void *arg); +extern int initialize_espeak(struct synth_t *s); extern void *espeak_thread(void *arg); +extern int open_softsynth(void); +extern void close_softsynth(void); +extern void *softsynth_thread(void *arg); extern void select_audio_mode(void); extern int init_audio(unsigned int rate); extern void lock_audio_mutex(void); diff --git a/softsynth.c b/softsynth.c index d3fe1b1..4472ff4 100644 --- a/softsynth.c +++ b/softsynth.c @@ -28,10 +28,12 @@ #include "espeakup.h" /* max buffer size */ -const size_t maxBufferSize = 1025; +static const size_t maxBufferSize = 1025; /* synth flush character */ -const int synthFlushChar = 0x18; +static const int synthFlushChar = 0x18; + +static int softFD = 0; static void queue_add_cmd(enum command_t cmd, enum adjust_t adj, int value) { @@ -175,6 +177,24 @@ static void request_espeak_stop(void) pthread_mutex_unlock(&queue_guard); } +int open_softsynth(void) +{ + int rc = 0; + /* open the softsynth. */ + softFD = open("/dev/softsynth", O_RDWR | O_NONBLOCK); + if (softFD < 0) { + perror("Unable to open the softsynth device"); + rc = -1; + } + return rc; +} + +void close_softsynth(void) +{ + if (softFD) + close(softFD); +} + void *softsynth_thread(void *arg) { struct synth_t *s = (struct synth_t *) arg; @@ -183,16 +203,8 @@ void *softsynth_thread(void *arg) char buf[maxBufferSize]; char *cp; int terminalFD = PIPE_READ_FD; - int softFD; int greatestFD; - /* open the softsynth. */ - softFD = open("/dev/softsynth", O_RDWR | O_NONBLOCK); - if (softFD < 0) { - perror("Unable to open the softsynth device"); - should_run = 0; - } - if (terminalFD > softFD) greatestFD = terminalFD; else @@ -231,7 +243,5 @@ void *softsynth_thread(void *arg) } process_buffer(s, buf, length); } - if (softFD) - close(softFD); return NULL; } diff --git a/synth.c b/synth.c index 58e111b..bcee672 100644 --- a/synth.c +++ b/synth.c @@ -206,6 +206,36 @@ static void queue_clear() } } +int initialize_espeak(struct synth_t *s) +{ + int rate; + + /* initialize espeak */ + select_audio_mode(); + rate = espeak_Initialize(audio_mode, 0, NULL, 0); + if (rate < 0) { + fprintf(stderr, "Unable to initialize espeak.\n"); + return -1; + } + + if (init_audio((unsigned int) rate) < 0) { + return -1; + } + + /* Setup initial voice parameters */ + if (defaultVoice) { + set_voice(s, defaultVoice); + free(defaultVoice); + defaultVoice = NULL; + } + set_frequency(s, defaultFrequency, ADJ_SET); + set_pitch(s, defaultPitch, ADJ_SET); + set_rate(s, defaultRate, ADJ_SET); + set_volume(s, defaultVolume, ADJ_SET); + espeak_SetParameter(espeakCAPITALS, 0, 0); + return 0; +} + /* espeak_thread is the "main" function of our secondary (queue-processing) * thread. * First, lock queue_guard, because it needs to be locked when we call @@ -225,35 +255,9 @@ static void queue_clear() * 1. We are waiting on runner_awake, or * 2. We are processing an entry that has just been removed from the queue. */ - void *espeak_thread(void *arg) { struct synth_t *s = (struct synth_t *) arg; - int rate; - - /* initialize espeak */ - select_audio_mode(); - rate = espeak_Initialize(audio_mode, 0, NULL, 0); - if (rate < 0) { - fprintf(stderr, "Unable to initialize espeak.\n"); - should_run = 0; - } - - if (init_audio((unsigned int) rate) < 0) { - should_run = 0; - } - - /* Setup initial voice parameters */ - if (defaultVoice) { - set_voice(s, defaultVoice); - free(defaultVoice); - defaultVoice = NULL; - } - set_frequency(s, defaultFrequency, ADJ_SET); - set_pitch(s, defaultPitch, ADJ_SET); - set_rate(s, defaultRate, ADJ_SET); - set_volume(s, defaultVolume, ADJ_SET); - espeak_SetParameter(espeakCAPITALS, 0, 0); pthread_mutex_lock(&queue_guard); while (should_run) { From eb74a3ce171515dd1f2970dfb3d1b6c2f07c6d79 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Thu, 25 Jun 2009 18:45:37 -0500 Subject: [PATCH 039/181] removed an unnecessary call to espeak_Terminate() --- synth.c | 1 - 1 file changed, 1 deletion(-) diff --git a/synth.c b/synth.c index bcee672..af2e6cc 100644 --- a/synth.c +++ b/synth.c @@ -278,6 +278,5 @@ void *espeak_thread(void *arg) } } pthread_mutex_unlock(&queue_guard); - espeak_Terminate(); return NULL; } From 1750b92cfb0e5d5a39564ea8d949113c4e0c3409 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Thu, 25 Jun 2009 20:04:42 -0500 Subject: [PATCH 040/181] fixed signal handling issue The signal handler stopped working after I moved the initialization calls to the main function. Creating the signal handler thread first fixed this issue. --- espeakup.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/espeakup.c b/espeakup.c index 0eafc2f..fd607a9 100644 --- a/espeakup.c +++ b/espeakup.c @@ -104,6 +104,21 @@ int main(int argc, char **argv) } } + /* create the signal processing thread here. */ + err = pthread_create(&signal_thread_id, NULL, signal_thread, NULL); + if (err != 0) { + return 4; + } + + /* + * Set up the signal mask which will be the default for all threads. + * We are handling sigint and sigterm, so block them. + */ + sigemptyset(&sigset); + sigaddset(&sigset, SIGINT); + sigaddset(&sigset, SIGTERM); + sigprocmask(SIG_BLOCK, &sigset, NULL); + /* Initialize espeak */ if (initialize_espeak(&s) < 0) { return 2; @@ -120,21 +135,6 @@ int main(int argc, char **argv) return 5; } - /* create the signal processing thread here. */ - err = pthread_create(&signal_thread_id, NULL, signal_thread, NULL); - if (err != 0) { - return 4; - } - - /* - * Set up the signal mask which will be the default for all threads. - * We are handling sigint and sigterm, so block them. - */ - sigemptyset(&sigset); - sigaddset(&sigset, SIGINT); - sigaddset(&sigset, SIGTERM); - sigprocmask(SIG_BLOCK, &sigset, NULL); - /* Spawn our softsynth thread. */ err = pthread_create(&softsynth_thread_id, NULL, softsynth_thread, &s); if (err != 0) { @@ -153,6 +153,7 @@ int main(int argc, char **argv) pthread_join(espeak_thread_id, NULL); espeak_Terminate(); + close_softsynth(); if ( ! debug) unlink(pidPath); return 0; From 633743117c7067bb7f7a7a12f2edbe6bb463a366 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Thu, 25 Jun 2009 20:24:34 -0500 Subject: [PATCH 041/181] mutex fixes We need to make sure that should_run is protected by the mutex. --- signal.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/signal.c b/signal.c index 6fdf6bc..6482264 100644 --- a/signal.c +++ b/signal.c @@ -46,14 +46,18 @@ void *signal_thread(void *arg) sigaction(SIGINT, &temp, NULL); sigaction(SIGTERM, &temp, NULL); + pthread_mutex_lock(&queue_guard); while(should_run) { + pthread_mutex_unlock(&queue_guard); sigfillset(&sigset); sigwait(&sigset, &sig); switch (sig) { case SIGINT: case SIGTERM: printf("This is where we shut down.\n"); + pthread_mutex_lock(&queue_guard); should_run = 0; + pthread_mutex_unlock(&queue_guard); break; default: printf("espeakup caught signal %d\n", sig); From d5fd5d69b84cdcde67357a5a934b343e46a32cb2 Mon Sep 17 00:00:00 2001 From: Chris Brannon Date: Thu, 25 Jun 2009 20:33:17 -0500 Subject: [PATCH 042/181] don't wait on a condition variable if should_run is false --- softsynth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/softsynth.c b/softsynth.c index 4472ff4..21f3cb8 100644 --- a/softsynth.c +++ b/softsynth.c @@ -172,7 +172,7 @@ static void request_espeak_stop(void) pthread_mutex_lock(&queue_guard); runner_must_stop = 1; pthread_cond_signal(&runner_awake); /* Wake runner, if necessary. */ - while(runner_must_stop == 1) + while(should_run && (runner_must_stop == 1)) pthread_cond_wait(&stop_acknowledged, &queue_guard); /* wait for acknowledgement. */ pthread_mutex_unlock(&queue_guard); } From 5ebe506026cf2a5953ba9773d2e2c434e8bbc6f4 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Thu, 25 Jun 2009 21:07:24 -0500 Subject: [PATCH 043/181] more mutex fixes Make sure that should_run is protected by the mutex in the softsynth thread. --- softsynth.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/softsynth.c b/softsynth.c index 21f3cb8..62dfd84 100644 --- a/softsynth.c +++ b/softsynth.c @@ -209,29 +209,41 @@ void *softsynth_thread(void *arg) greatestFD = terminalFD; else greatestFD = softFD; + pthread_mutex_lock(&queue_guard); while (should_run) { + pthread_mutex_unlock(&queue_guard); FD_ZERO(&set); FD_SET(softFD, &set); FD_SET(terminalFD, &set); if (select(greatestFD + 1, &set, NULL, NULL, NULL) < 0) { - if (errno == EINTR) + if (errno == EINTR) { + pthread_mutex_lock(&queue_guard); continue; + } perror("Select failed"); + pthread_mutex_lock(&queue_guard); break; } - if (FD_ISSET(terminalFD, &set)) + if (FD_ISSET(terminalFD, &set)) { + pthread_mutex_lock(&queue_guard); break; + } - if (!FD_ISSET(softFD, &set)) + if (!FD_ISSET(softFD, &set)) { + pthread_mutex_lock(&queue_guard); continue; + } length = read(softFD, buf, maxBufferSize - 1); if (length < 0) { - if (errno == EAGAIN || errno == EINTR) + if (errno == EAGAIN || errno == EINTR) { + pthread_mutex_lock(&queue_guard); continue; + } perror("Read from softsynth failed"); + pthread_mutex_lock(&queue_guard); break; } *(buf + length) = 0; @@ -242,6 +254,8 @@ void *softsynth_thread(void *arg) length = strlen(buf); } process_buffer(s, buf, length); + pthread_mutex_lock(&queue_guard); } + pthread_mutex_unlock(&queue_guard); return NULL; } From 5ec3809c599981f79db87f41f4b181eb5456a4f7 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Thu, 25 Jun 2009 21:17:34 -0500 Subject: [PATCH 044/181] wake up espeak_thread when softsynth_thread terminates espeak_thread needs a signal since it might be sleeping and should_run has changed. This makes sure it terminates. --- softsynth.c | 1 + 1 file changed, 1 insertion(+) diff --git a/softsynth.c b/softsynth.c index 62dfd84..96d0aca 100644 --- a/softsynth.c +++ b/softsynth.c @@ -256,6 +256,7 @@ void *softsynth_thread(void *arg) process_buffer(s, buf, length); pthread_mutex_lock(&queue_guard); } + pthread_cond_signal(&runner_awake); pthread_mutex_unlock(&queue_guard); return NULL; } From 24bcdf5666d2546b9177b54b25d2fbfc54ab804b Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Thu, 25 Jun 2009 22:00:25 -0500 Subject: [PATCH 045/181] another termination fix espeak_thread needs to signal softsynth_thread once more as it is going town so that softsynth_thread will see that should_run is now 0 and terminate. --- synth.c | 1 + 1 file changed, 1 insertion(+) diff --git a/synth.c b/synth.c index af2e6cc..ca9972c 100644 --- a/synth.c +++ b/synth.c @@ -277,6 +277,7 @@ void *espeak_thread(void *arg) pthread_cond_signal(&stop_acknowledged); } } + pthread_cond_signal(&stop_acknowledged); pthread_mutex_unlock(&queue_guard); return NULL; } From e49acbb59acdbad827da2fc4dd7061e7fe2de35a Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Thu, 25 Jun 2009 22:03:57 -0500 Subject: [PATCH 046/181] removed a debug print --- signal.c | 1 - 1 file changed, 1 deletion(-) diff --git a/signal.c b/signal.c index 6482264..5a49183 100644 --- a/signal.c +++ b/signal.c @@ -54,7 +54,6 @@ void *signal_thread(void *arg) switch (sig) { case SIGINT: case SIGTERM: - printf("This is where we shut down.\n"); pthread_mutex_lock(&queue_guard); should_run = 0; pthread_mutex_unlock(&queue_guard); From 8f3e8f196711d729de6c2dc1ed1ef2d086f99955 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Fri, 26 Jun 2009 09:50:11 -0500 Subject: [PATCH 047/181] moved the audio_mutex code to alsa This is not needed for native sound support, so it has been moved into the alsa specific code. --- alsa.c | 31 ++++++++++++++++++------------- espeak_sound.c | 9 ++------- espeakup.c | 1 - espeakup.h | 5 ++--- synth.c | 8 ++------ 5 files changed, 24 insertions(+), 30 deletions(-) diff --git a/alsa.c b/alsa.c index ae38798..8f05fd9 100644 --- a/alsa.c +++ b/alsa.c @@ -30,22 +30,13 @@ #include "espeakup.h" static pthread_mutex_t audio_mutex = PTHREAD_MUTEX_INITIALIZER; +static volatile int stopped = 0; static snd_pcm_t *handle; static snd_pcm_hw_params_t *params; snd_pcm_status_t *status; static int dir = 0; -void lock_audio_mutex(void) -{ - pthread_mutex_lock(&audio_mutex); -} - -void unlock_audio_mutex(void) -{ - pthread_mutex_unlock(&audio_mutex); -} - int sound_error(int err, const char *msg) { fprintf(stderr, "%s: %s\n", msg, snd_strerror(err)); @@ -68,14 +59,14 @@ static int alsa_play_callback(short *audio, int numsamples, int to_write; snd_pcm_state_t state; - lock_audio_mutex(); + pthread_mutex_lock(&audio_mutex); if (stopped) { snd_pcm_drop(handle); stopped = 0; - unlock_audio_mutex(); + pthread_mutex_unlock(&audio_mutex); return 1; } - unlock_audio_mutex(); + pthread_mutex_unlock(&audio_mutex); snd_pcm_status(handle, status); state = snd_pcm_status_get_state(status); @@ -165,3 +156,17 @@ int init_audio(unsigned int rate) espeak_SetSynthCallback(alsa_play_callback); return 0; } + +void stop_audio(void) +{ + pthread_mutex_lock(&audio_mutex); + stopped = 1; + pthread_mutex_unlock(&audio_mutex); +} + +void allow_audio(void) +{ + pthread_mutex_lock(&audio_mutex); + stopped = 0; + pthread_mutex_unlock(&audio_mutex); +} diff --git a/espeak_sound.c b/espeak_sound.c index 4c2d6d1..b20f0e2 100644 --- a/espeak_sound.c +++ b/espeak_sound.c @@ -10,17 +10,12 @@ int init_audio(unsigned int rate) return 0; } -/* - * lock_audio_mutex and unlock_audio_mutex are no-ops if we use native - * sound support. The stopped variable is never read; no need to protect it. - */ - -void lock_audio_mutex(void) +void stop_audio(void) { return; } -void unlock_audio_mutex(void) +void allow_audio(void) { return; } diff --git a/espeakup.c b/espeakup.c index fd607a9..8ab88ad 100644 --- a/espeakup.c +++ b/espeakup.c @@ -35,7 +35,6 @@ const char *pidPath = "/var/run/espeakup.pid"; int debug = 0; int self_pipe_fds[2]; -volatile int stopped = 0; volatile int should_run = 1; espeak_AUDIO_OUTPUT audio_mode; diff --git a/espeakup.h b/espeakup.h index 2992aa2..37ae8fd 100644 --- a/espeakup.h +++ b/espeakup.h @@ -77,10 +77,9 @@ extern void close_softsynth(void); extern void *softsynth_thread(void *arg); extern void select_audio_mode(void); extern int init_audio(unsigned int rate); -extern void lock_audio_mutex(void); -extern void unlock_audio_mutex(void); +extern void stop_audio(void); +extern void allow_audio(void); extern volatile int should_run; -extern volatile int stopped; extern volatile int runner_must_stop; extern int self_pipe_fds[2]; #define PIPE_READ_FD (self_pipe_fds[0]) diff --git a/synth.c b/synth.c index ca9972c..991a11a 100644 --- a/synth.c +++ b/synth.c @@ -125,9 +125,7 @@ static espeak_ERROR set_volume(struct synth_t * s, int vol, enum adjust_t adj) static espeak_ERROR stop_speech(void) { - lock_audio_mutex(); - stopped = 1; - unlock_audio_mutex(); + stop_audio(); return (espeak_Cancel()); } @@ -135,9 +133,7 @@ static espeak_ERROR speak_text(struct synth_t * s) { espeak_ERROR rc; - lock_audio_mutex(); - stopped = 0; - unlock_audio_mutex(); + allow_audio(); rc = espeak_Synth(s->buf, s->len + 1, 0, POS_CHARACTER, 0, 0, NULL, NULL); return rc; From 520bbae36512731bc075870c0baa9339929b4fde Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Fri, 26 Jun 2009 10:03:11 -0500 Subject: [PATCH 048/181] renamed stopped to stop_requested This is more descriptive of what the variable actually does. It signals the callback to stop the audio. --- alsa.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/alsa.c b/alsa.c index 8f05fd9..c1c51d0 100644 --- a/alsa.c +++ b/alsa.c @@ -30,7 +30,7 @@ #include "espeakup.h" static pthread_mutex_t audio_mutex = PTHREAD_MUTEX_INITIALIZER; -static volatile int stopped = 0; +static volatile int stop_requested = 0; static snd_pcm_t *handle; static snd_pcm_hw_params_t *params; @@ -60,9 +60,9 @@ static int alsa_play_callback(short *audio, int numsamples, snd_pcm_state_t state; pthread_mutex_lock(&audio_mutex); - if (stopped) { + if (stop_requested) { snd_pcm_drop(handle); - stopped = 0; + stop_requested = 0; pthread_mutex_unlock(&audio_mutex); return 1; } @@ -160,13 +160,13 @@ int init_audio(unsigned int rate) void stop_audio(void) { pthread_mutex_lock(&audio_mutex); - stopped = 1; + stop_requested = 1; pthread_mutex_unlock(&audio_mutex); } void allow_audio(void) { pthread_mutex_lock(&audio_mutex); - stopped = 0; + stop_requested = 0; pthread_mutex_unlock(&audio_mutex); } From 0471ff47f4dc031cf70b14eb15128fd60fb185dd Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Fri, 26 Jun 2009 11:34:28 -0500 Subject: [PATCH 049/181] add support for the user_data parameter to espeak_synth The user_data parameter is just a pointer that is passed into the espeak_synth call that is passed back to the callback. In native mode, we are not using it since there is not a callback. However, in alsa mode, it will be used to indicate when a cancel was processed. --- synth.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/synth.c b/synth.c index 991a11a..1ef8250 100644 --- a/synth.c +++ b/synth.c @@ -37,6 +37,7 @@ const int rateMultiplier = 34; const int rateOffset = 84; const int volumeMultiplier = 22; +static int user_data = 0; volatile int runner_must_stop = 0; static espeak_ERROR set_frequency(struct synth_t *s, int freq, enum adjust_t adj) @@ -125,8 +126,12 @@ static espeak_ERROR set_volume(struct synth_t * s, int vol, enum adjust_t adj) static espeak_ERROR stop_speech(void) { + espeak_ERROR rc; + stop_audio(); - return (espeak_Cancel()); + rc = espeak_Cancel(); + user_data = (user_data + 1) % 100; + return rc; } static espeak_ERROR speak_text(struct synth_t * s) @@ -135,7 +140,7 @@ static espeak_ERROR speak_text(struct synth_t * s) allow_audio(); rc = espeak_Synth(s->buf, s->len + 1, 0, POS_CHARACTER, 0, 0, NULL, - NULL); + &user_data); return rc; } From c1d33d673838faf8b70cc42c72c119f5c0002d44 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Fri, 26 Jun 2009 16:00:08 -0500 Subject: [PATCH 050/181] Set the espeak audio buffer size to 50 ms This should help make the cancel command more responsive. --- synth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synth.c b/synth.c index 1ef8250..e3dbab5 100644 --- a/synth.c +++ b/synth.c @@ -213,7 +213,7 @@ int initialize_espeak(struct synth_t *s) /* initialize espeak */ select_audio_mode(); - rate = espeak_Initialize(audio_mode, 0, NULL, 0); + rate = espeak_Initialize(audio_mode, 50, NULL, 0); if (rate < 0) { fprintf(stderr, "Unable to initialize espeak.\n"); return -1; From be879d206b52221546e4b8e00b60e0c0cf70f855 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Fri, 26 Jun 2009 16:12:31 -0500 Subject: [PATCH 051/181] alsa update I changed the name of the callback to alsa_callback and removed a line that was making the amount of data written to the sound card very small. --- alsa.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/alsa.c b/alsa.c index c1c51d0..8b967e8 100644 --- a/alsa.c +++ b/alsa.c @@ -51,8 +51,7 @@ int minimum(int x, int y) return y; } -static int alsa_play_callback(short *audio, int numsamples, - espeak_EVENT * events) +static int alsa_callback(short *audio, int numsamples, espeak_EVENT * events) { int samples_written = 0; int avail; @@ -77,7 +76,6 @@ static int alsa_play_callback(short *audio, int numsamples, avail = snd_pcm_avail_update(handle); if (avail <= 0) continue; - avail = minimum(avail, 32 * 2); to_write = minimum(avail, numsamples); samples_written = snd_pcm_writei(handle, audio, to_write); if (samples_written < 0) { @@ -99,7 +97,6 @@ int init_audio(unsigned int rate) { int rc; - /* Open PCM device for playback. */ rc = snd_pcm_open(&handle, "default", SND_PCM_STREAM_PLAYBACK, 0); if (rc < 0) @@ -153,7 +150,7 @@ int init_audio(unsigned int rate) if (rc < 0) return sound_error(rc, "unable to set hw parameters"); - espeak_SetSynthCallback(alsa_play_callback); + espeak_SetSynthCallback(alsa_callback); return 0; } From a9398bdeb413f8c9b88178756e0cdc7ede55b0bc Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Fri, 26 Jun 2009 23:11:15 -0500 Subject: [PATCH 052/181] Added another error check for alsa --- alsa.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/alsa.c b/alsa.c index 8b967e8..ef0a4cf 100644 --- a/alsa.c +++ b/alsa.c @@ -74,8 +74,13 @@ static int alsa_callback(short *audio, int numsamples, espeak_EVENT * events) while (numsamples > 0) { avail = snd_pcm_avail_update(handle); - if (avail <= 0) + if (avail == 0) continue; + if(avail < 0) { + /* Apparently this also can fail on buffer underrun. */ + snd_pcm_prepare(handle); + continue; + } to_write = minimum(avail, numsamples); samples_written = snd_pcm_writei(handle, audio, to_write); if (samples_written < 0) { From 4889572ad18a8be877916d131d9a101b6563773c Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Sat, 27 Jun 2009 13:20:43 -0500 Subject: [PATCH 053/181] use user_data to detect old events When espeak_Cancel is called, change the value of user_data that is passed to the events, and, in the callback, use this to test to see if cancel was received. If the value of user_data has changed, discarde events that have the old value. This patch is from Chris Brannon. --- alsa.c | 34 +++++++++++++++++++++++++++++----- espeak_sound.c | 7 ++++++- espeakup.h | 3 ++- synth.c | 3 ++- 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/alsa.c b/alsa.c index ef0a4cf..e1174ac 100644 --- a/alsa.c +++ b/alsa.c @@ -53,20 +53,41 @@ int minimum(int x, int y) static int alsa_callback(short *audio, int numsamples, espeak_EVENT * events) { + static int discarding_packets = 0; + static int user_data_old = 0; int samples_written = 0; int avail; int to_write; snd_pcm_state_t state; + int user_data_new; pthread_mutex_lock(&audio_mutex); + user_data_new = *(int *) events->user_data; if (stop_requested) { snd_pcm_drop(handle); stop_requested = 0; - pthread_mutex_unlock(&audio_mutex); - return 1; + discarding_packets = 1; } + pthread_mutex_unlock(&audio_mutex); + /* + * If discarding_packets is true, then do the following. + * Compare user_data_old and user_data_new. If they are equal, + * then espeak is still sending stale data through the callback. + * Keep on discarding it, and return 1. + * If they are different, a new stream has started. We can stop + * discarding. Just process the new data. + */ + + if (discarding_packets) { + if (user_data_new == user_data_old) + return 1; /* Discard stale data. */ + else + discarding_packets = 0; + } + + user_data_old = user_data_new; snd_pcm_status(handle, status); state = snd_pcm_status_get_state(status); if (state != SND_PCM_STATE_RUNNING) @@ -76,7 +97,7 @@ static int alsa_callback(short *audio, int numsamples, espeak_EVENT * events) avail = snd_pcm_avail_update(handle); if (avail == 0) continue; - if(avail < 0) { + if (avail < 0) { /* Apparently this also can fail on buffer underrun. */ snd_pcm_prepare(handle); continue; @@ -166,9 +187,12 @@ void stop_audio(void) pthread_mutex_unlock(&audio_mutex); } -void allow_audio(void) +void lock_audio_mutex(void) { pthread_mutex_lock(&audio_mutex); - stop_requested = 0; +} + +void unlock_audio_mutex(void) +{ pthread_mutex_unlock(&audio_mutex); } diff --git a/espeak_sound.c b/espeak_sound.c index b20f0e2..6cba147 100644 --- a/espeak_sound.c +++ b/espeak_sound.c @@ -15,7 +15,12 @@ void stop_audio(void) return; } -void allow_audio(void) +void lock_audio_mutex(void) +{ + return; +} + +void unlock_audio_mutex(void) { return; } diff --git a/espeakup.h b/espeakup.h index 37ae8fd..9650bb6 100644 --- a/espeakup.h +++ b/espeakup.h @@ -78,7 +78,8 @@ extern void *softsynth_thread(void *arg); extern void select_audio_mode(void); extern int init_audio(unsigned int rate); extern void stop_audio(void); -extern void allow_audio(void); +extern void lock_audio_mutex(void); +extern void unlock_audio_mutex(void); extern volatile int should_run; extern volatile int runner_must_stop; extern int self_pipe_fds[2]; diff --git a/synth.c b/synth.c index e3dbab5..77e5a5c 100644 --- a/synth.c +++ b/synth.c @@ -130,7 +130,9 @@ static espeak_ERROR stop_speech(void) stop_audio(); rc = espeak_Cancel(); + lock_audio_mutex(); user_data = (user_data + 1) % 100; + unlock_audio_mutex(); return rc; } @@ -138,7 +140,6 @@ static espeak_ERROR speak_text(struct synth_t * s) { espeak_ERROR rc; - allow_audio(); rc = espeak_Synth(s->buf, s->len + 1, 0, POS_CHARACTER, 0, 0, NULL, &user_data); return rc; From 87ab6c6ea822f9f7b393d1cb83c9f579d728326a Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Sat, 27 Jun 2009 13:32:43 -0500 Subject: [PATCH 054/181] make sure that snd_pcm_drop is successful. This was suggested by Kirk Reiser and Chris Brannon. --- alsa.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/alsa.c b/alsa.c index e1174ac..cb74395 100644 --- a/alsa.c +++ b/alsa.c @@ -58,13 +58,20 @@ static int alsa_callback(short *audio, int numsamples, espeak_EVENT * events) int samples_written = 0; int avail; int to_write; + int rc; snd_pcm_state_t state; int user_data_new; pthread_mutex_lock(&audio_mutex); user_data_new = *(int *) events->user_data; if (stop_requested) { - snd_pcm_drop(handle); + rc = snd_pcm_drop(handle); + while(rc < 0) { + fprintf(stderr, "Negative return from snd_pcm_drop!\n"); + /* Try to reset stream. */ + snd_pcm_prepare(handle); + rc = snd_pcm_drop(handle); + } stop_requested = 0; discarding_packets = 1; } From 46bf3d99d51960c7a179d9bfd6724c4a428e0658 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Sat, 27 Jun 2009 16:05:27 -0500 Subject: [PATCH 055/181] all access of the audio mutex should go through our functions --- alsa.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/alsa.c b/alsa.c index cb74395..bad766a 100644 --- a/alsa.c +++ b/alsa.c @@ -62,7 +62,7 @@ static int alsa_callback(short *audio, int numsamples, espeak_EVENT * events) snd_pcm_state_t state; int user_data_new; - pthread_mutex_lock(&audio_mutex); + lock_audio_mutex(); user_data_new = *(int *) events->user_data; if (stop_requested) { rc = snd_pcm_drop(handle); @@ -76,7 +76,7 @@ static int alsa_callback(short *audio, int numsamples, espeak_EVENT * events) discarding_packets = 1; } - pthread_mutex_unlock(&audio_mutex); + unlock_audio_mutex(); /* * If discarding_packets is true, then do the following. @@ -189,9 +189,9 @@ int init_audio(unsigned int rate) void stop_audio(void) { - pthread_mutex_lock(&audio_mutex); + lock_audio_mutex(); stop_requested = 1; - pthread_mutex_unlock(&audio_mutex); + unlock_audio_mutex(); } void lock_audio_mutex(void) From 9b7dcebb6d3dd84d19a448e7e79a1746cd939a62 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Sat, 27 Jun 2009 17:10:10 -0500 Subject: [PATCH 056/181] alsa updates The first while loop in the callback doesn't need to be a loop. If the audio fails, we can just print an error and return. --- alsa.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/alsa.c b/alsa.c index bad766a..b83dc64 100644 --- a/alsa.c +++ b/alsa.c @@ -58,24 +58,19 @@ static int alsa_callback(short *audio, int numsamples, espeak_EVENT * events) int samples_written = 0; int avail; int to_write; - int rc; snd_pcm_state_t state; int user_data_new; lock_audio_mutex(); user_data_new = *(int *) events->user_data; if (stop_requested) { - rc = snd_pcm_drop(handle); - while(rc < 0) { + if(snd_pcm_drop(handle) < 0) { fprintf(stderr, "Negative return from snd_pcm_drop!\n"); - /* Try to reset stream. */ - snd_pcm_prepare(handle); - rc = snd_pcm_drop(handle); + return 1; } stop_requested = 0; discarding_packets = 1; } - unlock_audio_mutex(); /* @@ -86,7 +81,6 @@ static int alsa_callback(short *audio, int numsamples, espeak_EVENT * events) * If they are different, a new stream has started. We can stop * discarding. Just process the new data. */ - if (discarding_packets) { if (user_data_new == user_data_old) return 1; /* Discard stale data. */ @@ -100,7 +94,7 @@ static int alsa_callback(short *audio, int numsamples, espeak_EVENT * events) if (state != SND_PCM_STATE_RUNNING) snd_pcm_prepare(handle); - while (numsamples > 0) { + while (numsamples > 0 && ! stop_requested) { avail = snd_pcm_avail_update(handle); if (avail == 0) continue; From bcd64cb263745e3994484156713a601db1b59990 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Sat, 27 Jun 2009 17:49:57 -0500 Subject: [PATCH 057/181] created a start_audio function This moves audio control to the specific files, espeak_sound.c and alsa.c, which are tied to the sound systems. --- alsa.c | 31 +++++++++++++++++++------------ espeak_sound.c | 7 +------ espeakup.h | 3 +-- synth.c | 4 +--- 4 files changed, 22 insertions(+), 23 deletions(-) diff --git a/alsa.c b/alsa.c index b83dc64..976769e 100644 --- a/alsa.c +++ b/alsa.c @@ -37,13 +37,23 @@ static snd_pcm_hw_params_t *params; snd_pcm_status_t *status; static int dir = 0; -int sound_error(int err, const char *msg) +static void lock_audio_mutex(void) +{ + pthread_mutex_lock(&audio_mutex); +} + +static void unlock_audio_mutex(void) +{ + pthread_mutex_unlock(&audio_mutex); +} + +static int sound_error(int err, const char *msg) { fprintf(stderr, "%s: %s\n", msg, snd_strerror(err)); return err; } -int minimum(int x, int y) +static int minimum(int x, int y) { if (x <= y) return x; @@ -68,7 +78,6 @@ static int alsa_callback(short *audio, int numsamples, espeak_EVENT * events) fprintf(stderr, "Negative return from snd_pcm_drop!\n"); return 1; } - stop_requested = 0; discarding_packets = 1; } unlock_audio_mutex(); @@ -188,12 +197,10 @@ void stop_audio(void) unlock_audio_mutex(); } -void lock_audio_mutex(void) -{ - pthread_mutex_lock(&audio_mutex); -} - -void unlock_audio_mutex(void) -{ - pthread_mutex_unlock(&audio_mutex); -} + void start_audio(int *user_data) + { + lock_audio_mutex(); + *user_data = (*user_data + 1) % 100; + stop_requested = 0; + unlock_audio_mutex(); + } diff --git a/espeak_sound.c b/espeak_sound.c index 6cba147..ec3f286 100644 --- a/espeak_sound.c +++ b/espeak_sound.c @@ -15,12 +15,7 @@ void stop_audio(void) return; } -void lock_audio_mutex(void) -{ - return; -} - -void unlock_audio_mutex(void) +void start_audio(int *user_data) { return; } diff --git a/espeakup.h b/espeakup.h index 9650bb6..91e9cbb 100644 --- a/espeakup.h +++ b/espeakup.h @@ -78,8 +78,7 @@ extern void *softsynth_thread(void *arg); extern void select_audio_mode(void); extern int init_audio(unsigned int rate); extern void stop_audio(void); -extern void lock_audio_mutex(void); -extern void unlock_audio_mutex(void); +extern void start_audio(int *user_data); extern volatile int should_run; extern volatile int runner_must_stop; extern int self_pipe_fds[2]; diff --git a/synth.c b/synth.c index 77e5a5c..28aa15c 100644 --- a/synth.c +++ b/synth.c @@ -130,9 +130,7 @@ static espeak_ERROR stop_speech(void) stop_audio(); rc = espeak_Cancel(); - lock_audio_mutex(); - user_data = (user_data + 1) % 100; - unlock_audio_mutex(); + start_audio(&user_data); return rc; } From 0238baa5c29f9fef26b4608be24e4f63b2927e82 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Sun, 28 Jun 2009 13:52:31 -0500 Subject: [PATCH 058/181] more alsa updates Made an 'if' statement in the callback more clear and added some locking for the audio mutex. --- alsa.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/alsa.c b/alsa.c index 976769e..5db5dc3 100644 --- a/alsa.c +++ b/alsa.c @@ -103,13 +103,14 @@ static int alsa_callback(short *audio, int numsamples, espeak_EVENT * events) if (state != SND_PCM_STATE_RUNNING) snd_pcm_prepare(handle); + lock_audio_mutex(); while (numsamples > 0 && ! stop_requested) { + unlock_audio_mutex(); avail = snd_pcm_avail_update(handle); - if (avail == 0) - continue; - if (avail < 0) { - /* Apparently this also can fail on buffer underrun. */ - snd_pcm_prepare(handle); + if (avail <= 0) { + if (avail < 0) + snd_pcm_prepare(handle); + lock_audio_mutex(); continue; } to_write = minimum(avail, numsamples); @@ -120,7 +121,9 @@ static int alsa_callback(short *audio, int numsamples, espeak_EVENT * events) numsamples -= samples_written; audio += samples_written; } + lock_audio_mutex(); } + unlock_audio_mutex(); return 0; } @@ -197,10 +200,10 @@ void stop_audio(void) unlock_audio_mutex(); } - void start_audio(int *user_data) - { +void start_audio(int *user_data) +{ lock_audio_mutex(); *user_data = (*user_data + 1) % 100; stop_requested = 0; unlock_audio_mutex(); - } +} From 58f09983f856703e8a06d9b16ef17b7d8728eb4d Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Sun, 28 Jun 2009 15:52:59 -0500 Subject: [PATCH 059/181] fixed callback return code The callback should use the value of stop_requested as its return code. --- alsa.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/alsa.c b/alsa.c index 5db5dc3..464bffa 100644 --- a/alsa.c +++ b/alsa.c @@ -70,6 +70,7 @@ static int alsa_callback(short *audio, int numsamples, espeak_EVENT * events) int to_write; snd_pcm_state_t state; int user_data_new; + int rc = 0; lock_audio_mutex(); user_data_new = *(int *) events->user_data; @@ -123,8 +124,9 @@ static int alsa_callback(short *audio, int numsamples, espeak_EVENT * events) } lock_audio_mutex(); } + rc = stop_requested; unlock_audio_mutex(); - return 0; + return rc; } void select_audio_mode(void) From a82bbd81400cfa002835c35ce46a956cc81460ad Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Sun, 28 Jun 2009 17:56:21 -0500 Subject: [PATCH 060/181] fixed a memory leak If we processed an entry from the queue successfully, we were removing the entry itself from the queue but not freeing the memory allocated to the entry. --- synth.c | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/synth.c b/synth.c index 28aa15c..f77960e 100644 --- a/synth.c +++ b/synth.c @@ -17,6 +17,7 @@ * along with this program. If not, see . */ +#include #include #include #include @@ -143,6 +144,26 @@ static espeak_ERROR speak_text(struct synth_t * s) return rc; } +static void free_espeak_entry(struct espeak_entry_t *entry) +{ + assert(entry); + if (entry->cmd == CMD_SPEAK_TEXT) + free(entry->buf); + free(entry); +} + +static void queue_clear() +{ + struct espeak_entry_t *current; + + current = (struct espeak_entry_t *) queue_peek(); + while (current) { + free_espeak_entry(current); + queue_remove(); + current = (struct espeak_entry_t *) queue_peek(); + } +} + static void queue_process_entry(struct synth_t *s) { espeak_ERROR error; @@ -180,6 +201,7 @@ static void queue_process_entry(struct synth_t *s) } if (error == EE_OK) { + free_espeak_entry(current); pthread_mutex_lock(&queue_guard); queue_remove(); pthread_mutex_unlock(&queue_guard); @@ -187,25 +209,6 @@ static void queue_process_entry(struct synth_t *s) } } -static void free_entry(struct espeak_entry_t *entry) -{ - if (entry->cmd == CMD_SPEAK_TEXT) - free(entry->buf); - free(entry); -} - -static void queue_clear() -{ - struct espeak_entry_t *current; - - current = (struct espeak_entry_t *) queue_peek(); - while (current) { - free_entry(current); - queue_remove(); - current = (struct espeak_entry_t *) queue_peek(); - } -} - int initialize_espeak(struct synth_t *s) { int rate; From c9f871f687c6bd6ef1a562000c53c6762cfa7205 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Mon, 29 Jun 2009 15:26:48 -0500 Subject: [PATCH 061/181] see if we need to silence speech before we process the queue --- synth.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/synth.c b/synth.c index f77960e..e454ed4 100644 --- a/synth.c +++ b/synth.c @@ -268,17 +268,17 @@ void *espeak_thread(void *arg) while (should_run && !queue_peek() && !runner_must_stop) pthread_cond_wait(&runner_awake, &queue_guard); - while (should_run && queue_peek() && !runner_must_stop) { - queue_process_entry(s); - pthread_mutex_lock(&queue_guard); - } - if (runner_must_stop) { queue_clear(); stop_speech(); runner_must_stop = 0; pthread_cond_signal(&stop_acknowledged); } + + while (should_run && queue_peek() && !runner_must_stop) { + queue_process_entry(s); + pthread_mutex_lock(&queue_guard); + } } pthread_cond_signal(&stop_acknowledged); pthread_mutex_unlock(&queue_guard); From ceaae3640a51fad408386f27bb30fe2063cdf58e Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Mon, 29 Jun 2009 15:59:55 -0500 Subject: [PATCH 062/181] audio should be stopped in softsynth_thread not espeak_thread --- softsynth.c | 1 + synth.c | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/softsynth.c b/softsynth.c index 96d0aca..4ccb087 100644 --- a/softsynth.c +++ b/softsynth.c @@ -170,6 +170,7 @@ static void process_buffer(struct synth_t *s, char *buf, ssize_t length) static void request_espeak_stop(void) { pthread_mutex_lock(&queue_guard); + stop_audio(); runner_must_stop = 1; pthread_cond_signal(&runner_awake); /* Wake runner, if necessary. */ while(should_run && (runner_must_stop == 1)) diff --git a/synth.c b/synth.c index e454ed4..9d77ffa 100644 --- a/synth.c +++ b/synth.c @@ -129,7 +129,6 @@ static espeak_ERROR stop_speech(void) { espeak_ERROR rc; - stop_audio(); rc = espeak_Cancel(); start_audio(&user_data); return rc; From 04d10d88ec0bb2161885bc3358a9bc6b5e06ce35 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Mon, 29 Jun 2009 17:48:16 -0500 Subject: [PATCH 063/181] more sound updates removed the user_data processing code and put the call to snd_pcm_drop in stop_audio. --- alsa.c | 32 +++++--------------------------- espeak_sound.c | 2 +- espeakup.h | 2 +- synth.c | 5 ++--- 4 files changed, 9 insertions(+), 32 deletions(-) diff --git a/alsa.c b/alsa.c index 464bffa..96261fe 100644 --- a/alsa.c +++ b/alsa.c @@ -63,42 +63,19 @@ static int minimum(int x, int y) static int alsa_callback(short *audio, int numsamples, espeak_EVENT * events) { - static int discarding_packets = 0; - static int user_data_old = 0; int samples_written = 0; int avail; int to_write; snd_pcm_state_t state; - int user_data_new; int rc = 0; lock_audio_mutex(); - user_data_new = *(int *) events->user_data; if (stop_requested) { - if(snd_pcm_drop(handle) < 0) { - fprintf(stderr, "Negative return from snd_pcm_drop!\n"); - return 1; - } - discarding_packets = 1; + unlock_audio_mutex(); + return 1; } unlock_audio_mutex(); - /* - * If discarding_packets is true, then do the following. - * Compare user_data_old and user_data_new. If they are equal, - * then espeak is still sending stale data through the callback. - * Keep on discarding it, and return 1. - * If they are different, a new stream has started. We can stop - * discarding. Just process the new data. - */ - if (discarding_packets) { - if (user_data_new == user_data_old) - return 1; /* Discard stale data. */ - else - discarding_packets = 0; - } - - user_data_old = user_data_new; snd_pcm_status(handle, status); state = snd_pcm_status_get_state(status); if (state != SND_PCM_STATE_RUNNING) @@ -199,13 +176,14 @@ void stop_audio(void) { lock_audio_mutex(); stop_requested = 1; + if(snd_pcm_drop(handle) < 0) + fprintf(stderr, "Negative return from snd_pcm_drop!\n"); unlock_audio_mutex(); } -void start_audio(int *user_data) +void start_audio(void) { lock_audio_mutex(); - *user_data = (*user_data + 1) % 100; stop_requested = 0; unlock_audio_mutex(); } diff --git a/espeak_sound.c b/espeak_sound.c index ec3f286..6101bc8 100644 --- a/espeak_sound.c +++ b/espeak_sound.c @@ -15,7 +15,7 @@ void stop_audio(void) return; } -void start_audio(int *user_data) +void start_audio(void) { return; } diff --git a/espeakup.h b/espeakup.h index 91e9cbb..7074bd1 100644 --- a/espeakup.h +++ b/espeakup.h @@ -78,7 +78,7 @@ extern void *softsynth_thread(void *arg); extern void select_audio_mode(void); extern int init_audio(unsigned int rate); extern void stop_audio(void); -extern void start_audio(int *user_data); +extern void start_audio(void); extern volatile int should_run; extern volatile int runner_must_stop; extern int self_pipe_fds[2]; diff --git a/synth.c b/synth.c index 9d77ffa..67559f6 100644 --- a/synth.c +++ b/synth.c @@ -38,7 +38,6 @@ const int rateMultiplier = 34; const int rateOffset = 84; const int volumeMultiplier = 22; -static int user_data = 0; volatile int runner_must_stop = 0; static espeak_ERROR set_frequency(struct synth_t *s, int freq, enum adjust_t adj) @@ -130,7 +129,7 @@ static espeak_ERROR stop_speech(void) espeak_ERROR rc; rc = espeak_Cancel(); - start_audio(&user_data); + start_audio(); return rc; } @@ -139,7 +138,7 @@ static espeak_ERROR speak_text(struct synth_t * s) espeak_ERROR rc; rc = espeak_Synth(s->buf, s->len + 1, 0, POS_CHARACTER, 0, 0, NULL, - &user_data); + NULL); return rc; } From 011ec271627615be44e1bacd6d269745c86028e9 Mon Sep 17 00:00:00 2001 From: Christopher Brannon Date: Mon, 29 Jun 2009 17:24:40 -0500 Subject: [PATCH 064/181] Create pipe before starting the signal handler thread. The thread can write to the pipe, so the pipe must be initialized before the thread starts. --- espeakup.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/espeakup.c b/espeakup.c index 8ab88ad..d7dce8d 100644 --- a/espeakup.c +++ b/espeakup.c @@ -103,6 +103,12 @@ int main(int argc, char **argv) } } + /* set up the pipe used to wake the espeak thread */ + if (pipe(self_pipe_fds) < 0) { + perror("Unable to create pipe"); + return 5; + } + /* create the signal processing thread here. */ err = pthread_create(&signal_thread_id, NULL, signal_thread, NULL); if (err != 0) { @@ -128,12 +134,6 @@ int main(int argc, char **argv) return 2; } - /* set up the pipe used to wake the espeak thread */ - if (pipe(self_pipe_fds) < 0) { - perror("Unable to create pipe"); - return 5; - } - /* Spawn our softsynth thread. */ err = pthread_create(&softsynth_thread_id, NULL, softsynth_thread, &s); if (err != 0) { From 31ad5f04ca691228889bd839852d8b19321c86c1 Mon Sep 17 00:00:00 2001 From: Christopher Brannon Date: Mon, 29 Jun 2009 17:54:09 -0500 Subject: [PATCH 065/181] Completely data-agnostic queue functions. The functions in queue.c no longer use static variables. We can now use them for multiple queues, if necessary. --- espeakup.c | 7 +++++++ espeakup.h | 10 +++++++--- queue.c | 51 +++++++++++++++++++++++++++++++-------------------- softsynth.c | 4 ++-- synth.c | 18 +++++++++--------- 5 files changed, 56 insertions(+), 34 deletions(-) diff --git a/espeakup.c b/espeakup.c index d7dce8d..16891a4 100644 --- a/espeakup.c +++ b/espeakup.c @@ -33,6 +33,7 @@ const char *Version = "0.71"; const char *pidPath = "/var/run/espeakup.pid"; int debug = 0; +struct queue_t *synth_queue = NULL; int self_pipe_fds[2]; volatile int should_run = 1; @@ -82,6 +83,12 @@ int main(int argc, char **argv) struct synth_t s = { .voice = "", }; + synth_queue = new_queue(); + + if (!synth_queue) { + fprintf(stderr, "Unable to allocate memory.\n"); + return 2; + } /* process command line options */ process_cli(argc, argv); diff --git a/espeakup.h b/espeakup.h index 7074bd1..3afbf54 100644 --- a/espeakup.h +++ b/espeakup.h @@ -63,12 +63,16 @@ struct synth_t { int len; }; +struct queue_t; /* An opaque type. */ + +extern struct queue_t *synth_queue; extern int debug; extern void process_cli(int argc, char **argv); -extern void queue_add(void *entry); -extern void queue_remove(void); -extern void *queue_peek(void); +extern struct queue_t *new_queue(void); +extern void queue_add(struct queue_t *q, void *entry); +extern void queue_remove(struct queue_t *q); +extern void *queue_peek(struct queue_t *q); extern void *signal_thread(void *arg); extern int initialize_espeak(struct synth_t *s); extern void *espeak_thread(void *arg); diff --git a/queue.c b/queue.c index dcce07c..c12ced9 100644 --- a/queue.c +++ b/queue.c @@ -31,48 +31,59 @@ struct queue_entry_t { struct queue_entry_t *next; }; -static struct queue_entry_t *head = NULL; -static struct queue_entry_t *tail = NULL; +struct queue_t { + struct queue_entry_t *head, *tail; +}; -void queue_add(void *data) +struct queue_t *new_queue(void) { -struct queue_entry_t *tmp; + struct queue_t *q = malloc(sizeof(struct queue_t)); + if (q != NULL) { + q->head = NULL; + q->tail = NULL; + } + return q; +} + +void queue_add(struct queue_t *q, void *data) +{ + struct queue_entry_t *tmp; assert(data); tmp = malloc(sizeof(struct queue_entry_t)); - if (! tmp) { + if (!tmp) { printf("Unable to allocate memory for queue entry.\n"); return; } tmp->data = data; tmp->next = NULL; - if (! tail) { - tail = tmp; + if (!q->tail) { + q->tail = tmp; } else { - tail->next = tmp; - tail = tail->next; + q->tail->next = tmp; + q->tail = q->tail->next; } - if (!head) - head = tmp; + if (!q->head) + q->head = tmp; } -void queue_remove(void) +void queue_remove(struct queue_t *q) { struct queue_entry_t *tmp; - if (head) { - tmp = head; - head = tmp->next; + if (q->head) { + tmp = q->head; + q->head = tmp->next; free(tmp); - if (!head) - tail = head; + if (!q->head) + q->tail = q->head; } } -void *queue_peek(void) +void *queue_peek(struct queue_t *q) { - if (head) - return head->data; + if (q->head) + return q->head->data; else return NULL; } diff --git a/softsynth.c b/softsynth.c index 4ccb087..27b466c 100644 --- a/softsynth.c +++ b/softsynth.c @@ -48,7 +48,7 @@ static void queue_add_cmd(enum command_t cmd, enum adjust_t adj, int value) entry->adjust = adj; entry->value = value; pthread_mutex_lock(&queue_guard); - queue_add((void *) entry); + queue_add(synth_queue, (void *) entry); pthread_cond_signal(&runner_awake); pthread_mutex_unlock(&queue_guard); } @@ -72,7 +72,7 @@ static void queue_add_text(char *txt, size_t length) } entry->len = length; pthread_mutex_lock(&queue_guard); - queue_add((void *) entry); + queue_add(synth_queue, (void *) entry); pthread_cond_signal(&runner_awake); pthread_mutex_unlock(&queue_guard); } diff --git a/synth.c b/synth.c index 67559f6..d34ad64 100644 --- a/synth.c +++ b/synth.c @@ -150,15 +150,15 @@ static void free_espeak_entry(struct espeak_entry_t *entry) free(entry); } -static void queue_clear() +static void synth_queue_clear() { struct espeak_entry_t *current; - current = (struct espeak_entry_t *) queue_peek(); + current = (struct espeak_entry_t *) queue_peek(synth_queue); while (current) { free_espeak_entry(current); - queue_remove(); - current = (struct espeak_entry_t *) queue_peek(); + queue_remove(synth_queue); + current = (struct espeak_entry_t *) queue_peek(synth_queue); } } @@ -167,7 +167,7 @@ static void queue_process_entry(struct synth_t *s) espeak_ERROR error; struct espeak_entry_t *current; - current = (struct espeak_entry_t *) queue_peek(); + current = (struct espeak_entry_t *) queue_peek(synth_queue); pthread_mutex_unlock(&queue_guard); if (current) { switch (current->cmd) { @@ -201,7 +201,7 @@ static void queue_process_entry(struct synth_t *s) if (error == EE_OK) { free_espeak_entry(current); pthread_mutex_lock(&queue_guard); - queue_remove(); + queue_remove(synth_queue); pthread_mutex_unlock(&queue_guard); } } @@ -263,17 +263,17 @@ void *espeak_thread(void *arg) pthread_mutex_lock(&queue_guard); while (should_run) { - while (should_run && !queue_peek() && !runner_must_stop) + while (should_run && !queue_peek(synth_queue) && !runner_must_stop) pthread_cond_wait(&runner_awake, &queue_guard); if (runner_must_stop) { - queue_clear(); + synth_queue_clear(); stop_speech(); runner_must_stop = 0; pthread_cond_signal(&stop_acknowledged); } - while (should_run && queue_peek() && !runner_must_stop) { + while (should_run && queue_peek(synth_queue) && !runner_must_stop) { queue_process_entry(s); pthread_mutex_lock(&queue_guard); } From ccb8cea91ee1537e24070dbd3cc568e6f24ddb28 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Mon, 29 Jun 2009 18:12:04 -0500 Subject: [PATCH 066/181] stop speech before clearing the queue Thanks to Kirk Reiser for pointing out that this makes the cancel response faster. --- synth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synth.c b/synth.c index d34ad64..80749ff 100644 --- a/synth.c +++ b/synth.c @@ -267,8 +267,8 @@ void *espeak_thread(void *arg) pthread_cond_wait(&runner_awake, &queue_guard); if (runner_must_stop) { - synth_queue_clear(); stop_speech(); + synth_queue_clear(); runner_must_stop = 0; pthread_cond_signal(&stop_acknowledged); } From 40479540b4c8dd6a876b084bce0e6c806033da06 Mon Sep 17 00:00:00 2001 From: Christopher Brannon Date: Mon, 29 Jun 2009 18:33:40 -0500 Subject: [PATCH 067/181] Fix a memory leak. If we fail to add entries to the queue in queue_add_cmd or queue_add_text, properly free the entry. --- espeakup.h | 2 +- queue.c | 5 +++-- softsynth.c | 17 ++++++++++++++--- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/espeakup.h b/espeakup.h index 3afbf54..604f240 100644 --- a/espeakup.h +++ b/espeakup.h @@ -70,7 +70,7 @@ extern int debug; extern void process_cli(int argc, char **argv); extern struct queue_t *new_queue(void); -extern void queue_add(struct queue_t *q, void *entry); +extern int queue_add(struct queue_t *q, void *entry); extern void queue_remove(struct queue_t *q); extern void *queue_peek(struct queue_t *q); extern void *signal_thread(void *arg); diff --git a/queue.c b/queue.c index c12ced9..0db6ecf 100644 --- a/queue.c +++ b/queue.c @@ -45,7 +45,7 @@ struct queue_t *new_queue(void) return q; } -void queue_add(struct queue_t *q, void *data) +int queue_add(struct queue_t *q, void *data) { struct queue_entry_t *tmp; @@ -53,7 +53,7 @@ void queue_add(struct queue_t *q, void *data) tmp = malloc(sizeof(struct queue_entry_t)); if (!tmp) { printf("Unable to allocate memory for queue entry.\n"); - return; + return 0; } tmp->data = data; tmp->next = NULL; @@ -65,6 +65,7 @@ void queue_add(struct queue_t *q, void *data) } if (!q->head) q->head = tmp; + return 1; } void queue_remove(struct queue_t *q) diff --git a/softsynth.c b/softsynth.c index 27b466c..2c19023 100644 --- a/softsynth.c +++ b/softsynth.c @@ -38,6 +38,7 @@ static int softFD = 0; static void queue_add_cmd(enum command_t cmd, enum adjust_t adj, int value) { struct espeak_entry_t *entry; + int added = 0; entry = malloc(sizeof(struct espeak_entry_t)); if (!entry) { @@ -48,7 +49,10 @@ static void queue_add_cmd(enum command_t cmd, enum adjust_t adj, int value) entry->adjust = adj; entry->value = value; pthread_mutex_lock(&queue_guard); - queue_add(synth_queue, (void *) entry); + added = queue_add(synth_queue, (void *) entry); + if (!added) + free(entry); + else pthread_cond_signal(&runner_awake); pthread_mutex_unlock(&queue_guard); } @@ -56,6 +60,7 @@ static void queue_add_cmd(enum command_t cmd, enum adjust_t adj, int value) static void queue_add_text(char *txt, size_t length) { struct espeak_entry_t *entry; + int added = 0; entry = malloc(sizeof(struct espeak_entry_t)); if (!entry) { @@ -72,8 +77,14 @@ static void queue_add_text(char *txt, size_t length) } entry->len = length; pthread_mutex_lock(&queue_guard); - queue_add(synth_queue, (void *) entry); - pthread_cond_signal(&runner_awake); + added = queue_add(synth_queue, (void *) entry); + if (!added) { + free(entry->buf); + free(entry); + } else { + pthread_cond_signal(&runner_awake); + } + pthread_mutex_unlock(&queue_guard); } From 0a9a8cce9bcb0310903aaffafd2dbdbe5a6458c4 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Tue, 30 Jun 2009 08:15:27 -0500 Subject: [PATCH 068/181] small style changes --- queue.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/queue.c b/queue.c index 0db6ecf..79c1ea1 100644 --- a/queue.c +++ b/queue.c @@ -32,13 +32,14 @@ struct queue_entry_t { }; struct queue_t { - struct queue_entry_t *head, *tail; + struct queue_entry_t *head; + struct queue_entry_t *tail; }; struct queue_t *new_queue(void) { struct queue_t *q = malloc(sizeof(struct queue_t)); - if (q != NULL) { + if (q) { q->head = NULL; q->tail = NULL; } From dc056e6c773e203af74d290393819b7fdc4043e0 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Tue, 30 Jun 2009 13:08:07 -0500 Subject: [PATCH 069/181] broke the queue definitions out into their own header file --- Makefile | 12 ++++++------ espeakup.h | 8 ++------ queue.h | 30 ++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 12 deletions(-) create mode 100644 queue.h diff --git a/Makefile b/Makefile index f784aac..ab01acc 100644 --- a/Makefile +++ b/Makefile @@ -44,14 +44,14 @@ espeakup: $(OBJS) cli.o: cli.c espeakup.h -espeakup.o: espeakup.c espeakup.h +espeakup.o: espeakup.c espeakup.h queue.h -queue.o: queue.c espeakup.h +queue.o: queue.c queue.h -softsynth.o: softsynth.c espeakup.h +softsynth.o: softsynth.c espeakup.h queue.h -synth.o: synth.c espeakup.h +synth.o: synth.c espeakup.h queue.h -alsa.o: alsa.c espeakup.h +alsa.o: alsa.c espeakup.h -espeak_sound.o: espeak_sound.c espeakup.h +espeak_sound.o: espeak_sound.c espeakup.h diff --git a/espeakup.h b/espeakup.h index 604f240..b0844a5 100644 --- a/espeakup.h +++ b/espeakup.h @@ -26,6 +26,8 @@ #include +#include "queue.h" + enum command_t { CMD_SET_FREQUENCY, CMD_SET_PITCH, @@ -63,16 +65,10 @@ struct synth_t { int len; }; -struct queue_t; /* An opaque type. */ - extern struct queue_t *synth_queue; extern int debug; extern void process_cli(int argc, char **argv); -extern struct queue_t *new_queue(void); -extern int queue_add(struct queue_t *q, void *entry); -extern void queue_remove(struct queue_t *q); -extern void *queue_peek(struct queue_t *q); extern void *signal_thread(void *arg); extern int initialize_espeak(struct synth_t *s); extern void *espeak_thread(void *arg); diff --git a/queue.h b/queue.h new file mode 100644 index 0000000..e1cf3ee --- /dev/null +++ b/queue.h @@ -0,0 +1,30 @@ +/* + * espeakup - interface which allows speakup to use espeak + * + * Copyright (C) 2008 William Hubbs + * + * This program 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. + * + * This program 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 this program. If not, see . + */ + +#ifndef __QUEUE_H +#define __QUEUE_H + +struct queue_t; /* An opaque type. */ + +extern struct queue_t *new_queue(void); +extern int queue_add(struct queue_t *q, void *entry); +extern void queue_remove(struct queue_t *q); +extern void *queue_peek(struct queue_t *q); + +#endif From 101e14901e0517f6f09024dc8dc1f47dc682227a Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Tue, 30 Jun 2009 13:21:52 -0500 Subject: [PATCH 070/181] removed white space in the makefile --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index ab01acc..1665d87 100644 --- a/Makefile +++ b/Makefile @@ -52,6 +52,6 @@ softsynth.o: softsynth.c espeakup.h queue.h synth.o: synth.c espeakup.h queue.h -alsa.o: alsa.c espeakup.h +alsa.o: alsa.c espeakup.h -espeak_sound.o: espeak_sound.c espeakup.h +espeak_sound.o: espeak_sound.c espeakup.h From 82490a98d253d5201f93f309289346fff5169abc Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Tue, 30 Jun 2009 15:54:52 -0500 Subject: [PATCH 071/181] call snd_pcm_prepare after snd_pcm_drop in stop_audio --- alsa.c | 1 + 1 file changed, 1 insertion(+) diff --git a/alsa.c b/alsa.c index 96261fe..adf7039 100644 --- a/alsa.c +++ b/alsa.c @@ -178,6 +178,7 @@ void stop_audio(void) stop_requested = 1; if(snd_pcm_drop(handle) < 0) fprintf(stderr, "Negative return from snd_pcm_drop!\n"); + snd_pcm_prepare(handle); unlock_audio_mutex(); } From 014d27b7aa218db968ab19b2b493fe95406b4b8b Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Tue, 30 Jun 2009 19:15:44 -0500 Subject: [PATCH 072/181] removed some unlock_audio_mutex() calls --- alsa.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/alsa.c b/alsa.c index adf7039..307f91a 100644 --- a/alsa.c +++ b/alsa.c @@ -66,7 +66,6 @@ static int alsa_callback(short *audio, int numsamples, espeak_EVENT * events) int samples_written = 0; int avail; int to_write; - snd_pcm_state_t state; int rc = 0; lock_audio_mutex(); @@ -74,21 +73,12 @@ static int alsa_callback(short *audio, int numsamples, espeak_EVENT * events) unlock_audio_mutex(); return 1; } - unlock_audio_mutex(); - snd_pcm_status(handle, status); - state = snd_pcm_status_get_state(status); - if (state != SND_PCM_STATE_RUNNING) - snd_pcm_prepare(handle); - - lock_audio_mutex(); while (numsamples > 0 && ! stop_requested) { - unlock_audio_mutex(); avail = snd_pcm_avail_update(handle); if (avail <= 0) { if (avail < 0) snd_pcm_prepare(handle); - lock_audio_mutex(); continue; } to_write = minimum(avail, numsamples); @@ -99,7 +89,6 @@ static int alsa_callback(short *audio, int numsamples, espeak_EVENT * events) numsamples -= samples_written; audio += samples_written; } - lock_audio_mutex(); } rc = stop_requested; unlock_audio_mutex(); From 739e074072100dd420b10eb1d8b8d55451b9bdea Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Tue, 30 Jun 2009 20:15:20 -0500 Subject: [PATCH 073/181] reworked the queue_remove function Now, when queue_remove is called, it returns the pointer to the data of the first entry in the queue and removes the entry. --- queue.c | 5 +++- queue.h | 2 +- synth.c | 80 ++++++++++++++++++++++++++++----------------------------- 3 files changed, 44 insertions(+), 43 deletions(-) diff --git a/queue.c b/queue.c index 79c1ea1..e1827da 100644 --- a/queue.c +++ b/queue.c @@ -69,17 +69,20 @@ int queue_add(struct queue_t *q, void *data) return 1; } -void queue_remove(struct queue_t *q) +void *queue_remove(struct queue_t *q) { + void *data = NULL; struct queue_entry_t *tmp; if (q->head) { tmp = q->head; + data = tmp->data; q->head = tmp->next; free(tmp); if (!q->head) q->tail = q->head; } + return data; } void *queue_peek(struct queue_t *q) diff --git a/queue.h b/queue.h index e1cf3ee..f572c29 100644 --- a/queue.h +++ b/queue.h @@ -24,7 +24,7 @@ struct queue_t; /* An opaque type. */ extern struct queue_t *new_queue(void); extern int queue_add(struct queue_t *q, void *entry); -extern void queue_remove(struct queue_t *q); +extern void *queue_remove(struct queue_t *q); extern void *queue_peek(struct queue_t *q); #endif diff --git a/synth.c b/synth.c index 80749ff..6b4589a 100644 --- a/synth.c +++ b/synth.c @@ -154,56 +154,54 @@ static void synth_queue_clear() { struct espeak_entry_t *current; - current = (struct espeak_entry_t *) queue_peek(synth_queue); - while (current) { + while (queue_peek(synth_queue)) { + current = (struct espeak_entry_t *) queue_remove(synth_queue); free_espeak_entry(current); - queue_remove(synth_queue); - current = (struct espeak_entry_t *) queue_peek(synth_queue); } } static void queue_process_entry(struct synth_t *s) { espeak_ERROR error; - struct espeak_entry_t *current; + static struct espeak_entry_t *current = NULL; - current = (struct espeak_entry_t *) queue_peek(synth_queue); - pthread_mutex_unlock(&queue_guard); - if (current) { - switch (current->cmd) { - case CMD_SET_FREQUENCY: - error = set_frequency(s, current->value, current->adjust); - break; - case CMD_SET_PITCH: - error = set_pitch(s, current->value, current->adjust); - break; - case CMD_SET_PUNCTUATION: - error = set_punctuation(s, current->value, current->adjust); - break; - case CMD_SET_RATE: - error = set_rate(s, current->value, current->adjust); - break; - case CMD_SET_VOICE: - error = EE_OK; - break; - case CMD_SET_VOLUME: - error = set_volume(s, current->value, current->adjust); - break; - case CMD_SPEAK_TEXT: - s->buf = current->buf; - s->len = current->len; - error = speak_text(s); - break; - default: - break; - } - - if (error == EE_OK) { + if (current != queue_peek(synth_queue)) { + if (current) free_espeak_entry(current); - pthread_mutex_lock(&queue_guard); - queue_remove(synth_queue); - pthread_mutex_unlock(&queue_guard); - } + current = (struct espeak_entry_t *) queue_remove(synth_queue); + } + pthread_mutex_unlock(&queue_guard); + switch (current->cmd) { + case CMD_SET_FREQUENCY: + error = set_frequency(s, current->value, current->adjust); + break; + case CMD_SET_PITCH: + error = set_pitch(s, current->value, current->adjust); + break; + case CMD_SET_PUNCTUATION: + error = set_punctuation(s, current->value, current->adjust); + break; + case CMD_SET_RATE: + error = set_rate(s, current->value, current->adjust); + break; + case CMD_SET_VOICE: + error = EE_OK; + break; + case CMD_SET_VOLUME: + error = set_volume(s, current->value, current->adjust); + break; + case CMD_SPEAK_TEXT: + s->buf = current->buf; + s->len = current->len; + error = speak_text(s); + break; + default: + break; + } + + if (error == EE_OK) { + free_espeak_entry(current); + current = NULL; } } From 4de82bf24cff9e5a82a2645f30af0dbfae6ded05 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Tue, 30 Jun 2009 21:32:52 -0500 Subject: [PATCH 074/181] added a couple of #defines to the alsa code --- alsa.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/alsa.c b/alsa.c index 307f91a..9885319 100644 --- a/alsa.c +++ b/alsa.c @@ -25,8 +25,13 @@ #include #include #include + #define ALSA_PCM_NEW_HW_PARAMS_API +#define ALSA_PCM_NEW_SW_PARAMS_API #include +#undef ALSA_PCM_NEW_HW_PARAMS_API +#undef ALSA_PCM_NEW_SW_PARAMS_API + #include "espeakup.h" static pthread_mutex_t audio_mutex = PTHREAD_MUTEX_INITIALIZER; From 32d848cb76de9853564d7e2ea37725c1f9af1ae4 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Wed, 1 Jul 2009 12:22:14 -0500 Subject: [PATCH 075/181] make callback honor should_run The callback should return and abort synthesis if should_run is 0. This fixes slow shutdown times in alsa mode. --- alsa.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/alsa.c b/alsa.c index 9885319..b15489c 100644 --- a/alsa.c +++ b/alsa.c @@ -74,12 +74,12 @@ static int alsa_callback(short *audio, int numsamples, espeak_EVENT * events) int rc = 0; lock_audio_mutex(); - if (stop_requested) { + if (stop_requested || !should_run) { unlock_audio_mutex(); return 1; } - while (numsamples > 0 && ! stop_requested) { + while (numsamples > 0 && (! stop_requested && should_run)) { avail = snd_pcm_avail_update(handle); if (avail <= 0) { if (avail < 0) @@ -95,7 +95,7 @@ static int alsa_callback(short *audio, int numsamples, espeak_EVENT * events) audio += samples_written; } } - rc = stop_requested; + rc = (stop_requested || !should_run); unlock_audio_mutex(); return rc; } From cc7e77eb9db904f27b9de12f4b25b17c2f6d5b02 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Wed, 1 Jul 2009 13:01:41 -0500 Subject: [PATCH 076/181] move stop_audio call to synth thread Since there is no reason currently for the softsynth thread to do this, it makes better sense to have the synth thread control all interaction with espeak. --- softsynth.c | 1 - synth.c | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/softsynth.c b/softsynth.c index 2c19023..96696a3 100644 --- a/softsynth.c +++ b/softsynth.c @@ -181,7 +181,6 @@ static void process_buffer(struct synth_t *s, char *buf, ssize_t length) static void request_espeak_stop(void) { pthread_mutex_lock(&queue_guard); - stop_audio(); runner_must_stop = 1; pthread_cond_signal(&runner_awake); /* Wake runner, if necessary. */ while(should_run && (runner_must_stop == 1)) diff --git a/synth.c b/synth.c index 6b4589a..d363d23 100644 --- a/synth.c +++ b/synth.c @@ -128,6 +128,7 @@ static espeak_ERROR stop_speech(void) { espeak_ERROR rc; + stop_audio(); rc = espeak_Cancel(); start_audio(); return rc; From 18ebab3247934c71320abed559021fe6eebab530 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Wed, 1 Jul 2009 19:04:01 -0500 Subject: [PATCH 077/181] indentation fixes --- alsa.c | 7 ++++--- espeakup.c | 2 +- queue.h | 2 +- signal.c | 6 +++--- softsynth.c | 6 +++--- synth.c | 20 ++++++++++++-------- 6 files changed, 24 insertions(+), 19 deletions(-) diff --git a/alsa.c b/alsa.c index b15489c..a45b4f9 100644 --- a/alsa.c +++ b/alsa.c @@ -66,7 +66,8 @@ static int minimum(int x, int y) return y; } -static int alsa_callback(short *audio, int numsamples, espeak_EVENT * events) +static int alsa_callback(short *audio, int numsamples, + espeak_EVENT * events) { int samples_written = 0; int avail; @@ -79,7 +80,7 @@ static int alsa_callback(short *audio, int numsamples, espeak_EVENT * events) return 1; } - while (numsamples > 0 && (! stop_requested && should_run)) { + while (numsamples > 0 && (!stop_requested && should_run)) { avail = snd_pcm_avail_update(handle); if (avail <= 0) { if (avail < 0) @@ -170,7 +171,7 @@ void stop_audio(void) { lock_audio_mutex(); stop_requested = 1; - if(snd_pcm_drop(handle) < 0) + if (snd_pcm_drop(handle) < 0) fprintf(stderr, "Negative return from snd_pcm_drop!\n"); snd_pcm_prepare(handle); unlock_audio_mutex(); diff --git a/espeakup.c b/espeakup.c index 16891a4..b749bcb 100644 --- a/espeakup.c +++ b/espeakup.c @@ -160,7 +160,7 @@ int main(int argc, char **argv) espeak_Terminate(); close_softsynth(); - if ( ! debug) + if (!debug) unlink(pidPath); return 0; } diff --git a/queue.h b/queue.h index f572c29..249f3ba 100644 --- a/queue.h +++ b/queue.h @@ -20,7 +20,7 @@ #ifndef __QUEUE_H #define __QUEUE_H -struct queue_t; /* An opaque type. */ +struct queue_t; /* An opaque type. */ extern struct queue_t *new_queue(void); extern int queue_add(struct queue_t *q, void *entry); diff --git a/signal.c b/signal.c index 5a49183..5996986 100644 --- a/signal.c +++ b/signal.c @@ -37,8 +37,8 @@ static void dummy_handler(int sig) void *signal_thread(void *arg) { struct sigaction temp; - sigset_t sigset; - int sig; + sigset_t sigset; + int sig; /* install dummy handlers for the signals we want to process */ temp.sa_handler = dummy_handler; @@ -47,7 +47,7 @@ void *signal_thread(void *arg) sigaction(SIGTERM, &temp, NULL); pthread_mutex_lock(&queue_guard); - while(should_run) { + while (should_run) { pthread_mutex_unlock(&queue_guard); sigfillset(&sigset); sigwait(&sigset, &sig); diff --git a/softsynth.c b/softsynth.c index 96696a3..d1f2b34 100644 --- a/softsynth.c +++ b/softsynth.c @@ -53,7 +53,7 @@ static void queue_add_cmd(enum command_t cmd, enum adjust_t adj, int value) if (!added) free(entry); else - pthread_cond_signal(&runner_awake); + pthread_cond_signal(&runner_awake); pthread_mutex_unlock(&queue_guard); } @@ -183,8 +183,8 @@ static void request_espeak_stop(void) pthread_mutex_lock(&queue_guard); runner_must_stop = 1; pthread_cond_signal(&runner_awake); /* Wake runner, if necessary. */ - while(should_run && (runner_must_stop == 1)) - pthread_cond_wait(&stop_acknowledged, &queue_guard); /* wait for acknowledgement. */ + while (should_run && (runner_must_stop == 1)) + pthread_cond_wait(&stop_acknowledged, &queue_guard); /* wait for acknowledgement. */ pthread_mutex_unlock(&queue_guard); } diff --git a/synth.c b/synth.c index d363d23..734f272 100644 --- a/synth.c +++ b/synth.c @@ -40,7 +40,8 @@ const int volumeMultiplier = 22; volatile int runner_must_stop = 0; -static espeak_ERROR set_frequency(struct synth_t *s, int freq, enum adjust_t adj) +static espeak_ERROR set_frequency(struct synth_t *s, int freq, + enum adjust_t adj) { espeak_ERROR rc; @@ -54,7 +55,8 @@ static espeak_ERROR set_frequency(struct synth_t *s, int freq, enum adjust_t adj return rc; } -static espeak_ERROR set_pitch(struct synth_t * s, int pitch, enum adjust_t adj) +static espeak_ERROR set_pitch(struct synth_t *s, int pitch, + enum adjust_t adj) { espeak_ERROR rc; @@ -68,8 +70,8 @@ static espeak_ERROR set_pitch(struct synth_t * s, int pitch, enum adjust_t adj) return rc; } -static espeak_ERROR set_punctuation(struct synth_t * s, int punct, - enum adjust_t adj) +static espeak_ERROR set_punctuation(struct synth_t *s, int punct, + enum adjust_t adj) { espeak_ERROR rc; @@ -83,7 +85,8 @@ static espeak_ERROR set_punctuation(struct synth_t * s, int punct, return rc; } -static espeak_ERROR set_rate(struct synth_t * s, int rate, enum adjust_t adj) +static espeak_ERROR set_rate(struct synth_t *s, int rate, + enum adjust_t adj) { espeak_ERROR rc; @@ -98,7 +101,7 @@ static espeak_ERROR set_rate(struct synth_t * s, int rate, enum adjust_t adj) return rc; } -static espeak_ERROR set_voice(struct synth_t * s, char *voice) +static espeak_ERROR set_voice(struct synth_t *s, char *voice) { espeak_ERROR rc; @@ -108,7 +111,8 @@ static espeak_ERROR set_voice(struct synth_t * s, char *voice) return rc; } -static espeak_ERROR set_volume(struct synth_t * s, int vol, enum adjust_t adj) +static espeak_ERROR set_volume(struct synth_t *s, int vol, + enum adjust_t adj) { espeak_ERROR rc; @@ -134,7 +138,7 @@ static espeak_ERROR stop_speech(void) return rc; } -static espeak_ERROR speak_text(struct synth_t * s) +static espeak_ERROR speak_text(struct synth_t *s) { espeak_ERROR rc; From ac9e12414b2f4a1b38f8dabdaf7eb5ae33276008 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Wed, 1 Jul 2009 20:16:29 -0500 Subject: [PATCH 078/181] made stop_requested a global variable The two variables, stop_requested and runner_must_stop were performing the same function, so I am using one variable, stop_requested for this function. --- alsa.c | 9 --------- espeak_sound.c | 5 ----- espeakup.h | 3 +-- softsynth.c | 4 ++-- synth.c | 11 +++++------ 5 files changed, 8 insertions(+), 24 deletions(-) diff --git a/alsa.c b/alsa.c index a45b4f9..adc2ceb 100644 --- a/alsa.c +++ b/alsa.c @@ -35,7 +35,6 @@ #include "espeakup.h" static pthread_mutex_t audio_mutex = PTHREAD_MUTEX_INITIALIZER; -static volatile int stop_requested = 0; static snd_pcm_t *handle; static snd_pcm_hw_params_t *params; @@ -170,16 +169,8 @@ int init_audio(unsigned int rate) void stop_audio(void) { lock_audio_mutex(); - stop_requested = 1; if (snd_pcm_drop(handle) < 0) fprintf(stderr, "Negative return from snd_pcm_drop!\n"); snd_pcm_prepare(handle); unlock_audio_mutex(); } - -void start_audio(void) -{ - lock_audio_mutex(); - stop_requested = 0; - unlock_audio_mutex(); -} diff --git a/espeak_sound.c b/espeak_sound.c index 6101bc8..6e24b8c 100644 --- a/espeak_sound.c +++ b/espeak_sound.c @@ -14,8 +14,3 @@ void stop_audio(void) { return; } - -void start_audio(void) -{ - return; -} diff --git a/espeakup.h b/espeakup.h index b0844a5..3580180 100644 --- a/espeakup.h +++ b/espeakup.h @@ -78,9 +78,8 @@ extern void *softsynth_thread(void *arg); extern void select_audio_mode(void); extern int init_audio(unsigned int rate); extern void stop_audio(void); -extern void start_audio(void); extern volatile int should_run; -extern volatile int runner_must_stop; +extern volatile int stop_requested; extern int self_pipe_fds[2]; #define PIPE_READ_FD (self_pipe_fds[0]) #define PIPE_WRITE_FD (self_pipe_fds[1]) diff --git a/softsynth.c b/softsynth.c index d1f2b34..9747963 100644 --- a/softsynth.c +++ b/softsynth.c @@ -181,9 +181,9 @@ static void process_buffer(struct synth_t *s, char *buf, ssize_t length) static void request_espeak_stop(void) { pthread_mutex_lock(&queue_guard); - runner_must_stop = 1; + stop_requested = 1; pthread_cond_signal(&runner_awake); /* Wake runner, if necessary. */ - while (should_run && (runner_must_stop == 1)) + while (should_run && stop_requested) pthread_cond_wait(&stop_acknowledged, &queue_guard); /* wait for acknowledgement. */ pthread_mutex_unlock(&queue_guard); } diff --git a/synth.c b/synth.c index 734f272..4a987b1 100644 --- a/synth.c +++ b/synth.c @@ -38,7 +38,7 @@ const int rateMultiplier = 34; const int rateOffset = 84; const int volumeMultiplier = 22; -volatile int runner_must_stop = 0; +volatile int stop_requested = 0; static espeak_ERROR set_frequency(struct synth_t *s, int freq, enum adjust_t adj) @@ -134,7 +134,6 @@ static espeak_ERROR stop_speech(void) stop_audio(); rc = espeak_Cancel(); - start_audio(); return rc; } @@ -266,17 +265,17 @@ void *espeak_thread(void *arg) pthread_mutex_lock(&queue_guard); while (should_run) { - while (should_run && !queue_peek(synth_queue) && !runner_must_stop) + while (should_run && !queue_peek(synth_queue) && !stop_requested) pthread_cond_wait(&runner_awake, &queue_guard); - if (runner_must_stop) { + if (stop_requested) { stop_speech(); synth_queue_clear(); - runner_must_stop = 0; + stop_requested = 0; pthread_cond_signal(&stop_acknowledged); } - while (should_run && queue_peek(synth_queue) && !runner_must_stop) { + while (should_run && queue_peek(synth_queue) && !stop_requested) { queue_process_entry(s); pthread_mutex_lock(&queue_guard); } From 57547e8efa0dcf9f7f1750d7e8472f7207d20329 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Wed, 19 Aug 2009 15:14:20 -0500 Subject: [PATCH 079/181] renamed synth.c to espeak.c The name was changed because it describes the function of this code more accurately. --- Makefile | 8 ++++---- synth.c => espeak.c | 0 2 files changed, 4 insertions(+), 4 deletions(-) rename synth.c => espeak.c (100%) diff --git a/Makefile b/Makefile index 1665d87..2e70b2c 100644 --- a/Makefile +++ b/Makefile @@ -11,11 +11,11 @@ ALSA_SRCS = alsa.c ESPEAK_SRCS = espeak_sound.c SRCS = \ cli.c \ + espeak.c \ espeakup.c \ queue.c \ signal.c \ - softsynth.c \ - synth.c + softsynth.c ifeq ($(AUDIO),alsa) SRCS += $(ALSA_SRCS) @@ -44,14 +44,14 @@ espeakup: $(OBJS) cli.o: cli.c espeakup.h +espeak.o: espeak.c espeakup.h queue.h + espeakup.o: espeakup.c espeakup.h queue.h queue.o: queue.c queue.h softsynth.o: softsynth.c espeakup.h queue.h -synth.o: synth.c espeakup.h queue.h - alsa.o: alsa.c espeakup.h espeak_sound.o: espeak_sound.c espeakup.h diff --git a/synth.c b/espeak.c similarity index 100% rename from synth.c rename to espeak.c From e4e3f0979e1820712a6a88bfcf60da34a8a747f0 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Fri, 21 Aug 2009 13:03:02 -0500 Subject: [PATCH 080/181] the status handle should be static --- alsa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alsa.c b/alsa.c index adc2ceb..e9378b0 100644 --- a/alsa.c +++ b/alsa.c @@ -38,7 +38,7 @@ static pthread_mutex_t audio_mutex = PTHREAD_MUTEX_INITIALIZER; static snd_pcm_t *handle; static snd_pcm_hw_params_t *params; -snd_pcm_status_t *status; +static snd_pcm_status_t *status; static int dir = 0; static void lock_audio_mutex(void) From 654fc810fe981907d3f17d212ae51d9d6124fa42 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Tue, 25 Aug 2009 18:22:40 -0500 Subject: [PATCH 081/181] default prefix to /usr/local Without packaging, we should be installing espeakup in /usr/local. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 2e70b2c..da34c2b 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ CFLAGS += -Wall LDLIBS = -lespeak -PREFIX = /usr +PREFIX = /usr/local MANDIR = $(PREFIX)/share/man/man8 BINDIR = $(PREFIX)/bin From 48fa03faf5529a4072ae50fe9ff983333bc6fca0 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Sat, 5 Sep 2009 11:32:22 -0500 Subject: [PATCH 082/181] renamed espeak_sound.c to portaudio.c This better describes the sound system that espeak uses natively. --- Makefile | 6 +++--- espeak_sound.c => portaudio.c | 0 2 files changed, 3 insertions(+), 3 deletions(-) rename espeak_sound.c => portaudio.c (100%) diff --git a/Makefile b/Makefile index da34c2b..6687bdc 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ BINDIR = $(PREFIX)/bin INSTALL = install ALSA_SRCS = alsa.c -ESPEAK_SRCS = espeak_sound.c +PORTAUDIO_SRCS = portaudio.c SRCS = \ cli.c \ espeak.c \ @@ -21,7 +21,7 @@ ifeq ($(AUDIO),alsa) SRCS += $(ALSA_SRCS) LDLIBS += -lasound else -SRCS += $(ESPEAK_SRCS) +SRCS += $(PORTAUDIO_SRCS) endif OBJS = $(SRCS:.c=.o) @@ -54,4 +54,4 @@ softsynth.o: softsynth.c espeakup.h queue.h alsa.o: alsa.c espeakup.h -espeak_sound.o: espeak_sound.c espeakup.h +portaudio.o: portaudio.c espeakup.h diff --git a/espeak_sound.c b/portaudio.c similarity index 100% rename from espeak_sound.c rename to portaudio.c From 11cc053d822d563b9c040ce50341f8c8cd8b4f86 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Mon, 7 Sep 2009 16:57:00 -0500 Subject: [PATCH 083/181] reworked the makefile This version of the makefile should be more compatible with allowing users to pass in cflags. --- Makefile | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 6687bdc..32c4293 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,9 @@ -CFLAGS += -Wall -LDLIBS = -lespeak +INSTALL = install PREFIX = /usr/local MANDIR = $(PREFIX)/share/man/man8 BINDIR = $(PREFIX)/bin -INSTALL = install - ALSA_SRCS = alsa.c PORTAUDIO_SRCS = portaudio.c SRCS = \ @@ -19,13 +16,15 @@ SRCS = \ ifeq ($(AUDIO),alsa) SRCS += $(ALSA_SRCS) -LDLIBS += -lasound +SOUNDLIB = -lasound else SRCS += $(PORTAUDIO_SRCS) endif OBJS = $(SRCS:.c=.o) +LDLIBS = -lespeak $(SOUNDLIB) + all: espeakup install: espeakup @@ -42,16 +41,20 @@ distclean: clean espeakup: $(OBJS) +%.o: %.c + $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -Wall -c $< + +alsa.o: alsa.c espeakup.h + cli.o: cli.c espeakup.h espeak.o: espeak.c espeakup.h queue.h espeakup.o: espeakup.c espeakup.h queue.h +portaudio.o: portaudio.c espeakup.h + queue.o: queue.c queue.h softsynth.o: softsynth.c espeakup.h queue.h -alsa.o: alsa.c espeakup.h - -portaudio.o: portaudio.c espeakup.h From e66311bb992122ca4797eab1d2a79b1619c71b9b Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Wed, 23 Sep 2009 15:44:51 -0500 Subject: [PATCH 084/181] added automatic dependency tracking to the Makefile --- .gitignore | 1 + Makefile | 33 +++++++++++---------------------- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index 49299b3..aeb1414 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ espeakup +*.d *.o diff --git a/Makefile b/Makefile index 32c4293..3ae9301 100644 --- a/Makefile +++ b/Makefile @@ -4,9 +4,14 @@ PREFIX = /usr/local MANDIR = $(PREFIX)/share/man/man8 BINDIR = $(PREFIX)/bin -ALSA_SRCS = alsa.c -PORTAUDIO_SRCS = portaudio.c -SRCS = \ +ifndef AUDIO + AUDIO=portaudio +endif + +alsa_SRCS = alsa.c +portaudio_SRCS = portaudio.c + +SRCS = $($(AUDIO)_SRCS) \ cli.c \ espeak.c \ espeakup.c \ @@ -15,10 +20,7 @@ SRCS = \ softsynth.c ifeq ($(AUDIO),alsa) -SRCS += $(ALSA_SRCS) SOUNDLIB = -lasound -else -SRCS += $(PORTAUDIO_SRCS) endif OBJS = $(SRCS:.c=.o) @@ -34,7 +36,7 @@ install: espeakup $(INSTALL) -m 0644 espeakup.8 $(DESTDIR)$(MANDIR) clean: - $(RM) *.o + $(RM) *.d *.o distclean: clean $(RM) espeakup @@ -42,19 +44,6 @@ distclean: clean espeakup: $(OBJS) %.o: %.c - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -Wall -c $< - -alsa.o: alsa.c espeakup.h - -cli.o: cli.c espeakup.h - -espeak.o: espeak.c espeakup.h queue.h - -espeakup.o: espeakup.c espeakup.h queue.h - -portaudio.o: portaudio.c espeakup.h - -queue.o: queue.c queue.h - -softsynth.o: softsynth.c espeakup.h queue.h + $(COMPILE.c) -MMD -Wall $(OUTPUT_OPTION) $< +-include $(SRCS:.c=.d) From ffe397fb911b0de8a14cacfc69bf9e683c9ef402 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Thu, 1 Oct 2009 14:15:43 -0500 Subject: [PATCH 085/181] removed the minimum function This function really wasn't needed. I also attempted to make the callback functionn more like the test code in the alsa library git repository. --- alsa.c | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/alsa.c b/alsa.c index e9378b0..c7f7d79 100644 --- a/alsa.c +++ b/alsa.c @@ -57,20 +57,10 @@ static int sound_error(int err, const char *msg) return err; } -static int minimum(int x, int y) -{ - if (x <= y) - return x; - else - return y; -} - static int alsa_callback(short *audio, int numsamples, espeak_EVENT * events) { - int samples_written = 0; - int avail; - int to_write; + int written = 0; int rc = 0; lock_audio_mutex(); @@ -80,20 +70,17 @@ static int alsa_callback(short *audio, int numsamples, } while (numsamples > 0 && (!stop_requested && should_run)) { - avail = snd_pcm_avail_update(handle); - if (avail <= 0) { - if (avail < 0) - snd_pcm_prepare(handle); - continue; - } - to_write = minimum(avail, numsamples); - samples_written = snd_pcm_writei(handle, audio, to_write); - if (samples_written < 0) { - snd_pcm_prepare(handle); - } else { - numsamples -= samples_written; - audio += samples_written; + written = snd_pcm_writei(handle, audio, numsamples); + if (written < 0) + written = snd_pcm_recover(handle, written, 0); + if (written < 0) { + fprintf(stderr, "snd_pcm_writei failed: %s\n", snd_strerror(written)); + break; } + if (written > 0 && written < numsamples) + printf("Short write (expected %i, wrote %i)\n", numsamples, written); + numsamples -= written; + audio += written; } rc = (stop_requested || !should_run); unlock_audio_mutex(); From 311b6911959263a81f4dd74b44ad93af53a981b1 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Wed, 7 Oct 2009 15:55:46 -0500 Subject: [PATCH 086/181] fix makefile to not define variables if they are already defined --- Makefile | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 3ae9301..7a22e47 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,10 @@ -INSTALL = install +INSTALL ?= install -PREFIX = /usr/local -MANDIR = $(PREFIX)/share/man/man8 -BINDIR = $(PREFIX)/bin +PREFIX ?= /usr/local +MANDIR ?= $(PREFIX)/share/man/man8 +BINDIR ?= $(PREFIX)/bin -ifndef AUDIO - AUDIO=portaudio -endif +AUDIO ?= portaudio alsa_SRCS = alsa.c portaudio_SRCS = portaudio.c From 486fe27f47d12a0482060aac4fc6c1568fab0613 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Wed, 7 Oct 2009 15:59:12 -0500 Subject: [PATCH 087/181] removed permission settings from makefile --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 7a22e47..367eaa7 100644 --- a/Makefile +++ b/Makefile @@ -29,9 +29,9 @@ all: espeakup install: espeakup $(INSTALL) -d $(DESTDIR)$(BINDIR) - $(INSTALL) -m 0755 $< $(DESTDIR)$(BINDIR) $(INSTALL) -d $(DESTDIR)$(MANDIR) - $(INSTALL) -m 0644 espeakup.8 $(DESTDIR)$(MANDIR) + $(INSTALL) $< $(DESTDIR)$(BINDIR) + $(INSTALL) espeakup.8 $(DESTDIR)$(MANDIR) clean: $(RM) *.d *.o From dec561324df67bd64eede09bcb2eb25273a04081 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Thu, 8 Oct 2009 17:46:39 -0500 Subject: [PATCH 088/181] updates to alsa support After studying pcm_min.c in the alsa library git repository, I updated the alsa support to be similar to what I saw there. --- alsa.c | 106 ++++++++++++++++----------------------------------------- 1 file changed, 29 insertions(+), 77 deletions(-) diff --git a/alsa.c b/alsa.c index c7f7d79..fa9e526 100644 --- a/alsa.c +++ b/alsa.c @@ -25,21 +25,13 @@ #include #include #include - -#define ALSA_PCM_NEW_HW_PARAMS_API -#define ALSA_PCM_NEW_SW_PARAMS_API #include -#undef ALSA_PCM_NEW_HW_PARAMS_API -#undef ALSA_PCM_NEW_SW_PARAMS_API #include "espeakup.h" static pthread_mutex_t audio_mutex = PTHREAD_MUTEX_INITIALIZER; static snd_pcm_t *handle; -static snd_pcm_hw_params_t *params; -static snd_pcm_status_t *status; -static int dir = 0; static void lock_audio_mutex(void) { @@ -51,16 +43,9 @@ static void unlock_audio_mutex(void) pthread_mutex_unlock(&audio_mutex); } -static int sound_error(int err, const char *msg) +static int alsa_callback(short *audio, int numsamples, espeak_EVENT * events) { - fprintf(stderr, "%s: %s\n", msg, snd_strerror(err)); - return err; -} - -static int alsa_callback(short *audio, int numsamples, - espeak_EVENT * events) -{ - int written = 0; + int frames = 0; int rc = 0; lock_audio_mutex(); @@ -70,17 +55,17 @@ static int alsa_callback(short *audio, int numsamples, } while (numsamples > 0 && (!stop_requested && should_run)) { - written = snd_pcm_writei(handle, audio, numsamples); - if (written < 0) - written = snd_pcm_recover(handle, written, 0); - if (written < 0) { - fprintf(stderr, "snd_pcm_writei failed: %s\n", snd_strerror(written)); + frames = snd_pcm_writei(handle, audio, numsamples); + if (frames < 0) + frames = snd_pcm_recover(handle, frames, !debug); + if (frames < 0) { + fprintf(stderr, "snd_pcm_writei failed: %s\n", snd_strerror(frames)); break; } - if (written > 0 && written < numsamples) - printf("Short write (expected %i, wrote %i)\n", numsamples, written); - numsamples -= written; - audio += written; + if (frames > 0 && frames < numsamples && debug) + fprintf(stderr, "Short write (expected %i, wrote %i)\n", numsamples, frames); + numsamples -= frames; + audio += frames; } rc = (stop_requested || !should_run); unlock_audio_mutex(); @@ -94,60 +79,27 @@ void select_audio_mode(void) int init_audio(unsigned int rate) { - int rc; + int err; /* Open PCM device for playback. */ - rc = snd_pcm_open(&handle, "default", SND_PCM_STREAM_PLAYBACK, 0); - if (rc < 0) - return sound_error(rc, "unable to open pcm device"); + err = snd_pcm_open(&handle, "default", SND_PCM_STREAM_PLAYBACK, 0); + if (err < 0) { + fprintf(stderr, "Playback open error: %s\n", snd_strerror(err)); + return err; + } - /* Allocate a hardware parameters object. */ - rc = snd_pcm_hw_params_malloc(¶ms); - if (rc < 0) - return sound_error(rc, - "Unable to allocate memory to store audio parameters"); - - rc = snd_pcm_status_malloc(&status); - if (rc < 0) - return sound_error(rc, - "Unable to allocate memory to store PCM status"); - - /* Fill it in with default values. */ - rc = snd_pcm_hw_params_any(handle, params); - - if (rc < 0) - return sound_error(rc, - "Unable to establish defaults for hardware parameters."); - - /* Set the desired hardware parameters. */ - - /* Interleaved mode */ - rc = snd_pcm_hw_params_set_access(handle, params, - SND_PCM_ACCESS_RW_INTERLEAVED); - - if (rc < 0) - return sound_error(rc, "Error selecting interleaved mode."); - - /* Signed 16-bit little-endian format */ - rc = snd_pcm_hw_params_set_format(handle, params, - SND_PCM_FORMAT_S16_LE); - if (rc < 0) - return sound_error(rc, "Unable to select signed 16-bit samples"); - - /* One channel */ - rc = snd_pcm_hw_params_set_channels(handle, params, 1); - - if (rc < 0) - return sound_error(rc, "Unable to use mono output."); - - rc = snd_pcm_hw_params_set_rate_near(handle, params, &rate, &dir); - if (rc < 0) - return sound_error(rc, "Unable to set sample rate"); - - /* Write the parameters to the driver */ - rc = snd_pcm_hw_params(handle, params); - if (rc < 0) - return sound_error(rc, "unable to set hw parameters"); + /* Set parameters. */ + err = snd_pcm_set_params(handle, + SND_PCM_FORMAT_S16_LE, + SND_PCM_ACCESS_RW_INTERLEAVED, + 1, + rate, + 1, + 0); + if (err < 0) { + fprintf(stderr, "Playback open error: %s\n", snd_strerror(err)); + return err; + } espeak_SetSynthCallback(alsa_callback); return 0; From edb5e50fcd52d6f0ed9d2decb5c874dfd9395998 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Fri, 9 Oct 2009 08:56:58 -0500 Subject: [PATCH 089/181] make alsa code more readable This changes the code to use constants for the parameters to snd_pcm_set_params. This makes it easier to read the code and to update the values if needed. --- alsa.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/alsa.c b/alsa.c index fa9e526..bae9798 100644 --- a/alsa.c +++ b/alsa.c @@ -32,6 +32,9 @@ static pthread_mutex_t audio_mutex = PTHREAD_MUTEX_INITIALIZER; static snd_pcm_t *handle; +static const unsigned int channels = 1; +static const int soft_resample = 1; +static const unsigned int latency = 125000; static void lock_audio_mutex(void) { @@ -92,10 +95,10 @@ int init_audio(unsigned int rate) err = snd_pcm_set_params(handle, SND_PCM_FORMAT_S16_LE, SND_PCM_ACCESS_RW_INTERLEAVED, - 1, + channels, rate, - 1, - 0); + soft_resample, + latency); if (err < 0) { fprintf(stderr, "Playback open error: %s\n", snd_strerror(err)); return err; From 1a10788c5f140f75e0f54a2baaf8625125bb52ac Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Fri, 9 Oct 2009 11:09:20 -0500 Subject: [PATCH 090/181] lowered latency setting to 1/40 of a second. --- alsa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alsa.c b/alsa.c index bae9798..392b149 100644 --- a/alsa.c +++ b/alsa.c @@ -34,7 +34,7 @@ static pthread_mutex_t audio_mutex = PTHREAD_MUTEX_INITIALIZER; static snd_pcm_t *handle; static const unsigned int channels = 1; static const int soft_resample = 1; -static const unsigned int latency = 125000; +static const unsigned int latency = 25000; static void lock_audio_mutex(void) { From 4cfcd7ba116ddd3e1c80744b4eb7e0b83438ec86 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Fri, 9 Oct 2009 11:10:49 -0500 Subject: [PATCH 091/181] fixed mandir the mandir variable in the makefile should point only to the top level of the man tree. --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 367eaa7..eab706a 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ INSTALL ?= install PREFIX ?= /usr/local -MANDIR ?= $(PREFIX)/share/man/man8 BINDIR ?= $(PREFIX)/bin +MANDIR ?= $(PREFIX)/share/man AUDIO ?= portaudio @@ -29,9 +29,9 @@ all: espeakup install: espeakup $(INSTALL) -d $(DESTDIR)$(BINDIR) - $(INSTALL) -d $(DESTDIR)$(MANDIR) + $(INSTALL) -d $(DESTDIR)$(MANDIR)/man8 $(INSTALL) $< $(DESTDIR)$(BINDIR) - $(INSTALL) espeakup.8 $(DESTDIR)$(MANDIR) + $(INSTALL) espeakup.8 $(DESTDIR)$(MANDIR)/man8 clean: $(RM) *.d *.o From 8fda956e020abcde9365c20c6e14f3ebc15cd2e1 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Fri, 9 Oct 2009 11:20:17 -0500 Subject: [PATCH 092/181] fixed permissions in makefile It turns out that the install commands need to have the permission options otherwise the permission of everything that is installed is 755, which is not correct. --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index eab706a..ca700aa 100644 --- a/Makefile +++ b/Makefile @@ -30,8 +30,8 @@ all: espeakup install: espeakup $(INSTALL) -d $(DESTDIR)$(BINDIR) $(INSTALL) -d $(DESTDIR)$(MANDIR)/man8 - $(INSTALL) $< $(DESTDIR)$(BINDIR) - $(INSTALL) espeakup.8 $(DESTDIR)$(MANDIR)/man8 + $(INSTALL) -m 755 $< $(DESTDIR)$(BINDIR) + $(INSTALL) -m 644 espeakup.8 $(DESTDIR)$(MANDIR)/man8 clean: $(RM) *.d *.o From d1630432ba55033c82da0dcae4a409f14da8d03f Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Sat, 10 Oct 2009 12:04:41 -0500 Subject: [PATCH 093/181] re-organized the makefile. --- Makefile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index ca700aa..482d916 100644 --- a/Makefile +++ b/Makefile @@ -16,13 +16,13 @@ SRCS = $($(AUDIO)_SRCS) \ queue.c \ signal.c \ softsynth.c +OBJS = $(SRCS:.c=.o) +DEPFLAGS = -MMD +WARNFLAGS = -Wall ifeq ($(AUDIO),alsa) SOUNDLIB = -lasound endif - -OBJS = $(SRCS:.c=.o) - LDLIBS = -lespeak $(SOUNDLIB) all: espeakup @@ -33,15 +33,15 @@ install: espeakup $(INSTALL) -m 755 $< $(DESTDIR)$(BINDIR) $(INSTALL) -m 644 espeakup.8 $(DESTDIR)$(MANDIR)/man8 +espeakup: $(OBJS) + clean: $(RM) *.d *.o distclean: clean $(RM) espeakup -espeakup: $(OBJS) - %.o: %.c - $(COMPILE.c) -MMD -Wall $(OUTPUT_OPTION) $< + $(COMPILE.c) $(DEPFLAGS) $(WARNFLAGS) $(OUTPUT_OPTION) $< -include $(SRCS:.c=.d) From 056dcf70fe5a6850b73193ea06480bd955695e2e Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Tue, 4 May 2010 12:59:53 -0500 Subject: [PATCH 094/181] convert to autotools --- .gitignore | 13 ++++++++++++- Makefile | 47 ----------------------------------------------- Makefile.am | 10 ++++++++++ alsa.c | 4 ++++ cli.c | 10 ++++++---- configure.ac | 43 +++++++++++++++++++++++++++++++++++++++++++ espeak.c | 4 ++++ espeakup.c | 7 ++++--- portaudio.c | 4 ++++ queue.c | 4 ++++ signal.c | 4 ++++ softsynth.c | 4 ++++ tarball | 22 ---------------------- version | 5 ----- 14 files changed, 99 insertions(+), 82 deletions(-) delete mode 100644 Makefile create mode 100644 Makefile.am create mode 100644 configure.ac delete mode 100755 tarball delete mode 100755 version diff --git a/.gitignore b/.gitignore index aeb1414..c6a1e36 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,14 @@ +.deps +aclocal.m4 +autom4te.cache +config.* +configure +depcomp espeakup -*.d +install-sh +Makefile +Makefile.in +missing +stamp-h1 *.o +*.swp diff --git a/Makefile b/Makefile deleted file mode 100644 index 482d916..0000000 --- a/Makefile +++ /dev/null @@ -1,47 +0,0 @@ -INSTALL ?= install - -PREFIX ?= /usr/local -BINDIR ?= $(PREFIX)/bin -MANDIR ?= $(PREFIX)/share/man - -AUDIO ?= portaudio - -alsa_SRCS = alsa.c -portaudio_SRCS = portaudio.c - -SRCS = $($(AUDIO)_SRCS) \ - cli.c \ - espeak.c \ - espeakup.c \ - queue.c \ - signal.c \ - softsynth.c -OBJS = $(SRCS:.c=.o) - -DEPFLAGS = -MMD -WARNFLAGS = -Wall -ifeq ($(AUDIO),alsa) -SOUNDLIB = -lasound -endif -LDLIBS = -lespeak $(SOUNDLIB) - -all: espeakup - -install: espeakup - $(INSTALL) -d $(DESTDIR)$(BINDIR) - $(INSTALL) -d $(DESTDIR)$(MANDIR)/man8 - $(INSTALL) -m 755 $< $(DESTDIR)$(BINDIR) - $(INSTALL) -m 644 espeakup.8 $(DESTDIR)$(MANDIR)/man8 - -espeakup: $(OBJS) - -clean: - $(RM) *.d *.o - -distclean: clean - $(RM) espeakup - -%.o: %.c - $(COMPILE.c) $(DEPFLAGS) $(WARNFLAGS) $(OUTPUT_OPTION) $< - --include $(SRCS:.c=.d) diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..c516fe1 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,10 @@ +bin_PROGRAMS = espeakup +espeakup_SOURCES = espeakup.c espeakup.h cli.c espeak.c queue.c queue.h signal.c softsynth.c + +if ALSA +espeakup_SOURCES += alsa.c +else +espeakup_SOURCES += portaudio.c +endif + +dist_man8_MANS = espeakup.8 diff --git a/alsa.c b/alsa.c index 392b149..35235fc 100644 --- a/alsa.c +++ b/alsa.c @@ -22,6 +22,10 @@ * Description: Produce audio by calling the ALSA library directly. */ +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include #include diff --git a/cli.c b/cli.c index 023d6cc..af8ec14 100644 --- a/cli.c +++ b/cli.c @@ -17,6 +17,10 @@ * along with this program. If not, see . */ +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include #include @@ -24,9 +28,6 @@ #include "espeakup.h" -/* program version */ -extern const char *Version; - /* default voice */ extern char *defaultVoice; @@ -53,10 +54,11 @@ static void show_help() static void show_version(void) { - printf("espeakup %s\n", Version); + printf("%s\n", PACKAGE_STRING); printf("Copyright (C) 2008 William Hubbs\n"); printf("License GPLv3+: GNU GPL version 3 or later\n"); printf("You are free to change and redistribute this software.\n"); + printf("Please report bugs to %s\n", PACKAGE_BUGREPORT); exit(0); } diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..d20967a --- /dev/null +++ b/configure.ac @@ -0,0 +1,43 @@ +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. + +AC_PREREQ([2.65]) +AC_INIT([espeakup], [0.71], [w.d.hubbs@gmail.com]) +AM_INIT_AUTOMAKE([foreign]) +AC_CONFIG_SRCDIR([espeakup.c]) +AC_CONFIG_HEADERS([config.h]) + +# process command line options +AC_ARG_WITH([alsa], + [AS_HELP_STRING([--with-alsa],[build with ALSA support])], + [], + [with_alsa=no]) +AM_CONDITIONAL([ALSA], [test x$with_alsa = xyes]) + +# Checks for programs. +AC_PROG_CC +AC_PROG_INSTALL + +# Checks for libraries. +if test x$with_alsa = xyes; then +AC_SEARCH_LIBS([snd_pcm_open], [asound]) +fi +AC_SEARCH_LIBS([espeak_Synth], [espeak]) + +# Checks for header files. +AC_CHECK_HEADERS([fcntl.h limits.h stddef.h stdlib.h string.h unistd.h espeak/speak_lib.h]) +if test x$with_alsa = xyes; then +AC_CHECK_HEADERS([alsa/asoundlib.h]) +fi + +# Checks for typedefs, structures, and compiler characteristics. +AC_TYPE_PID_T +AC_TYPE_SIZE_T +AC_TYPE_SSIZE_T + +# Checks for library functions. +AC_FUNC_MALLOC +AC_CHECK_FUNCS([memmove select strdup strrchr]) + +AC_CONFIG_FILES([Makefile]) +AC_OUTPUT diff --git a/espeak.c b/espeak.c index 4a987b1..b308832 100644 --- a/espeak.c +++ b/espeak.c @@ -17,6 +17,10 @@ * along with this program. If not, see . */ +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include #include diff --git a/espeakup.c b/espeakup.c index b749bcb..38dcf4f 100644 --- a/espeakup.c +++ b/espeakup.c @@ -17,6 +17,10 @@ * along with this program. If not, see . */ +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include #include @@ -26,9 +30,6 @@ #include "espeakup.h" -/* program version */ -const char *Version = "0.71"; - /* path to our pid file */ const char *pidPath = "/var/run/espeakup.pid"; diff --git a/portaudio.c b/portaudio.c index 6e24b8c..82af6c6 100644 --- a/portaudio.c +++ b/portaudio.c @@ -1,3 +1,7 @@ +#ifdef HAVE_CONFIG_H +#include +#endif + #include "espeakup.h" void select_audio_mode(void) diff --git a/queue.c b/queue.c index e1827da..9815e48 100644 --- a/queue.c +++ b/queue.c @@ -21,6 +21,10 @@ * along with this program. If not, see . */ +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include #include diff --git a/signal.c b/signal.c index 5996986..52f3ec6 100644 --- a/signal.c +++ b/signal.c @@ -17,6 +17,10 @@ * along with this program. If not, see . */ +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include #include diff --git a/softsynth.c b/softsynth.c index 9747963..4bac4f2 100644 --- a/softsynth.c +++ b/softsynth.c @@ -17,6 +17,10 @@ * along with this program. If not, see . */ +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include #include diff --git a/tarball b/tarball deleted file mode 100755 index 12bf7ee..0000000 --- a/tarball +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash -# Makes a tarball release - -VER=$(./version) -PREFIX=espeakup-${VER} -REL=${1:-v${VER}} - -if [ "$REL" != "v${VER}" ]; then - TIMESTAMP=`git show $REL --pretty=format:%ai |head -1` - PATCHLEVEL=`date --utc -d "$TIMESTAMP" +_p%Y%m%d%H%M` -fi - -TARFILE=${PREFIX}${PATCHLEVEL}.tar - -git archive --format=tar --prefix=${PREFIX}/ $REL > ${TARFILE} -tar f ${TARFILE} --delete ${PREFIX}/.gitignore --delete ${PREFIX}/tarball -mkdir ${PREFIX} -git log ${REL} > ${PREFIX}/ChangeLog -tar rf ${TARFILE} ${PREFIX} -rm -rf ${PREFIX} -bzip2 ${TARFILE} -echo "Produced ${TARFILE}.bz2" diff --git a/version b/version deleted file mode 100755 index de85fd8..0000000 --- a/version +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -ver=$(grep "const char.*Version" espeakup.c) -ver=${ver%\"*} -ver=${ver#*\"} -echo ${ver} From 0d9d7b61419eb37247e8f7afb6c5b7ff198f0ab7 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Tue, 4 May 2010 23:17:53 -0500 Subject: [PATCH 095/181] update readme --- README | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/README b/README index c5f6f5e..0483dec 100644 --- a/README +++ b/README @@ -21,20 +21,26 @@ The preferred way to install espeakup is using your distribution's packaging system, but if your distribution does not have a package for espeakup yet, here are some basic instructions. -To install espeakup, first cd into the directory where you -unpacked the tarball, then issue make to compile the program. Once this -is done, as root, issue make install. This will install espeakup in /usr/bin. +Espeakup uses an autotools build system, so installation should be very +straight forward. + +If you are installing from git, you must have at least automake 1.11.1 +and autoconf 2.65 installed. Then, change to the repository directory +and type: + +autoreconf -i + +If this runs successfully, you will have a configure script, so run it +then run make. If that completes successfully, run make install. ALSA SUPPORT ============ -Direct support for alsa was just contributed to this project; I would -like to thank Chris Brannon for his work on this. Currently,, it is in -the early stages, so if you have any suggestions or patches, I am -definitely interested. +Chris Brannon contributed the alsa support to this project, and I would +like to thank him for his work on it. -To build with alsa support, add "AUDIO=alsa" to the make command when you -compile the program. +To build with alsa support, add --with-alsa to the command line when you +run the configure script. Starting Up =========== From 037e6422179424dd40667765039c6584ac306514 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Tue, 4 May 2010 23:31:34 -0500 Subject: [PATCH 096/181] rename todo file --- ToDo => TODO | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename ToDo => TODO (100%) diff --git a/ToDo b/TODO similarity index 100% rename from ToDo rename to TODO From 3bfc662bae54038172de1c52b04e9c589d2f7bd0 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Wed, 5 May 2010 15:11:02 -0500 Subject: [PATCH 097/181] update location of latest version and git repository --- README | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README b/README index 0483dec..13f4a2b 100644 --- a/README +++ b/README @@ -63,14 +63,15 @@ Espeakup currently accepts the following command line options: Getting the Latest Version ========================== -Currently, a tarball of the latest official release will be included in -the contrib/ directory of the speakup repository. Also, it is possible -to download a tarball of any released version from github as follows: +It is possible to download a tarball from github of any released version +as follows: wget http://www.github.com/williamh/espeakup/tarball/vx.y -Also, the clone URL, if you are familiar with using git is -git://github.com/williamh/espeakup.git. +If you need a tarball for packaging purposes, one is available from +ftp://ftp.linux-speakup.org/pub/linux/goodies/espeakup-x.y.tar.bz2. + +The url for the git repository is git://github.com/williamh/espeakup.git. Acknowledgements ================ From c7ae47dfe59481b29ec80de2faaa6c8d3bd63379 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Wed, 2 Jun 2010 12:11:05 -0500 Subject: [PATCH 098/181] add experimental support for building a static binary This is done by adding a --enable-standalone switch to the configure script. --- Makefile.am | 4 ++++ configure.ac | 36 +++++++++++++++++++++++++----------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/Makefile.am b/Makefile.am index c516fe1..41fcf0b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -7,4 +7,8 @@ else espeakup_SOURCES += portaudio.c endif +if STANDALONE +espeakup_LDFLAGS = -all-static +endif + dist_man8_MANS = espeakup.8 diff --git a/configure.ac b/configure.ac index d20967a..3d9c5c1 100644 --- a/configure.ac +++ b/configure.ac @@ -4,14 +4,21 @@ AC_PREREQ([2.65]) AC_INIT([espeakup], [0.71], [w.d.hubbs@gmail.com]) AM_INIT_AUTOMAKE([foreign]) +LT_INIT() AC_CONFIG_SRCDIR([espeakup.c]) AC_CONFIG_HEADERS([config.h]) # process command line options +AC_ARG_ENABLE([standalone], + [AS_HELP_STRING([--enable-standalone],[build a standalone executable])], + [], + [enable_standalone=no]) +AM_CONDITIONAL([STANDALONE], [test x$enable_standalone = xyes]) + AC_ARG_WITH([alsa], - [AS_HELP_STRING([--with-alsa],[build with ALSA support])], - [], - [with_alsa=no]) + [AS_HELP_STRING([--with-alsa],[build with ALSA support])], + [], + [with_alsa=no]) AM_CONDITIONAL([ALSA], [test x$with_alsa = xyes]) # Checks for programs. @@ -19,16 +26,23 @@ AC_PROG_CC AC_PROG_INSTALL # Checks for libraries. -if test x$with_alsa = xyes; then -AC_SEARCH_LIBS([snd_pcm_open], [asound]) -fi -AC_SEARCH_LIBS([espeak_Synth], [espeak]) +AC_SEARCH_LIBS([pow], [m], [], + [AC_MSG_FAILURE([math library missing -- unable to continue.])]) +AC_SEARCH_LIBS([pthread_create], [pthread], [], + [AC_MSG_FAILURE([threads library missing -- unable to continue.])]) + +AS_IF([test x$with_alsa = xyes], + [AC_SEARCH_LIBS([snd_pcm_open], [asound], [], + [AC_MSG_FAILURE([ALSA library missing -- unable to continue.])])]) + +AC_SEARCH_LIBS([Pa_Initialize], [portaudio]) +AC_SEARCH_LIBS([espeak_Synth], [espeak], [], + [AC_MSG_FAILURE([espeak library missing -- unable to continue.])]) # Checks for header files. -AC_CHECK_HEADERS([fcntl.h limits.h stddef.h stdlib.h string.h unistd.h espeak/speak_lib.h]) -if test x$with_alsa = xyes; then -AC_CHECK_HEADERS([alsa/asoundlib.h]) -fi +AC_CHECK_HEADERS([fcntl.h limits.h stddef.h stdlib.h string.h unistd.h]) +AS_IF([test x$with_alsa = xyes], + [AC_CHECK_HEADERS([alsa/asoundlib.h])]) # Checks for typedefs, structures, and compiler characteristics. AC_TYPE_PID_T From 7bf2eee07a6c5d2120e62d13e0385e4c8e9c6782 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Sat, 5 Mar 2011 16:49:58 -0600 Subject: [PATCH 099/181] remove experimental alsa support The direct alsa support was experimental and never worked well. It had a setting which was system specific. Also, I feel that it is better to let espeak control the audio processing. --- Makefile.am | 6 --- README | 9 ---- alsa.c | 122 --------------------------------------------------- configure.ac | 6 --- espeak.c | 8 +--- espeakup.h | 5 --- portaudio.c | 20 --------- 7 files changed, 1 insertion(+), 175 deletions(-) delete mode 100644 alsa.c delete mode 100644 portaudio.c diff --git a/Makefile.am b/Makefile.am index 41fcf0b..3afa3ae 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,12 +1,6 @@ bin_PROGRAMS = espeakup espeakup_SOURCES = espeakup.c espeakup.h cli.c espeak.c queue.c queue.h signal.c softsynth.c -if ALSA -espeakup_SOURCES += alsa.c -else -espeakup_SOURCES += portaudio.c -endif - if STANDALONE espeakup_LDFLAGS = -all-static endif diff --git a/README b/README index 13f4a2b..f3cd032 100644 --- a/README +++ b/README @@ -33,15 +33,6 @@ autoreconf -i If this runs successfully, you will have a configure script, so run it then run make. If that completes successfully, run make install. -ALSA SUPPORT -============ - -Chris Brannon contributed the alsa support to this project, and I would -like to thank him for his work on it. - -To build with alsa support, add --with-alsa to the command line when you -run the configure script. - Starting Up =========== diff --git a/alsa.c b/alsa.c deleted file mode 100644 index 35235fc..0000000 --- a/alsa.c +++ /dev/null @@ -1,122 +0,0 @@ -/* - * espeakup - interface which allows speakup to use espeak - * - * Copyright (C) 2008 William Hubbs - * - * This program 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. - * - * This program 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 this program. If not, see . - */ - -/* - * File: alsa.c - * Description: Produce audio by calling the ALSA library directly. -*/ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include - -#include "espeakup.h" - -static pthread_mutex_t audio_mutex = PTHREAD_MUTEX_INITIALIZER; - -static snd_pcm_t *handle; -static const unsigned int channels = 1; -static const int soft_resample = 1; -static const unsigned int latency = 25000; - -static void lock_audio_mutex(void) -{ - pthread_mutex_lock(&audio_mutex); -} - -static void unlock_audio_mutex(void) -{ - pthread_mutex_unlock(&audio_mutex); -} - -static int alsa_callback(short *audio, int numsamples, espeak_EVENT * events) -{ - int frames = 0; - int rc = 0; - - lock_audio_mutex(); - if (stop_requested || !should_run) { - unlock_audio_mutex(); - return 1; - } - - while (numsamples > 0 && (!stop_requested && should_run)) { - frames = snd_pcm_writei(handle, audio, numsamples); - if (frames < 0) - frames = snd_pcm_recover(handle, frames, !debug); - if (frames < 0) { - fprintf(stderr, "snd_pcm_writei failed: %s\n", snd_strerror(frames)); - break; - } - if (frames > 0 && frames < numsamples && debug) - fprintf(stderr, "Short write (expected %i, wrote %i)\n", numsamples, frames); - numsamples -= frames; - audio += frames; - } - rc = (stop_requested || !should_run); - unlock_audio_mutex(); - return rc; -} - -void select_audio_mode(void) -{ - audio_mode = AUDIO_OUTPUT_RETRIEVAL; -} - -int init_audio(unsigned int rate) -{ - int err; - - /* Open PCM device for playback. */ - err = snd_pcm_open(&handle, "default", SND_PCM_STREAM_PLAYBACK, 0); - if (err < 0) { - fprintf(stderr, "Playback open error: %s\n", snd_strerror(err)); - return err; - } - - /* Set parameters. */ - err = snd_pcm_set_params(handle, - SND_PCM_FORMAT_S16_LE, - SND_PCM_ACCESS_RW_INTERLEAVED, - channels, - rate, - soft_resample, - latency); - if (err < 0) { - fprintf(stderr, "Playback open error: %s\n", snd_strerror(err)); - return err; - } - - espeak_SetSynthCallback(alsa_callback); - return 0; -} - -void stop_audio(void) -{ - lock_audio_mutex(); - if (snd_pcm_drop(handle) < 0) - fprintf(stderr, "Negative return from snd_pcm_drop!\n"); - snd_pcm_prepare(handle); - unlock_audio_mutex(); -} diff --git a/configure.ac b/configure.ac index 3d9c5c1..084ddb6 100644 --- a/configure.ac +++ b/configure.ac @@ -15,12 +15,6 @@ AC_ARG_ENABLE([standalone], [enable_standalone=no]) AM_CONDITIONAL([STANDALONE], [test x$enable_standalone = xyes]) -AC_ARG_WITH([alsa], - [AS_HELP_STRING([--with-alsa],[build with ALSA support])], - [], - [with_alsa=no]) -AM_CONDITIONAL([ALSA], [test x$with_alsa = xyes]) - # Checks for programs. AC_PROG_CC AC_PROG_INSTALL diff --git a/espeak.c b/espeak.c index b308832..8c0f275 100644 --- a/espeak.c +++ b/espeak.c @@ -136,7 +136,6 @@ static espeak_ERROR stop_speech(void) { espeak_ERROR rc; - stop_audio(); rc = espeak_Cancel(); return rc; } @@ -218,17 +217,12 @@ int initialize_espeak(struct synth_t *s) int rate; /* initialize espeak */ - select_audio_mode(); - rate = espeak_Initialize(audio_mode, 50, NULL, 0); + rate = espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 50, NULL, 0); if (rate < 0) { fprintf(stderr, "Unable to initialize espeak.\n"); return -1; } - if (init_audio((unsigned int) rate) < 0) { - return -1; - } - /* Setup initial voice parameters */ if (defaultVoice) { set_voice(s, defaultVoice); diff --git a/espeakup.h b/espeakup.h index 3580180..8680ae2 100644 --- a/espeakup.h +++ b/espeakup.h @@ -75,17 +75,12 @@ extern void *espeak_thread(void *arg); extern int open_softsynth(void); extern void close_softsynth(void); extern void *softsynth_thread(void *arg); -extern void select_audio_mode(void); -extern int init_audio(unsigned int rate); -extern void stop_audio(void); extern volatile int should_run; extern volatile int stop_requested; extern int self_pipe_fds[2]; #define PIPE_READ_FD (self_pipe_fds[0]) #define PIPE_WRITE_FD (self_pipe_fds[1]) -extern espeak_AUDIO_OUTPUT audio_mode; - extern pthread_cond_t runner_awake; extern pthread_cond_t stop_acknowledged; extern pthread_mutex_t queue_guard; diff --git a/portaudio.c b/portaudio.c deleted file mode 100644 index 82af6c6..0000000 --- a/portaudio.c +++ /dev/null @@ -1,20 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include -#endif - -#include "espeakup.h" - -void select_audio_mode(void) -{ - audio_mode = AUDIO_OUTPUT_PLAYBACK; -} - -int init_audio(unsigned int rate) -{ - return 0; -} - -void stop_audio(void) -{ - return; -} From 701074fd9685ce4133672fbb35f046e76ab13422 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Sat, 5 Mar 2011 20:11:21 -0600 Subject: [PATCH 100/181] go back to just using a makefile The reason I went to autotools was the multiple sound systems, but since we are now just using espeak's audio processing we can go back to a more simple build system. --- .gitignore | 12 +----------- Makefile | 40 ++++++++++++++++++++++++++++++++++++++++ Makefile.am | 8 -------- README | 16 +++------------- cli.c | 6 +----- configure.ac | 51 --------------------------------------------------- espeak.c | 4 ---- espeakup.c | 4 ---- espeakup.h | 3 +++ queue.c | 4 ---- signal.c | 4 ---- softsynth.c | 4 ---- 12 files changed, 48 insertions(+), 108 deletions(-) create mode 100644 Makefile delete mode 100644 Makefile.am delete mode 100644 configure.ac diff --git a/.gitignore b/.gitignore index c6a1e36..7870fbc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,4 @@ -.deps -aclocal.m4 -autom4te.cache -config.* -configure -depcomp espeakup -install-sh -Makefile -Makefile.in -missing -stamp-h1 +*.d *.o *.swp diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9c156f6 --- /dev/null +++ b/Makefile @@ -0,0 +1,40 @@ +PREFIX = /usr/local +BINDIR = ${PREFIX}/bin +MANDIR = ${PREFIX}/share/man + +DEPFLAGS = -MMD +WARNFLAGS = -Wall +CFLAGS += ${DEPFLAGS} ${WARNFLAGS} + +LDLIBS = -lespeak -lpthread + +INSTALL = install +BINMODE = 0755 +MANMODE = 0644 + +SRCS = cli.c \ + espeak.c \ + espeakup.c \ + queue.c \ + signal.c \ + softsynth.c + +OBJS = ${SRCS:.c=.o} + +all: espeakup + +install: espeakup + ${INSTALL} -d ${DESTDIR}${BINDIR} + ${INSTALL} -m ${BINMODE} $< ${DESTDIR}${BINDIR} + ${INSTALL} -d ${DESTDIR}${MANDIR}/man8 + ${INSTALL} -m 644 espeakup.8 ${DESTDIR}${MANDIR}/man8 + +espeakup: ${OBJS} + +clean: + ${RM} *.d *.o + +distclean: clean + ${RM} espeakup + +-include ${SRCS:.c=.d} diff --git a/Makefile.am b/Makefile.am deleted file mode 100644 index 3afa3ae..0000000 --- a/Makefile.am +++ /dev/null @@ -1,8 +0,0 @@ -bin_PROGRAMS = espeakup -espeakup_SOURCES = espeakup.c espeakup.h cli.c espeak.c queue.c queue.h signal.c softsynth.c - -if STANDALONE -espeakup_LDFLAGS = -all-static -endif - -dist_man8_MANS = espeakup.8 diff --git a/README b/README index f3cd032..b8ed359 100644 --- a/README +++ b/README @@ -19,19 +19,9 @@ Installation The preferred way to install espeakup is using your distribution's packaging system, but if your distribution does not have a package for -espeakup yet, here are some basic instructions. - -Espeakup uses an autotools build system, so installation should be very -straight forward. - -If you are installing from git, you must have at least automake 1.11.1 -and autoconf 2.65 installed. Then, change to the repository directory -and type: - -autoreconf -i - -If this runs successfully, you will have a configure script, so run it -then run make. If that completes successfully, run make install. +espeakup yet, espeakup just uses a Makefile, so you should be able to +change to the source directory, then type make, then as root, make +install. Starting Up =========== diff --git a/cli.c b/cli.c index af8ec14..64cfd6b 100644 --- a/cli.c +++ b/cli.c @@ -17,10 +17,6 @@ * along with this program. If not, see . */ -#ifdef HAVE_CONFIG_H -#include -#endif - #include #include #include @@ -54,7 +50,7 @@ static void show_help() static void show_version(void) { - printf("%s\n", PACKAGE_STRING); + printf("ESpeakup %s\n", PACKAGE_VERSION); printf("Copyright (C) 2008 William Hubbs\n"); printf("License GPLv3+: GNU GPL version 3 or later\n"); printf("You are free to change and redistribute this software.\n"); diff --git a/configure.ac b/configure.ac deleted file mode 100644 index 084ddb6..0000000 --- a/configure.ac +++ /dev/null @@ -1,51 +0,0 @@ -# -*- Autoconf -*- -# Process this file with autoconf to produce a configure script. - -AC_PREREQ([2.65]) -AC_INIT([espeakup], [0.71], [w.d.hubbs@gmail.com]) -AM_INIT_AUTOMAKE([foreign]) -LT_INIT() -AC_CONFIG_SRCDIR([espeakup.c]) -AC_CONFIG_HEADERS([config.h]) - -# process command line options -AC_ARG_ENABLE([standalone], - [AS_HELP_STRING([--enable-standalone],[build a standalone executable])], - [], - [enable_standalone=no]) -AM_CONDITIONAL([STANDALONE], [test x$enable_standalone = xyes]) - -# Checks for programs. -AC_PROG_CC -AC_PROG_INSTALL - -# Checks for libraries. -AC_SEARCH_LIBS([pow], [m], [], - [AC_MSG_FAILURE([math library missing -- unable to continue.])]) -AC_SEARCH_LIBS([pthread_create], [pthread], [], - [AC_MSG_FAILURE([threads library missing -- unable to continue.])]) - -AS_IF([test x$with_alsa = xyes], - [AC_SEARCH_LIBS([snd_pcm_open], [asound], [], - [AC_MSG_FAILURE([ALSA library missing -- unable to continue.])])]) - -AC_SEARCH_LIBS([Pa_Initialize], [portaudio]) -AC_SEARCH_LIBS([espeak_Synth], [espeak], [], - [AC_MSG_FAILURE([espeak library missing -- unable to continue.])]) - -# Checks for header files. -AC_CHECK_HEADERS([fcntl.h limits.h stddef.h stdlib.h string.h unistd.h]) -AS_IF([test x$with_alsa = xyes], - [AC_CHECK_HEADERS([alsa/asoundlib.h])]) - -# Checks for typedefs, structures, and compiler characteristics. -AC_TYPE_PID_T -AC_TYPE_SIZE_T -AC_TYPE_SSIZE_T - -# Checks for library functions. -AC_FUNC_MALLOC -AC_CHECK_FUNCS([memmove select strdup strrchr]) - -AC_CONFIG_FILES([Makefile]) -AC_OUTPUT diff --git a/espeak.c b/espeak.c index 8c0f275..5e69ac5 100644 --- a/espeak.c +++ b/espeak.c @@ -17,10 +17,6 @@ * along with this program. If not, see . */ -#ifdef HAVE_CONFIG_H -#include -#endif - #include #include #include diff --git a/espeakup.c b/espeakup.c index 38dcf4f..e059b84 100644 --- a/espeakup.c +++ b/espeakup.c @@ -17,10 +17,6 @@ * along with this program. If not, see . */ -#ifdef HAVE_CONFIG_H -#include -#endif - #include #include #include diff --git a/espeakup.h b/espeakup.h index 8680ae2..8cd318a 100644 --- a/espeakup.h +++ b/espeakup.h @@ -28,6 +28,9 @@ #include "queue.h" +#define PACKAGE_VERSION "0.80-dev" +#define PACKAGE_BUGREPORT "http://github.com/williamh/espeakup/issues" + enum command_t { CMD_SET_FREQUENCY, CMD_SET_PITCH, diff --git a/queue.c b/queue.c index 9815e48..e1827da 100644 --- a/queue.c +++ b/queue.c @@ -21,10 +21,6 @@ * along with this program. If not, see . */ -#ifdef HAVE_CONFIG_H -#include -#endif - #include #include #include diff --git a/signal.c b/signal.c index 52f3ec6..5996986 100644 --- a/signal.c +++ b/signal.c @@ -17,10 +17,6 @@ * along with this program. If not, see . */ -#ifdef HAVE_CONFIG_H -#include -#endif - #include #include #include diff --git a/softsynth.c b/softsynth.c index 4bac4f2..9747963 100644 --- a/softsynth.c +++ b/softsynth.c @@ -17,10 +17,6 @@ * along with this program. If not, see . */ -#ifdef HAVE_CONFIG_H -#include -#endif - #include #include #include From 1990e8e25d23fd4cbaa924ac7af480e2a079b9dc Mon Sep 17 00:00:00 2001 From: Christopher Brannon Date: Sun, 6 Mar 2011 20:18:46 +0000 Subject: [PATCH 101/181] Properly initialize sigaction struct. The sigaction struct used in signal_thread was stored in an automatic variable. The fields which were not set manually had undefined values. --- signal.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/signal.c b/signal.c index 5996986..c87c508 100644 --- a/signal.c +++ b/signal.c @@ -25,6 +25,9 @@ #include "espeakup.h" +/* A struct sigaction with all values set to zero. */ +static struct sigaction OUR_SIGACTION_INITIALIZER; + /* * We install a dummy signal handler to let the o/s know that we * do not want the default action to be performed since we are @@ -36,7 +39,7 @@ static void dummy_handler(int sig) void *signal_thread(void *arg) { - struct sigaction temp; + struct sigaction temp = OUR_SIGACTION_INITIALIZER; sigset_t sigset; int sig; From 2154d1a23157cc2b0ff72f1ed51e5c8a26b452cb Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Sun, 6 Mar 2011 15:10:07 -0600 Subject: [PATCH 102/181] use memset to initialize sigaction structure --- signal.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/signal.c b/signal.c index c87c508..102c3cf 100644 --- a/signal.c +++ b/signal.c @@ -25,9 +25,6 @@ #include "espeakup.h" -/* A struct sigaction with all values set to zero. */ -static struct sigaction OUR_SIGACTION_INITIALIZER; - /* * We install a dummy signal handler to let the o/s know that we * do not want the default action to be performed since we are @@ -39,10 +36,11 @@ static void dummy_handler(int sig) void *signal_thread(void *arg) { - struct sigaction temp = OUR_SIGACTION_INITIALIZER; + struct sigaction temp; sigset_t sigset; int sig; + memset(&temp, 0, sizeof (struct sigaction)); /* install dummy handlers for the signals we want to process */ temp.sa_handler = dummy_handler; sigemptyset(&temp.sa_mask); From 49dcacb2eca6f808f1f52a4faaf96f1fae24e4b5 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Thu, 5 May 2011 12:30:18 -0500 Subject: [PATCH 103/181] adjust rate offset and multiplier for espeak 1.45.04 --- espeak.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/espeak.c b/espeak.c index 5e69ac5..6c1bec5 100644 --- a/espeak.c +++ b/espeak.c @@ -34,8 +34,8 @@ char *defaultVoice = NULL; /* multipliers and offsets */ const int frequencyMultiplier = 11; const int pitchMultiplier = 11; -const int rateMultiplier = 34; -const int rateOffset = 84; +const int rateMultiplier = 41; +const int rateOffset = 80; const int volumeMultiplier = 22; volatile int stop_requested = 0; From 3353241a79f0e2b130dce5e98d656284a7da84f8 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Thu, 5 May 2011 14:12:40 -0500 Subject: [PATCH 104/181] add command line option to change the pid path This adds a -P or --pid-path option to the command line which allows the user to change the path and the name of the pid file created when espeakup is running as a daemon. I would like to thank Chris Brannon for the original idea for this. --- cli.c | 12 +++++++++++- espeakup.8 | 6 ++++++ espeakup.c | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/cli.c b/cli.c index 64cfd6b..1ad291c 100644 --- a/cli.c +++ b/cli.c @@ -24,12 +24,16 @@ #include "espeakup.h" +/* pid path */ +extern char *pidPath; + /* default voice */ extern char *defaultVoice; /* command line options */ -const char *shortOptions = "dhV:v"; +const char *shortOptions = "P:V:dhv"; const struct option longOptions[] = { + {"pid-path", required_argument, NULL, 'P'}, {"default-voice", required_argument, NULL, 'V'}, {"debug", no_argument, NULL, 'd'}, {"help", no_argument, NULL, 'h'}, @@ -61,10 +65,16 @@ static void show_version(void) void process_cli(int argc, char **argv) { int opt; + char *cp; do { opt = getopt_long(argc, argv, shortOptions, longOptions, NULL); switch (opt) { + case 'p': + cp = strdup(optarg); + if (cp != NULL) + pidPath = cp; + break; case 'V': defaultVoice = strdup(optarg); break; diff --git a/espeakup.8 b/espeakup.8 index 314aed7..092c776 100644 --- a/espeakup.8 +++ b/espeakup.8 @@ -9,6 +9,9 @@ espeakup \(em connect Speakup to the ESpeak TTS engine .SH SYNOPSIS .B espeakup [ +.B \-\^\-pid-path=path +] +[ .B \-\^\-default-voice=voicename ] [ @@ -22,6 +25,9 @@ espeakup \(em connect Speakup to the ESpeak TTS engine ] .SH OPTIONS .TP +.B \-P path, \-\^\-pid-path=path +Set the full path for the pid file espeakup uses when in daemon mode. +.TP .B \-V voicename, \-\^\-default-voice=voicename Set the espeak voice to be used by default. .TP diff --git a/espeakup.c b/espeakup.c index e059b84..40b4a64 100644 --- a/espeakup.c +++ b/espeakup.c @@ -27,7 +27,7 @@ #include "espeakup.h" /* path to our pid file */ -const char *pidPath = "/var/run/espeakup.pid"; +char *pidPath = "/var/run/espeakup.pid"; int debug = 0; struct queue_t *synth_queue = NULL; From 999e6551b5999f5779299e51858e4bbb587f5561 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Thu, 5 May 2011 14:50:23 -0500 Subject: [PATCH 105/181] add pid path option to help --- cli.c | 1 + 1 file changed, 1 insertion(+) diff --git a/cli.c b/cli.c index 1ad291c..1ddd34b 100644 --- a/cli.c +++ b/cli.c @@ -45,6 +45,7 @@ static void show_help() { printf("Usage: espeakup [options]\n\n"); printf("Options are as follows:\n"); + printf(" --pid-path=path, -P path\t\tSet path for pid file.\n"); printf(" --default-voice=voice, -V voice\tSet default voice.\n"); printf(" --debug, -d\t\t\t\tDebug mode (stay in the foreground).\n"); printf(" --help, -h\t\t\t\tShow this help.\n"); From 70f74657c274d37f94cf7a4eabcd1d06bafbfcb5 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Thu, 5 May 2011 14:52:05 -0500 Subject: [PATCH 106/181] fix Makefile to use MANMODE to install man pages --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9c156f6..1adde93 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ install: espeakup ${INSTALL} -d ${DESTDIR}${BINDIR} ${INSTALL} -m ${BINMODE} $< ${DESTDIR}${BINDIR} ${INSTALL} -d ${DESTDIR}${MANDIR}/man8 - ${INSTALL} -m 644 espeakup.8 ${DESTDIR}${MANDIR}/man8 + ${INSTALL} -m ${MANMODE} espeakup.8 ${DESTDIR}${MANDIR}/man8 espeakup: ${OBJS} From c06f18c4544a6e9e3d28b8f037bc40588fbff3f5 Mon Sep 17 00:00:00 2001 From: Christopher Brannon Date: Sun, 1 May 2011 15:40:44 +0000 Subject: [PATCH 107/181] support adapters using the acsint module --- cli.c | 6 ++- espeak.c | 27 +++++++++- espeakup.c | 3 +- espeakup.h | 6 +++ softsynth.c | 146 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 5 files changed, 181 insertions(+), 7 deletions(-) diff --git a/cli.c b/cli.c index 1ddd34b..033de09 100644 --- a/cli.c +++ b/cli.c @@ -31,10 +31,11 @@ extern char *pidPath; extern char *defaultVoice; /* command line options */ -const char *shortOptions = "P:V:dhv"; +const char *shortOptions = "P:V:adhv"; const struct option longOptions[] = { {"pid-path", required_argument, NULL, 'P'}, {"default-voice", required_argument, NULL, 'V'}, + {"acsint", no_argument, NULL, 'a'}, {"debug", no_argument, NULL, 'd'}, {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'v'}, @@ -79,6 +80,9 @@ void process_cli(int argc, char **argv) case 'V': defaultVoice = strdup(optarg); break; + case 'a': + espeakup_mode = ESPEAKUP_MODE_ACSINT; + break; case 'd': debug = 1; break; diff --git a/espeak.c b/espeak.c index 6c1bec5..510a44c 100644 --- a/espeak.c +++ b/espeak.c @@ -40,6 +40,21 @@ const int volumeMultiplier = 22; volatile int stop_requested = 0; +static int acsint_callback(short *wav, int numsamples, espeak_EVENT * events) +{ + int i; + for (i = 0; events[i].type != espeakEVENT_LIST_TERMINATED; i++) { + if (events[i].type == espeakEVENT_MARK) { + int mark = atoi(events[i].id.name); + if ((mark < 0) || (mark > 255)) + continue; + putchar(mark); + fflush(stdout); + } + } + return 0; +} + static espeak_ERROR set_frequency(struct synth_t *s, int freq, enum adjust_t adj) { @@ -139,9 +154,13 @@ static espeak_ERROR stop_speech(void) static espeak_ERROR speak_text(struct synth_t *s) { espeak_ERROR rc; + int synth_mode = 0; - rc = espeak_Synth(s->buf, s->len + 1, 0, POS_CHARACTER, 0, 0, NULL, - NULL); + if (espeakup_mode == ESPEAKUP_MODE_ACSINT) + synth_mode |= espeakSSML; + + rc = espeak_Synth(s->buf, s->len + 1, 0, POS_CHARACTER, 0, synth_mode, + NULL, NULL); return rc; } @@ -219,6 +238,10 @@ int initialize_espeak(struct synth_t *s) return -1; } + /* We need a callback in acsint mode, but not in speakup mode. */ + if (espeakup_mode == ESPEAKUP_MODE_ACSINT) + espeak_SetSynthCallback(acsint_callback); + /* Setup initial voice parameters */ if (defaultVoice) { set_voice(s, defaultVoice); diff --git a/espeakup.c b/espeakup.c index 40b4a64..124fcc3 100644 --- a/espeakup.c +++ b/espeakup.c @@ -30,6 +30,7 @@ char *pidPath = "/var/run/espeakup.pid"; int debug = 0; +enum espeakup_mode_t espeakup_mode = ESPEAKUP_MODE_SPEAKUP; struct queue_t *synth_queue = NULL; int self_pipe_fds[2]; @@ -99,7 +100,7 @@ int main(int argc, char **argv) /* * If we are not in debug mode, become a daemon and store the pid. */ - if (!debug) { + if (espeakup_mode != ESPEAKUP_MODE_ACSINT && !debug) { daemon(0, 1); if (create_pid_file() < 0) { perror("Unable to create pid file"); diff --git a/espeakup.h b/espeakup.h index 8cd318a..57a3f29 100644 --- a/espeakup.h +++ b/espeakup.h @@ -31,6 +31,11 @@ #define PACKAGE_VERSION "0.80-dev" #define PACKAGE_BUGREPORT "http://github.com/williamh/espeakup/issues" +enum espeakup_mode_t { + ESPEAKUP_MODE_SPEAKUP, + ESPEAKUP_MODE_ACSINT +}; + enum command_t { CMD_SET_FREQUENCY, CMD_SET_PITCH, @@ -70,6 +75,7 @@ struct synth_t { extern struct queue_t *synth_queue; extern int debug; +extern enum espeakup_mode_t espeakup_mode; extern void process_cli(int argc, char **argv); extern void *signal_thread(void *arg); diff --git a/softsynth.c b/softsynth.c index 9747963..d70c381 100644 --- a/softsynth.c +++ b/softsynth.c @@ -28,13 +28,103 @@ #include "espeakup.h" /* max buffer size */ -static const size_t maxBufferSize = 1025; +/* A big fat buffer. */ +static const size_t maxBufferSize = 16 * 1024 + 1; /* synth flush character */ static const int synthFlushChar = 0x18; + static int softFD = 0; +/* Text accumulator: */ +char *textAccumulator; +int textAccumulator_l; + +/* String routines, borrowed from edbrowse: */ +char *EMPTYSTRING = ""; + +void *allocMem(size_t n) +{ + void *s; + if (!n) + return EMPTYSTRING; + if (!(s = malloc(n))) { + fprintf(stderr, "Out of memory!\n"); + exit(1); + } + return s; +} /* allocMem */ + +void *reallocMem(void *p, size_t n) +{ + void *s; + if (!n) { + fprintf(stderr, "Trying to reallocate memory with size of 0.\n"); + exit(1); + } + if (!p) { + fprintf(stderr, "realloc called with a NULL pointer!\n"); + exit(1); + } + if (p == EMPTYSTRING) + return allocMem(n); + if (!(s = realloc(p, n))) { + fprintf(stderr, "Failed to allocate memory.\n"); + exit(1); + } + return s; +} /* reallocMem */ + +char *initString(int *l) +{ + *l = 0; + return EMPTYSTRING; +} + +void stringAndString(char **s, int *l, const char *t) +{ + char *p = *s; + int oldlen, newlen, x; + oldlen = *l; + newlen = oldlen + strlen(t); + *l = newlen; + ++newlen; /* room for the 0 */ + x = oldlen ^ newlen; + if (x > oldlen) { /* must realloc */ + newlen |= (newlen >> 1); + newlen |= (newlen >> 2); + newlen |= (newlen >> 4); + newlen |= (newlen >> 8); + newlen |= (newlen >> 16); + p = reallocMem(p, newlen); + *s = p; + } + strcpy(p + oldlen, t); +} /* stringAndString */ + +void stringAndBytes(char **s, int *l, const char *t, int cnt) +{ + char *p = *s; + int oldlen, newlen, x; + oldlen = *l; + newlen = oldlen + cnt; + *l = newlen; + ++newlen; + x = oldlen ^ newlen; + if (x > oldlen) { /* must realloc */ + newlen |= (newlen >> 1); + newlen |= (newlen >> 2); + newlen |= (newlen >> 4); + newlen |= (newlen >> 8); + newlen |= (newlen >> 16); + p = reallocMem(p, newlen); + *s = p; + } + memcpy(p + oldlen, t, cnt); + p[oldlen + cnt] = 0; +} /* stringAndBytes */ + static void queue_add_cmd(enum command_t cmd, enum adjust_t adj, int value) { struct espeak_entry_t *entry; @@ -147,8 +237,15 @@ static int process_command(struct synth_t *s, char *buf, int start) break; } - if (cmd != CMD_FLUSH && cmd != CMD_UNKNOWN) + if (cmd != CMD_FLUSH && cmd != CMD_UNKNOWN) { + if (espeakup_mode == ESPEAKUP_MODE_ACSINT + && textAccumulator_l != 0) { + queue_add_text(textAccumulator, textAccumulator_l); + free(textAccumulator); + textAccumulator = initString(&textAccumulator_l); + } queue_add_cmd(cmd, adj, value); + } return cp - (buf + start); } @@ -178,6 +275,38 @@ static void process_buffer(struct synth_t *s, char *buf, ssize_t length) } } +static void process_buffer_acsint(struct synth_t *s, char *buf, + ssize_t length) +{ + int start = 0; + int i; + int flushIt = 0; + + while (start < length) { + for (i = start; i < length; i++) { + if (buf[i] == '\r' || buf[i] == '\n') + flushIt = 1; + if (buf[i] >= 0 && buf[i] < ' ') + break; + } + if (i > start) + stringAndBytes(&textAccumulator, &textAccumulator_l, + buf + start, i - start); + if (flushIt) { + if (textAccumulator != EMPTYSTRING) { + queue_add_text(textAccumulator, textAccumulator_l); + free(textAccumulator); + textAccumulator = initString(&textAccumulator_l); + } + flushIt = 0; + } + if (i < length) + start = i = i + process_command(s, buf, i); + else + start = length; + } +} + static void request_espeak_stop(void) { pthread_mutex_lock(&queue_guard); @@ -191,6 +320,12 @@ static void request_espeak_stop(void) int open_softsynth(void) { int rc = 0; + /* If we're in acsint mode, we read from stdin. No need to open. */ + if (espeakup_mode == ESPEAKUP_MODE_ACSINT) { + softFD = STDIN_FILENO; + return 0; + } + /* open the softsynth. */ softFD = open("/dev/softsynth", O_RDWR | O_NONBLOCK); if (softFD < 0) { @@ -216,6 +351,8 @@ void *softsynth_thread(void *arg) int terminalFD = PIPE_READ_FD; int greatestFD; + textAccumulator = initString(&textAccumulator_l); + if (terminalFD > softFD) greatestFD = terminalFD; else @@ -264,7 +401,10 @@ void *softsynth_thread(void *arg) memmove(buf, cp + 1, strlen(cp + 1) + 1); length = strlen(buf); } - process_buffer(s, buf, length); + if (espeakup_mode == ESPEAKUP_MODE_SPEAKUP) + process_buffer(s, buf, length); + else + process_buffer_acsint(s, buf, length); pthread_mutex_lock(&queue_guard); } pthread_cond_signal(&runner_awake); From ba316a4cd4ad42b5cf7a550953c1dc26338e3569 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Thu, 5 May 2011 17:26:31 -0500 Subject: [PATCH 108/181] separate string handling routines into their own module --- Makefile | 3 +- softsynth.c | 87 +----------------------------------- stringhandling.c | 112 +++++++++++++++++++++++++++++++++++++++++++++++ stringhandling.h | 31 +++++++++++++ 4 files changed, 146 insertions(+), 87 deletions(-) create mode 100644 stringhandling.c create mode 100644 stringhandling.h diff --git a/Makefile b/Makefile index 1adde93..b499454 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,8 @@ SRCS = cli.c \ espeakup.c \ queue.c \ signal.c \ - softsynth.c + softsynth.c \ + stringhandling.c OBJS = ${SRCS:.c=.o} diff --git a/softsynth.c b/softsynth.c index d70c381..0b9f76f 100644 --- a/softsynth.c +++ b/softsynth.c @@ -26,105 +26,20 @@ #include #include "espeakup.h" +#include "stringhandling.h" /* max buffer size */ -/* A big fat buffer. */ static const size_t maxBufferSize = 16 * 1024 + 1; /* synth flush character */ static const int synthFlushChar = 0x18; - static int softFD = 0; /* Text accumulator: */ char *textAccumulator; int textAccumulator_l; -/* String routines, borrowed from edbrowse: */ -char *EMPTYSTRING = ""; - -void *allocMem(size_t n) -{ - void *s; - if (!n) - return EMPTYSTRING; - if (!(s = malloc(n))) { - fprintf(stderr, "Out of memory!\n"); - exit(1); - } - return s; -} /* allocMem */ - -void *reallocMem(void *p, size_t n) -{ - void *s; - if (!n) { - fprintf(stderr, "Trying to reallocate memory with size of 0.\n"); - exit(1); - } - if (!p) { - fprintf(stderr, "realloc called with a NULL pointer!\n"); - exit(1); - } - if (p == EMPTYSTRING) - return allocMem(n); - if (!(s = realloc(p, n))) { - fprintf(stderr, "Failed to allocate memory.\n"); - exit(1); - } - return s; -} /* reallocMem */ - -char *initString(int *l) -{ - *l = 0; - return EMPTYSTRING; -} - -void stringAndString(char **s, int *l, const char *t) -{ - char *p = *s; - int oldlen, newlen, x; - oldlen = *l; - newlen = oldlen + strlen(t); - *l = newlen; - ++newlen; /* room for the 0 */ - x = oldlen ^ newlen; - if (x > oldlen) { /* must realloc */ - newlen |= (newlen >> 1); - newlen |= (newlen >> 2); - newlen |= (newlen >> 4); - newlen |= (newlen >> 8); - newlen |= (newlen >> 16); - p = reallocMem(p, newlen); - *s = p; - } - strcpy(p + oldlen, t); -} /* stringAndString */ - -void stringAndBytes(char **s, int *l, const char *t, int cnt) -{ - char *p = *s; - int oldlen, newlen, x; - oldlen = *l; - newlen = oldlen + cnt; - *l = newlen; - ++newlen; - x = oldlen ^ newlen; - if (x > oldlen) { /* must realloc */ - newlen |= (newlen >> 1); - newlen |= (newlen >> 2); - newlen |= (newlen >> 4); - newlen |= (newlen >> 8); - newlen |= (newlen >> 16); - p = reallocMem(p, newlen); - *s = p; - } - memcpy(p + oldlen, t, cnt); - p[oldlen + cnt] = 0; -} /* stringAndBytes */ - static void queue_add_cmd(enum command_t cmd, enum adjust_t adj, int value) { struct espeak_entry_t *entry; diff --git a/stringhandling.c b/stringhandling.c new file mode 100644 index 0000000..8c18a39 --- /dev/null +++ b/stringhandling.c @@ -0,0 +1,112 @@ +/* + * espeakup - interface which allows speakup to use espeak + * + * Copyright (C) 2011 William Hubbs + * + * This program 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. + * + * This program 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 this program. If not, see . + */ + +/* + * These string routines were borrowed from edbrowse, which was + * originally written by Karl Dahlke, and is being currently maintained + * by Christopher Brannon. + * I would like to thank both of them for their work on this software. + */ + +#include +#include +#include + +char *EMPTYSTRING = ""; + +void *allocMem(size_t n) +{ + void *s; + if (!n) + return EMPTYSTRING; + if (!(s = malloc(n))) { + fprintf(stderr, "Out of memory!\n"); + exit(1); + } + return s; +} + +void *reallocMem(void *p, size_t n) +{ + void *s; + if (!n) { + fprintf(stderr, "Trying to reallocate memory with size of 0.\n"); + exit(1); + } + if (!p) { + fprintf(stderr, "realloc called with a NULL pointer!\n"); + exit(1); + } + if (p == EMPTYSTRING) + return allocMem(n); + if (!(s = realloc(p, n))) { + fprintf(stderr, "Failed to allocate memory.\n"); + exit(1); + } + return s; +} + +char *initString(int *l) +{ + *l = 0; + return EMPTYSTRING; +} + +void stringAndString(char **s, int *l, const char *t) +{ + char *p = *s; + int oldlen, newlen, x; + oldlen = *l; + newlen = oldlen + strlen(t); + *l = newlen; + ++newlen; /* room for the 0 */ + x = oldlen ^ newlen; + if (x > oldlen) { /* must realloc */ + newlen |= (newlen >> 1); + newlen |= (newlen >> 2); + newlen |= (newlen >> 4); + newlen |= (newlen >> 8); + newlen |= (newlen >> 16); + p = reallocMem(p, newlen); + *s = p; + } + strcpy(p + oldlen, t); +} + +void stringAndBytes(char **s, int *l, const char *t, int cnt) +{ + char *p = *s; + int oldlen, newlen, x; + oldlen = *l; + newlen = oldlen + cnt; + *l = newlen; + ++newlen; + x = oldlen ^ newlen; + if (x > oldlen) { /* must realloc */ + newlen |= (newlen >> 1); + newlen |= (newlen >> 2); + newlen |= (newlen >> 4); + newlen |= (newlen >> 8); + newlen |= (newlen >> 16); + p = reallocMem(p, newlen); + *s = p; + } + memcpy(p + oldlen, t, cnt); + p[oldlen + cnt] = 0; +} diff --git a/stringhandling.h b/stringhandling.h new file mode 100644 index 0000000..1353391 --- /dev/null +++ b/stringhandling.h @@ -0,0 +1,31 @@ +/* + * espeakup - interface which allows speakup to use espeak + * + * Copyright (C) 2011 William Hubbs + * + * This program 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. + * + * This program 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 this program. If not, see . + */ + +#ifndef __STRINGHANDLING_H +#define __STRINGHANDLING_H + +extern char *EMPTYSTRING; + +void *allocMem(size_t n); +void *reallocMem(void *p, size_t n); +char *initString(int *l); +void stringAndString(char **s, int *l, const char *t); +void stringAndBytes(char **s, int *l, const char *t, int cnt); + +#endif From 6180ff6e49371d9fc1cfb5afb05941222d925d70 Mon Sep 17 00:00:00 2001 From: Christopher Brannon Date: Fri, 6 May 2011 14:27:12 +0000 Subject: [PATCH 109/181] Don't check to see if espeakup is running in acsint mode. This check is important when running with speakup, since there can only be one instance accessing /dev/softsynth. It is unnecessary in acsint mode. --- espeakup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/espeakup.c b/espeakup.c index 124fcc3..dff917c 100644 --- a/espeakup.c +++ b/espeakup.c @@ -92,7 +92,7 @@ int main(int argc, char **argv) process_cli(argc, argv); /* Is the espeakup daemon running? */ - if (espeakup_is_running()) { + if (espeakup_mode != ESPEAKUP_MODE_ACSINT && espeakup_is_running()) { printf("Espeakup is already running!\n"); return 1; } From 3b4b6d0cbc98d175f00a9f1e744406e3491c6d85 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Fri, 6 May 2011 23:08:33 -0500 Subject: [PATCH 110/181] change code to use allocMem wrapper for memory allocation One of the new string handling routines is a wrapper for allocating memory. This commit changes the rest of the code to take advantage of that wrapper. --- queue.c | 18 ++++++------------ softsynth.c | 12 ++---------- stringhandling.h | 2 ++ 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/queue.c b/queue.c index e1827da..860ad94 100644 --- a/queue.c +++ b/queue.c @@ -22,9 +22,9 @@ */ #include -#include #include -#include + +#include "stringhandling.h" struct queue_entry_t { void *data; @@ -38,11 +38,9 @@ struct queue_t { struct queue_t *new_queue(void) { - struct queue_t *q = malloc(sizeof(struct queue_t)); - if (q) { - q->head = NULL; - q->tail = NULL; - } + struct queue_t *q = allocMem(sizeof(struct queue_t)); + q->head = NULL; + q->tail = NULL; return q; } @@ -51,11 +49,7 @@ int queue_add(struct queue_t *q, void *data) struct queue_entry_t *tmp; assert(data); - tmp = malloc(sizeof(struct queue_entry_t)); - if (!tmp) { - printf("Unable to allocate memory for queue entry.\n"); - return 0; - } + tmp = allocMem(sizeof(struct queue_entry_t)); tmp->data = data; tmp->next = NULL; if (!q->tail) { diff --git a/softsynth.c b/softsynth.c index 0b9f76f..9c5af80 100644 --- a/softsynth.c +++ b/softsynth.c @@ -45,11 +45,7 @@ static void queue_add_cmd(enum command_t cmd, enum adjust_t adj, int value) struct espeak_entry_t *entry; int added = 0; - entry = malloc(sizeof(struct espeak_entry_t)); - if (!entry) { - perror("unable to allocate memory for queue entry"); - return; - } + entry = allocMem(sizeof(struct espeak_entry_t)); entry->cmd = cmd; entry->adjust = adj; entry->value = value; @@ -67,11 +63,7 @@ static void queue_add_text(char *txt, size_t length) struct espeak_entry_t *entry; int added = 0; - entry = malloc(sizeof(struct espeak_entry_t)); - if (!entry) { - perror("unable to allocate memory for queue entry"); - return; - } + entry = allocMem(sizeof(struct espeak_entry_t)); entry->cmd = CMD_SPEAK_TEXT; entry->adjust = ADJ_SET; entry->buf = strdup(txt); diff --git a/stringhandling.h b/stringhandling.h index 1353391..a7d7cea 100644 --- a/stringhandling.h +++ b/stringhandling.h @@ -20,6 +20,8 @@ #ifndef __STRINGHANDLING_H #define __STRINGHANDLING_H +#include + extern char *EMPTYSTRING; void *allocMem(size_t n); From b2bd1d33a8a8d08ea9316bcf3cf8169545e7df78 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Fri, 6 May 2011 23:43:39 -0500 Subject: [PATCH 111/181] make espeakup's default rate closer to espeak's default --- espeak.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/espeak.c b/espeak.c index 510a44c..8015fc4 100644 --- a/espeak.c +++ b/espeak.c @@ -27,7 +27,7 @@ /* default voice settings */ const int defaultFrequency = 5; const int defaultPitch = 5; -const int defaultRate = 5; +const int defaultRate = 2; const int defaultVolume = 5; char *defaultVoice = NULL; From 58ed438f00c0f79c87885b73292c3b4e5c44e0d4 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Sat, 7 May 2011 10:35:57 -0500 Subject: [PATCH 112/181] rework two if statements These if statements were executing code if we were not in acsint mode. They have been combined and the code is now executed when we are in speakup mode, which is what we want. --- espeakup.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/espeakup.c b/espeakup.c index dff917c..9d1f06c 100644 --- a/espeakup.c +++ b/espeakup.c @@ -91,20 +91,22 @@ int main(int argc, char **argv) /* process command line options */ process_cli(argc, argv); - /* Is the espeakup daemon running? */ - if (espeakup_mode != ESPEAKUP_MODE_ACSINT && espeakup_is_running()) { - printf("Espeakup is already running!\n"); - return 1; - } + if (espeakup_mode == ESPEAKUP_MODE_SPEAKUP) { + /* Is the espeakup daemon running? */ + if (espeakup_is_running()) { + printf("Espeakup is already running!\n"); + return 1; + } -/* - * If we are not in debug mode, become a daemon and store the pid. - */ - if (espeakup_mode != ESPEAKUP_MODE_ACSINT && !debug) { - daemon(0, 1); - if (create_pid_file() < 0) { - perror("Unable to create pid file"); - return 2; + /* + * If we are not in debug mode, daemonize and store the pid. + */ + if (!debug) { + daemon(0, 1); + if (create_pid_file() < 0) { + perror("Unable to create pid file"); + return 2; + } } } From 3fbbdf19224c26b80b161666b37cec70ac5dd6d2 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Sat, 7 May 2011 10:44:05 -0500 Subject: [PATCH 113/181] Do not try to remove the pid file unless we are in speakup mode --- espeakup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/espeakup.c b/espeakup.c index 9d1f06c..ffb2e42 100644 --- a/espeakup.c +++ b/espeakup.c @@ -160,7 +160,7 @@ int main(int argc, char **argv) espeak_Terminate(); close_softsynth(); - if (!debug) + if (!debug && espeakup_mode == ESPEAKUP_MODE_SPEAKUP) unlink(pidPath); return 0; } From e84e000b3ec9d393d720845a5f5fd05aa2ee7302 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Mon, 9 May 2011 21:47:56 -0500 Subject: [PATCH 114/181] add indexing support --- espeak.c | 6 ++++++ espeakup.h | 1 + softsynth.c | 3 +++ 3 files changed, 10 insertions(+) diff --git a/espeak.c b/espeak.c index 8015fc4..b192177 100644 --- a/espeak.c +++ b/espeak.c @@ -185,6 +185,7 @@ static void synth_queue_clear() static void queue_process_entry(struct synth_t *s) { espeak_ERROR error; + char markbuff[50]; static struct espeak_entry_t *current = NULL; if (current != queue_peek(synth_queue)) { @@ -197,6 +198,11 @@ static void queue_process_entry(struct synth_t *s) case CMD_SET_FREQUENCY: error = set_frequency(s, current->value, current->adjust); break; + case CMD_SET_MARK: + sprintf(markbuff, "", current->value); + error = espeak_Synth(markbuff, strlen(markbuff)+1, 0, POS_CHARACTER, + 0, espeakSSML, NULL, NULL); + break; case CMD_SET_PITCH: error = set_pitch(s, current->value, current->adjust); break; diff --git a/espeakup.h b/espeakup.h index 57a3f29..38187ac 100644 --- a/espeakup.h +++ b/espeakup.h @@ -38,6 +38,7 @@ enum espeakup_mode_t { enum command_t { CMD_SET_FREQUENCY, + CMD_SET_MARK, CMD_SET_PITCH, CMD_SET_PUNCTUATION, CMD_SET_RATE, diff --git a/softsynth.c b/softsynth.c index 9c5af80..a2c281b 100644 --- a/softsynth.c +++ b/softsynth.c @@ -123,6 +123,9 @@ static int process_command(struct synth_t *s, char *buf, int start) case 'f': cmd = CMD_SET_FREQUENCY; break; + case 'i': + cmd = CMD_SET_MARK; + break; case 'p': cmd = CMD_SET_PITCH; break; From d95ee07775f6a63d80323e5ea242c530adf9c79b Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Mon, 9 May 2011 22:22:14 -0500 Subject: [PATCH 115/181] Revert "add indexing support" This reverts commit e84e000b3ec9d393d720845a5f5fd05aa2ee7302. I need to think more about how to implement this. --- espeak.c | 6 ------ espeakup.h | 1 - softsynth.c | 3 --- 3 files changed, 10 deletions(-) diff --git a/espeak.c b/espeak.c index b192177..8015fc4 100644 --- a/espeak.c +++ b/espeak.c @@ -185,7 +185,6 @@ static void synth_queue_clear() static void queue_process_entry(struct synth_t *s) { espeak_ERROR error; - char markbuff[50]; static struct espeak_entry_t *current = NULL; if (current != queue_peek(synth_queue)) { @@ -198,11 +197,6 @@ static void queue_process_entry(struct synth_t *s) case CMD_SET_FREQUENCY: error = set_frequency(s, current->value, current->adjust); break; - case CMD_SET_MARK: - sprintf(markbuff, "", current->value); - error = espeak_Synth(markbuff, strlen(markbuff)+1, 0, POS_CHARACTER, - 0, espeakSSML, NULL, NULL); - break; case CMD_SET_PITCH: error = set_pitch(s, current->value, current->adjust); break; diff --git a/espeakup.h b/espeakup.h index 38187ac..57a3f29 100644 --- a/espeakup.h +++ b/espeakup.h @@ -38,7 +38,6 @@ enum espeakup_mode_t { enum command_t { CMD_SET_FREQUENCY, - CMD_SET_MARK, CMD_SET_PITCH, CMD_SET_PUNCTUATION, CMD_SET_RATE, diff --git a/softsynth.c b/softsynth.c index a2c281b..9c5af80 100644 --- a/softsynth.c +++ b/softsynth.c @@ -123,9 +123,6 @@ static int process_command(struct synth_t *s, char *buf, int start) case 'f': cmd = CMD_SET_FREQUENCY; break; - case 'i': - cmd = CMD_SET_MARK; - break; case 'p': cmd = CMD_SET_PITCH; break; From d97724373556e5ad6d632249bcc0ba4ef7aec4d8 Mon Sep 17 00:00:00 2001 From: Christopher Brannon Date: Sun, 14 Jun 2015 13:57:50 -0700 Subject: [PATCH 116/181] Add a missing #include, so that this can be built with musl. This closes #5. --- softsynth.c | 1 + 1 file changed, 1 insertion(+) diff --git a/softsynth.c b/softsynth.c index 9c5af80..3394434 100644 --- a/softsynth.c +++ b/softsynth.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include From c1ad891f2e321b052802a2c3c121522757948e61 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Thu, 10 Mar 2016 08:10:30 -0600 Subject: [PATCH 117/181] Create pid file when espeakup is really ready This makes sure that we do not report that we are ready until everything is initialized. --- espeakup.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/espeakup.c b/espeakup.c index ffb2e42..8a55b0c 100644 --- a/espeakup.c +++ b/espeakup.c @@ -98,15 +98,9 @@ int main(int argc, char **argv) return 1; } - /* - * If we are not in debug mode, daemonize and store the pid. - */ + /* Daemonize if we are not in debug mode. */ if (!debug) { daemon(0, 1); - if (create_pid_file() < 0) { - perror("Unable to create pid file"); - return 2; - } } } @@ -153,6 +147,14 @@ int main(int argc, char **argv) return 4; } + /* Store the pid */ + if (!debug && espeakup_mode == ESPEAKUP_MODE_SPEAKUP) { + if (create_pid_file() < 0) { + perror("Unable to create pid file"); + return 2; + } + } + /* wait for the threads to shut down. */ pthread_join(signal_thread_id, NULL); pthread_join(softsynth_thread_id, NULL); From ee099174d849e32bf7b555e458963d27f84c64b2 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Thu, 10 Mar 2016 08:20:45 -0600 Subject: [PATCH 118/181] Allow a voice to be selected by language name This allows the -V option on the command line to be a language name. --- espeak.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/espeak.c b/espeak.c index 8015fc4..fb973e7 100644 --- a/espeak.c +++ b/espeak.c @@ -119,8 +119,15 @@ static espeak_ERROR set_rate(struct synth_t *s, int rate, static espeak_ERROR set_voice(struct synth_t *s, char *voice) { espeak_ERROR rc; + espeak_VOICE voice_select; rc = espeak_SetVoiceByName(voice); + if (rc != EE_OK) + { + memset(&voice_select, 0, sizeof(voice_select)); + voice_select.languages = voice; + rc = espeak_SetVoiceByProperties(&voice_select); + } if (rc == EE_OK) strcpy(s->voice, voice); return rc; From 92903254894d2b6f2c398a104e78d15553de6017 Mon Sep 17 00:00:00 2001 From: Christopher Brannon Date: Thu, 10 Mar 2016 10:11:54 -0800 Subject: [PATCH 119/181] Fix spelling keystrokes and char-by-char echo. Use ssml's interpret-as="characters" setting when the kernel reports just one character. This allows the use of espeak's internationalized spelling of letters instead of having to maintain spelling ourselves in speakup. Original patch courtesy of Samuel Thibault and modified to work with the current code by Chris. This fixes #6. --- espeak.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/espeak.c b/espeak.c index fb973e7..0aa6a62 100644 --- a/espeak.c +++ b/espeak.c @@ -166,8 +166,25 @@ static espeak_ERROR speak_text(struct synth_t *s) if (espeakup_mode == ESPEAKUP_MODE_ACSINT) synth_mode |= espeakSSML; - rc = espeak_Synth(s->buf, s->len + 1, 0, POS_CHARACTER, 0, synth_mode, - NULL, NULL); + if (espeakup_mode == ESPEAKUP_MODE_SPEAKUP && (s->len == 1)) { + char *buf; + int n; + n = asprintf(&buf, + "%c", + s->buf[0]); + if (n == -1) { + /* D'oh. Not much to do on allocation failure. + * Perhaps espeak will happen to say the character */ + rc = espeak_Synth(s->buf, s->len + 1, 0, POS_CHARACTER, + 0, synth_mode, NULL, NULL); + } else { + rc = espeak_Synth(buf, n + 1, 0, POS_CHARACTER, 0, + espeakSSML, NULL, NULL); + free(buf); + } + } else + rc = espeak_Synth(s->buf, s->len + 1, 0, POS_CHARACTER, 0, + synth_mode, NULL, NULL); return rc; } From 97adab70de5e49dde3ac26774a636cbca48558c0 Mon Sep 17 00:00:00 2001 From: Christopher Brannon Date: Thu, 21 Jul 2016 03:04:50 -0700 Subject: [PATCH 120/181] Replace usage of daemon(3). Original patch and commit message courtesy of: Samuel Thibault currently espeakup uses daemon() to do the daemonizing stuff. Unfortunately, daemon() does things not very appropriately, and there is notably a delay between the parent exit()ing and the child writing the pid file. The attached patch reimplements it properly, espeakup then notably plays much more nicely with systemd. Modified by Chris to apply to master. This fixes #8. --- espeakup.c | 175 ++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 127 insertions(+), 48 deletions(-) diff --git a/espeakup.c b/espeakup.c index 8a55b0c..1981430 100644 --- a/espeakup.c +++ b/espeakup.c @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include "espeakup.h" @@ -41,38 +43,103 @@ pthread_cond_t runner_awake = PTHREAD_COND_INITIALIZER; pthread_cond_t stop_acknowledged = PTHREAD_COND_INITIALIZER; pthread_mutex_t queue_guard = PTHREAD_MUTEX_INITIALIZER; -int espeakup_is_running(void) +int espeakup_start_daemon(void) { - int rc; - FILE *pidFile; + int fds[2]; pid_t pid; + char c; - rc = 0; - pidFile = fopen(pidPath, "r"); - if (pidFile) { - fscanf(pidFile, "%d", &pid); - fclose(pidFile); - if (!kill(pid, 0) || errno != ESRCH) - rc = 1; + if (pipe(fds) < 0) { + perror("pipe"); + exit(1); } - return rc; + pid = fork(); + + if (pid < 0) { + perror("fork"); + exit(1); + } + if (pid) { + /* Parent, just wait for daemon */ + if (read(fds[0], &c, 1) < 0) { + printf("Espeakup is already running!\n"); + exit(1); + } + exit(c); + } + + /* Child, create new session */ + setsid(); + pid = fork(); + if (pid) + /* Intermediate child, just exit */ + exit(0); + + /* Child */ + if (chdir("/") < 0) { + c = 1; + (void)write(fds[1], &c, 1); + exit(1); + } + return fds[1]; } -int create_pid_file(void) +int espeakup_is_running(void) { - FILE *pidFile; + int pidFile; + int n; + char s[16]; + pid_t pid; - pidFile = fopen(pidPath, "w"); - if (!pidFile) + pidFile = open(pidPath, O_RDWR | O_CREAT, 0666); + if (pidFile < 0) { + printf("Can not work with the pid file %s: %s\n", pidPath, + strerror(errno)); return -1; + } - fprintf(pidFile, "%d\n", getpid()); - fclose(pidFile); + if (flock(pidFile, LOCK_EX) < 0) { + printf("Can not lock the pid file %s: %s\n", pidPath, + strerror(errno)); + goto error; + } + n = read(pidFile, s, sizeof(s) - 1); + if (n < 0) { + printf("Can not read the pid file %s: %s\n", pidPath, + strerror(errno)); + goto error; + } + s[n] = 0; + n = sscanf(s, "%d", &pid); + if (n == 1 && (!kill(pid, 0) || errno != ESRCH)) { + /* Already running */ + close(pidFile); + return 1; + } + if (ftruncate(pidFile, 0) < 0) { + printf("Could not truncate the pid file %s: %s\n", pidPath, + strerror(errno)); + goto error; + } + lseek(pidFile, 0, SEEK_SET); + n = snprintf(s, sizeof(s), "%d", getpid()); + if (write(pidFile, s, n) < 0) { + printf("Could not write to the pid file %s: %s\n", pidPath, + strerror(errno)); + goto error; + } + close(pidFile); return 0; + +error: + close(pidFile); + return -1; } int main(int argc, char **argv) { + int fd, devnull; + char ret = 0; sigset_t sigset; int err; pthread_t signal_thread_id; @@ -88,32 +155,37 @@ int main(int argc, char **argv) return 2; } - /* process command line options */ - process_cli(argc, argv); - - if (espeakup_mode == ESPEAKUP_MODE_SPEAKUP) { - /* Is the espeakup daemon running? */ - if (espeakup_is_running()) { - printf("Espeakup is already running!\n"); - return 1; - } - - /* Daemonize if we are not in debug mode. */ - if (!debug) { - daemon(0, 1); - } - } - /* set up the pipe used to wake the espeak thread */ if (pipe(self_pipe_fds) < 0) { perror("Unable to create pipe"); return 5; } + /* process command line options */ + process_cli(argc, argv); + + if (!debug && espeakup_mode == ESPEAKUP_MODE_SPEAKUP) { + fd = espeakup_start_daemon(); + + if (espeakup_is_running()) { + printf("Espeakup is already running!\n"); + ret = 1; + goto out; + } + + devnull = open("/dev/null", O_RDWR); + dup2(devnull, STDIN_FILENO); + dup2(devnull, STDOUT_FILENO); + dup2(devnull, STDERR_FILENO); + if (devnull > 2) + close(devnull); + } + /* create the signal processing thread here. */ err = pthread_create(&signal_thread_id, NULL, signal_thread, NULL); if (err != 0) { - return 4; + ret = 4; + goto out; } /* @@ -127,33 +199,32 @@ int main(int argc, char **argv) /* Initialize espeak */ if (initialize_espeak(&s) < 0) { - return 2; + ret = 2; + goto out; } /* open the softsynth */ if (open_softsynth() < 0) { - return 2; + ret = 2; + goto out; } /* Spawn our softsynth thread. */ err = pthread_create(&softsynth_thread_id, NULL, softsynth_thread, &s); if (err != 0) { - return 4; + ret = 4; + goto out; } /* Spawn our espeak-interacting thread. */ err = pthread_create(&espeak_thread_id, NULL, espeak_thread, &s); if (err != 0) { - return 4; + ret = 4; + goto out; } - /* Store the pid */ - if (!debug && espeakup_mode == ESPEAKUP_MODE_SPEAKUP) { - if (create_pid_file() < 0) { - perror("Unable to create pid file"); - return 2; - } - } + if (!debug && espeakup_mode == ESPEAKUP_MODE_SPEAKUP) + (void)write(fd, &ret, 1); /* wait for the threads to shut down. */ pthread_join(signal_thread_id, NULL); @@ -162,7 +233,15 @@ int main(int argc, char **argv) espeak_Terminate(); close_softsynth(); - if (!debug && espeakup_mode == ESPEAKUP_MODE_SPEAKUP) - unlink(pidPath); - return 0; + +out: + if (!debug && espeakup_mode == ESPEAKUP_MODE_SPEAKUP) { + if (ret != 1) + unlink(pidPath); + if (ret != 0) + (void)write(fd, &ret, 1); + /* If ret was 0, the status byte was written before joining + * the threads. */ + } + return ret; } From 8b49d9d211f917f7ee2009569f746659ec9096a8 Mon Sep 17 00:00:00 2001 From: Christopher Brannon Date: Thu, 21 Jul 2016 05:56:43 -0700 Subject: [PATCH 121/181] Fix implicit function declaration warning. This fixes #7 --- espeak.c | 1 + 1 file changed, 1 insertion(+) diff --git a/espeak.c b/espeak.c index 0aa6a62..f09d3c4 100644 --- a/espeak.c +++ b/espeak.c @@ -17,6 +17,7 @@ * along with this program. If not, see . */ +#define _GNU_SOURCE #include #include #include From 3e5815429bd702d9b0af68d793e6c83f035f9e23 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Sun, 24 Jul 2016 21:38:44 -0500 Subject: [PATCH 122/181] Add my email address to the copyright statement --- cli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli.c b/cli.c index 033de09..31db4b0 100644 --- a/cli.c +++ b/cli.c @@ -57,7 +57,7 @@ static void show_help() static void show_version(void) { printf("ESpeakup %s\n", PACKAGE_VERSION); - printf("Copyright (C) 2008 William Hubbs\n"); + printf("Copyright (C) 2008 William Hubbs \n"); printf("License GPLv3+: GNU GPL version 3 or later\n"); printf("You are free to change and redistribute this software.\n"); printf("Please report bugs to %s\n", PACKAGE_BUGREPORT); From 918e8853cdd8270c77f641c69871851effe18416 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Sun, 24 Jul 2016 21:38:56 -0500 Subject: [PATCH 123/181] version 0.80 --- espeakup.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/espeakup.h b/espeakup.h index 57a3f29..4d1bcf7 100644 --- a/espeakup.h +++ b/espeakup.h @@ -28,7 +28,7 @@ #include "queue.h" -#define PACKAGE_VERSION "0.80-dev" +#define PACKAGE_VERSION "0.80" #define PACKAGE_BUGREPORT "http://github.com/williamh/espeakup/issues" enum espeakup_mode_t { From 2964310b2411c10756712ba902687e8388c78142 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Mon, 25 Jul 2016 10:22:31 -0500 Subject: [PATCH 124/181] makefile: add target to generate changelog --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile b/Makefile index b499454..ad67b61 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,7 @@ LDLIBS = -lespeak -lpthread INSTALL = install BINMODE = 0755 MANMODE = 0644 +CHANGELOG_LIMIT?= --after="1 year ago" SRCS = cli.c \ espeak.c \ @@ -24,6 +25,9 @@ OBJS = ${SRCS:.c=.o} all: espeakup +changelog: + git log ${CHANGELOG_LIMIT} --format=full > ChangeLog + install: espeakup ${INSTALL} -d ${DESTDIR}${BINDIR} ${INSTALL} -m ${BINMODE} $< ${DESTDIR}${BINDIR} From e55f16b7fd43854fd62c9a209af26e750f03999e Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Mon, 25 Jul 2016 10:25:09 -0500 Subject: [PATCH 125/181] Update ChangeLog --- ChangeLog | 1806 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1806 insertions(+) create mode 100644 ChangeLog diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..b276f00 --- /dev/null +++ b/ChangeLog @@ -0,0 +1,1806 @@ +commit 2964310b2411c10756712ba902687e8388c78142 +Author: William Hubbs +Commit: William Hubbs + + makefile: add target to generate changelog + +commit 918e8853cdd8270c77f641c69871851effe18416 +Author: William Hubbs +Commit: William Hubbs + + version 0.80 + +commit 3e5815429bd702d9b0af68d793e6c83f035f9e23 +Author: William Hubbs +Commit: William Hubbs + + Add my email address to the copyright statement + +commit 8b49d9d211f917f7ee2009569f746659ec9096a8 +Author: Christopher Brannon +Commit: William Hubbs + + Fix implicit function declaration warning. + + This fixes #7 + +commit 97adab70de5e49dde3ac26774a636cbca48558c0 +Author: Christopher Brannon +Commit: William Hubbs + + Replace usage of daemon(3). + + Original patch and commit message courtesy of: + Samuel Thibault + + currently espeakup uses daemon() to do the daemonizing stuff. + Unfortunately, daemon() does things not very appropriately, and there + is notably a delay between the parent exit()ing and the child writing + the pid file. The attached patch reimplements it properly, espeakup + then notably plays much more nicely with systemd. + + Modified by Chris to apply to master. + This fixes #8. + +commit 92903254894d2b6f2c398a104e78d15553de6017 +Author: Christopher Brannon +Commit: William Hubbs + + Fix spelling keystrokes and char-by-char echo. + + Use ssml's interpret-as="characters" setting when the kernel reports + just one character. This allows the use of espeak's internationalized + spelling of letters instead of having to maintain spelling ourselves in speakup. + + Original patch courtesy of + Samuel Thibault + and modified to work with the current code by Chris. + + This fixes #6. + +commit ee099174d849e32bf7b555e458963d27f84c64b2 +Author: Samuel Thibault +Commit: William Hubbs + + Allow a voice to be selected by language name + + This allows the -V option on the command line to be a language name. + +commit c1ad891f2e321b052802a2c3c121522757948e61 +Author: Samuel Thibault +Commit: William Hubbs + + Create pid file when espeakup is really ready + + This makes sure that we do not report that we are ready until everything + is initialized. + +commit d97724373556e5ad6d632249bcc0ba4ef7aec4d8 +Author: Christopher Brannon +Commit: William Hubbs + + Add a missing #include, so that this can be built with musl. + + This closes #5. + +commit d95ee07775f6a63d80323e5ea242c530adf9c79b +Author: William Hubbs +Commit: William Hubbs + + Revert "add indexing support" + + This reverts commit e84e000b3ec9d393d720845a5f5fd05aa2ee7302. + I need to think more about how to implement this. + +commit e84e000b3ec9d393d720845a5f5fd05aa2ee7302 +Author: William Hubbs +Commit: William Hubbs + + add indexing support + +commit 3fbbdf19224c26b80b161666b37cec70ac5dd6d2 +Author: William Hubbs +Commit: William Hubbs + + Do not try to remove the pid file unless we are in speakup mode + +commit 58ed438f00c0f79c87885b73292c3b4e5c44e0d4 +Author: William Hubbs +Commit: William Hubbs + + rework two if statements + + These if statements were executing code if we were not in acsint mode. + They have been combined and the code is now executed when we are in + speakup mode, which is what we want. + +commit b2bd1d33a8a8d08ea9316bcf3cf8169545e7df78 +Author: William Hubbs +Commit: William Hubbs + + make espeakup's default rate closer to espeak's default + +commit 3b4b6d0cbc98d175f00a9f1e744406e3491c6d85 +Author: William Hubbs +Commit: William Hubbs + + change code to use allocMem wrapper for memory allocation + + One of the new string handling routines is a wrapper for allocating + memory. This commit changes the rest of the code to take advantage of + that wrapper. + +commit 6180ff6e49371d9fc1cfb5afb05941222d925d70 +Author: Christopher Brannon +Commit: Christopher Brannon + + Don't check to see if espeakup is running in acsint mode. + + This check is important when running with speakup, since there can only + be one instance accessing /dev/softsynth. + It is unnecessary in acsint mode. + +commit ba316a4cd4ad42b5cf7a550953c1dc26338e3569 +Author: William Hubbs +Commit: William Hubbs + + separate string handling routines into their own module + +commit c06f18c4544a6e9e3d28b8f037bc40588fbff3f5 +Author: Christopher Brannon +Commit: William Hubbs + + support adapters using the acsint module + +commit 70f74657c274d37f94cf7a4eabcd1d06bafbfcb5 +Author: William Hubbs +Commit: William Hubbs + + fix Makefile to use MANMODE to install man pages + +commit 999e6551b5999f5779299e51858e4bbb587f5561 +Author: William Hubbs +Commit: William Hubbs + + add pid path option to help + +commit 3353241a79f0e2b130dce5e98d656284a7da84f8 +Author: William Hubbs +Commit: William Hubbs + + add command line option to change the pid path + + This adds a -P or --pid-path option to the command line which + allows the user to change the path and the name of the pid file created + when espeakup is running as a daemon. + + I would like to thank Chris Brannon for the original idea for this. + +commit 49dcacb2eca6f808f1f52a4faaf96f1fae24e4b5 +Author: William Hubbs +Commit: William Hubbs + + adjust rate offset and multiplier for espeak 1.45.04 + +commit 2154d1a23157cc2b0ff72f1ed51e5c8a26b452cb +Author: William Hubbs +Commit: William Hubbs + + use memset to initialize sigaction structure + +commit 1990e8e25d23fd4cbaa924ac7af480e2a079b9dc +Author: Christopher Brannon +Commit: William Hubbs + + Properly initialize sigaction struct. + + The sigaction struct used in signal_thread was stored in an automatic + variable. The fields which were not set manually had undefined values. + +commit 701074fd9685ce4133672fbb35f046e76ab13422 +Author: William Hubbs +Commit: William Hubbs + + go back to just using a makefile + + The reason I went to autotools was the multiple sound systems, but since + we are now just using espeak's audio processing we can go back to a more + simple build system. + +commit 7bf2eee07a6c5d2120e62d13e0385e4c8e9c6782 +Author: William Hubbs +Commit: William Hubbs + + remove experimental alsa support + + The direct alsa support was experimental and never worked well. It had a + setting which was system specific. Also, I feel that it is better to let + espeak control the audio processing. + +commit c7ae47dfe59481b29ec80de2faaa6c8d3bd63379 +Author: William Hubbs +Commit: William Hubbs + + add experimental support for building a static binary + + This is done by adding a --enable-standalone switch to the configure + script. + +commit 3bfc662bae54038172de1c52b04e9c589d2f7bd0 +Author: William Hubbs +Commit: William Hubbs + + update location of latest version and git repository + +commit 037e6422179424dd40667765039c6584ac306514 +Author: William Hubbs +Commit: William Hubbs + + rename todo file + +commit 0d9d7b61419eb37247e8f7afb6c5b7ff198f0ab7 +Author: William Hubbs +Commit: William Hubbs + + update readme + +commit 056dcf70fe5a6850b73193ea06480bd955695e2e +Author: William Hubbs +Commit: William Hubbs + + convert to autotools + +commit d1630432ba55033c82da0dcae4a409f14da8d03f +Author: William Hubbs +Commit: William Hubbs + + re-organized the makefile. + +commit 8fda956e020abcde9365c20c6e14f3ebc15cd2e1 +Author: William Hubbs +Commit: William Hubbs + + fixed permissions in makefile + + It turns out that the install commands need to have the permission + options otherwise the permission of everything that is installed is 755, + which is not correct. + +commit 4cfcd7ba116ddd3e1c80744b4eb7e0b83438ec86 +Author: William Hubbs +Commit: William Hubbs + + fixed mandir + + the mandir variable in the makefile should point only to the top level + of the man tree. + +commit 1a10788c5f140f75e0f54a2baaf8625125bb52ac +Author: William Hubbs +Commit: William Hubbs + + lowered latency setting to 1/40 of a second. + +commit edb5e50fcd52d6f0ed9d2decb5c874dfd9395998 +Author: William Hubbs +Commit: William Hubbs + + make alsa code more readable + + This changes the code to use constants for the parameters to + snd_pcm_set_params. This makes it easier to read the code and to update + the values if needed. + +commit dec561324df67bd64eede09bcb2eb25273a04081 +Author: William Hubbs +Commit: William Hubbs + + updates to alsa support + + After studying pcm_min.c in the alsa library git repository, I updated + the alsa support to be similar to what I saw there. + +commit 486fe27f47d12a0482060aac4fc6c1568fab0613 +Author: William Hubbs +Commit: William Hubbs + + removed permission settings from makefile + +commit 311b6911959263a81f4dd74b44ad93af53a981b1 +Author: William Hubbs +Commit: William Hubbs + + fix makefile to not define variables if they are already defined + +commit ffe397fb911b0de8a14cacfc69bf9e683c9ef402 +Author: William Hubbs +Commit: William Hubbs + + removed the minimum function + + This function really wasn't needed. I also attempted to make the + callback functionn more like the test code in the alsa library git + repository. + +commit e66311bb992122ca4797eab1d2a79b1619c71b9b +Author: William Hubbs +Commit: William Hubbs + + added automatic dependency tracking to the Makefile + +commit 11cc053d822d563b9c040ce50341f8c8cd8b4f86 +Author: William Hubbs +Commit: William Hubbs + + reworked the makefile + + This version of the makefile should be more compatible with allowing + users to pass in cflags. + +commit 48fa03faf5529a4072ae50fe9ff983333bc6fca0 +Author: William Hubbs +Commit: William Hubbs + + renamed espeak_sound.c to portaudio.c + + This better describes the sound system that espeak uses natively. + +commit 654fc810fe981907d3f17d212ae51d9d6124fa42 +Author: William Hubbs +Commit: William Hubbs + + default prefix to /usr/local + + Without packaging, we should be installing espeakup in /usr/local. + +commit e4e3f0979e1820712a6a88bfcf60da34a8a747f0 +Author: William Hubbs +Commit: William Hubbs + + the status handle should be static + +commit 57547e8efa0dcf9f7f1750d7e8472f7207d20329 +Author: William Hubbs +Commit: William Hubbs + + renamed synth.c to espeak.c + + The name was changed because it describes the function of this code more + accurately. + +commit ac9e12414b2f4a1b38f8dabdaf7eb5ae33276008 +Author: William Hubbs +Commit: William Hubbs + + made stop_requested a global variable + + The two variables, stop_requested and runner_must_stop were performing + the same function, so I am using one variable, stop_requested for this + function. + +commit 18ebab3247934c71320abed559021fe6eebab530 +Author: William Hubbs +Commit: William Hubbs + + indentation fixes + +commit cc7e77eb9db904f27b9de12f4b25b17c2f6d5b02 +Author: William Hubbs +Commit: William Hubbs + + move stop_audio call to synth thread + + Since there is no reason currently for the softsynth thread to do this, + it makes better sense to have the synth thread control all interaction + with espeak. + +commit 32d848cb76de9853564d7e2ea37725c1f9af1ae4 +Author: William Hubbs +Commit: William Hubbs + + make callback honor should_run + + The callback should return and abort synthesis if should_run is 0. This + fixes slow shutdown times in alsa mode. + +commit 4de82bf24cff9e5a82a2645f30af0dbfae6ded05 +Author: William Hubbs +Commit: William Hubbs + + added a couple of #defines to the alsa code + +commit 739e074072100dd420b10eb1d8b8d55451b9bdea +Author: William Hubbs +Commit: William Hubbs + + reworked the queue_remove function + + Now, when queue_remove is called, it returns the pointer to the data of + the first entry in the queue and removes the entry. + +commit 014d27b7aa218db968ab19b2b493fe95406b4b8b +Author: William Hubbs +Commit: William Hubbs + + removed some unlock_audio_mutex() calls + +commit 82490a98d253d5201f93f309289346fff5169abc +Author: William Hubbs +Commit: William Hubbs + + call snd_pcm_prepare after snd_pcm_drop in stop_audio + +commit 101e14901e0517f6f09024dc8dc1f47dc682227a +Author: William Hubbs +Commit: William Hubbs + + removed white space in the makefile + +commit dc056e6c773e203af74d290393819b7fdc4043e0 +Author: William Hubbs +Commit: William Hubbs + + broke the queue definitions out into their own header file + +commit 0a9a8cce9bcb0310903aaffafd2dbdbe5a6458c4 +Author: William Hubbs +Commit: William Hubbs + + small style changes + +commit 40479540b4c8dd6a876b084bce0e6c806033da06 +Author: Christopher Brannon +Commit: William Hubbs + + Fix a memory leak. + + If we fail to add entries to the queue in queue_add_cmd or + queue_add_text, properly free the entry. + +commit ccb8cea91ee1537e24070dbd3cc568e6f24ddb28 +Author: William Hubbs +Commit: William Hubbs + + stop speech before clearing the queue + + Thanks to Kirk Reiser for pointing out that this makes the cancel + response faster. + +commit 31ad5f04ca691228889bd839852d8b19321c86c1 +Author: Christopher Brannon +Commit: William Hubbs + + Completely data-agnostic queue functions. + + The functions in queue.c no longer use static variables. We can now use + them for multiple queues, if necessary. + +commit 011ec271627615be44e1bacd6d269745c86028e9 +Author: Christopher Brannon +Commit: William Hubbs + + Create pipe before starting the signal handler thread. + + The thread can write to the pipe, so the pipe must be initialized + before the thread starts. + +commit 04d10d88ec0bb2161885bc3358a9bc6b5e06ce35 +Author: William Hubbs +Commit: William Hubbs + + more sound updates + + removed the user_data processing code and put the call to snd_pcm_drop + in stop_audio. + +commit ceaae3640a51fad408386f27bb30fe2063cdf58e +Author: William Hubbs +Commit: William Hubbs + + audio should be stopped in softsynth_thread not espeak_thread + +commit c9f871f687c6bd6ef1a562000c53c6762cfa7205 +Author: William Hubbs +Commit: William Hubbs + + see if we need to silence speech before we process the queue + +commit a82bbd81400cfa002835c35ce46a956cc81460ad +Author: William Hubbs +Commit: William Hubbs + + fixed a memory leak + + If we processed an entry from the queue successfully, we were removing + the entry itself from the queue but not freeing the memory allocated to + the entry. + +commit 58f09983f856703e8a06d9b16ef17b7d8728eb4d +Author: William Hubbs +Commit: William Hubbs + + fixed callback return code + + The callback should use the value of stop_requested as its return code. + +commit 0238baa5c29f9fef26b4608be24e4f63b2927e82 +Author: William Hubbs +Commit: William Hubbs + + more alsa updates + + Made an 'if' statement in the callback more clear and added some locking + for the audio mutex. + +commit bcd64cb263745e3994484156713a601db1b59990 +Author: William Hubbs +Commit: William Hubbs + + created a start_audio function + + This moves audio control to the specific files, espeak_sound.c and + alsa.c, which are tied to the sound systems. + +commit 9b7dcebb6d3dd84d19a448e7e79a1746cd939a62 +Author: William Hubbs +Commit: William Hubbs + + alsa updates + + The first while loop in the callback doesn't need to be a loop. If the + audio fails, we can just print an error and return. + +commit 46bf3d99d51960c7a179d9bfd6724c4a428e0658 +Author: William Hubbs +Commit: William Hubbs + + all access of the audio mutex should go through our functions + +commit 87ab6c6ea822f9f7b393d1cb83c9f579d728326a +Author: William Hubbs +Commit: William Hubbs + + make sure that snd_pcm_drop is successful. + + This was suggested by Kirk Reiser and Chris Brannon. + +commit 4889572ad18a8be877916d131d9a101b6563773c +Author: William Hubbs +Commit: William Hubbs + + use user_data to detect old events + + When espeak_Cancel is called, change the value of user_data that is + passed to the events, and, in the callback, use this to test to see if + cancel was received. If the value of user_data has changed, discarde + events that have the old value. This patch is from Chris Brannon. + +commit a9398bdeb413f8c9b88178756e0cdc7ede55b0bc +Author: William Hubbs +Commit: William Hubbs + + Added another error check for alsa + +commit be879d206b52221546e4b8e00b60e0c0cf70f855 +Author: William Hubbs +Commit: William Hubbs + + alsa update + + I changed the name of the callback to alsa_callback and removed a line + that was making the amount of data written to the sound card very small. + +commit c1d33d673838faf8b70cc42c72c119f5c0002d44 +Author: William Hubbs +Commit: William Hubbs + + Set the espeak audio buffer size to 50 ms + + This should help make the cancel command more responsive. + +commit 0471ff47f4dc031cf70b14eb15128fd60fb185dd +Author: William Hubbs +Commit: William Hubbs + + add support for the user_data parameter to espeak_synth + + The user_data parameter is just a pointer that is passed into the + espeak_synth call that is passed back to the callback. In native mode, + we are not using it since there is not a callback. However, in alsa + mode, it will be used to indicate when a cancel was processed. + +commit 520bbae36512731bc075870c0baa9339929b4fde +Author: William Hubbs +Commit: William Hubbs + + renamed stopped to stop_requested + + This is more descriptive of what the variable actually does. It signals + the callback to stop the audio. + +commit 8f3e8f196711d729de6c2dc1ed1ef2d086f99955 +Author: William Hubbs +Commit: William Hubbs + + moved the audio_mutex code to alsa + + This is not needed for native sound support, so it has been moved into + the alsa specific code. + +commit e49acbb59acdbad827da2fc4dd7061e7fe2de35a +Author: William Hubbs +Commit: William Hubbs + + removed a debug print + +commit 24bcdf5666d2546b9177b54b25d2fbfc54ab804b +Author: William Hubbs +Commit: William Hubbs + + another termination fix + + espeak_thread needs to signal softsynth_thread once more as it is going + town so that softsynth_thread will see that should_run is now 0 and + terminate. + +commit 5ec3809c599981f79db87f41f4b181eb5456a4f7 +Author: William Hubbs +Commit: William Hubbs + + wake up espeak_thread when softsynth_thread terminates + + espeak_thread needs a signal since it might be sleeping and + should_run has changed. This makes sure it terminates. + +commit 5ebe506026cf2a5953ba9773d2e2c434e8bbc6f4 +Author: William Hubbs +Commit: William Hubbs + + more mutex fixes + + Make sure that should_run is protected by the mutex in the softsynth + thread. + +commit d5fd5d69b84cdcde67357a5a934b343e46a32cb2 +Author: Chris Brannon +Commit: William Hubbs + + don't wait on a condition variable if should_run is false + +commit 633743117c7067bb7f7a7a12f2edbe6bb463a366 +Author: William Hubbs +Commit: William Hubbs + + mutex fixes + + We need to make sure that should_run is protected by the mutex. + +commit 1750b92cfb0e5d5a39564ea8d949113c4e0c3409 +Author: William Hubbs +Commit: William Hubbs + + fixed signal handling issue + + The signal handler stopped working after I moved the initialization + calls to the main function. Creating the signal handler thread first + fixed this issue. + +commit eb74a3ce171515dd1f2970dfb3d1b6c2f07c6d79 +Author: William Hubbs +Commit: William Hubbs + + removed an unnecessary call to espeak_Terminate() + +commit dd00775695f713667b2fc295feab6a2a2fe1926e +Author: William Hubbs +Commit: William Hubbs + + initialization update + + The main function now initializes espeak and opens the softsynth before + starting the threads. This insures that the resources we need are + active. + +commit 6a15f2cccf4d98e112f09ae64e68773c028b76f6 +Author: William Hubbs +Commit: William Hubbs + + fixed first wait in softsynth thread + + The thread should wait if there is nothing in the queue and if there is + not a request to stop. + Thanks to Chris Brannon for the patch. + +commit 3687f16b09d7ff37f73ca0f98acd8dedd4ce18c1 +Author: William Hubbs +Commit: William Hubbs + + wait for acknowledgements correctly + + pthread_cond_wait() can have spurious wakeups, so we need to be sure + that the condition is actually true when we return from this function. + Thanks to Chris Brannon for the patch. + +commit 938e10b66a14237cdff734ae5b97525f9c4ae9cc +Author: William Hubbs +Commit: William Hubbs + + removed a nested lock/unlock + +commit 975765289b3348219d0db8b2d64e2f4f7747f9f2 +Author: William Hubbs +Commit: William Hubbs + + made sure all cond_wait and cond_signal calls are inside lock/unlock + calls + +commit b8c7247feb05a07bab653cab2a6be50a4a17fd5d +Author: William Hubbs +Commit: William Hubbs + + removed acknowledge_guard and substituted queue_guard + +commit 1091182f884cb8187ce3cdaf3723243deaa4dcb2 +Author: William Hubbs +Commit: William Hubbs + + removed a debug print call + +commit 0bf2cae5a6cd35ea7ee78fbb136ccb58f6937b3e +Author: William Hubbs +Commit: William Hubbs + + moved lock/unlock in queue_process_entry + + The only time queue_process_entry should lock the queue gard is when it + is removing the item from the queue. This happens only when the item + was successfully processed. + +commit 554a03d26c147958b99b78690214e195cda65c41 +Author: William Hubbs +Commit: William Hubbs + + white space fix + +commit b7f324072f26fa31a8d9772f38bdf1f920504223 +Author: Christopher Brannon +Commit: William Hubbs + + Fix concurrency bugs. + + 1. Don't lock or unlock queue_guard during queue_clear. + It is locked when queue_clear is called, and it should remain so. + 2. Protect runner_must_stop with queue_guard in + the request_espeak_stop function. + The following condition should always hold: queue_guard is locked while + testing or modifying runner_must_stop. + 3. Rename stop_guard to acknowledge_guard. This is a more + descriptive name. This mutex simply protects the acknowledgement of + the stop request from being lost. + 4. Remove the pthread_mutex_lock from the top of queue_process_entry, + because queue_guard is already locked when the function is called. + +commit a8cad20de898002465fad6f3cf42f381f2a33812 +Author: William Hubbs +Commit: William Hubbs + + more multithreading work + + Rearranged the queue handling code so that queue.c is generic. Also + rearranged several functions in the threads. + +commit 42c3f76a083890c49fcb7d92a2f695f69e4882b4 +Author: William Hubbs +Commit: William Hubbs + + moved include for pthread.h to espeakup.h + +commit 3e8e7d12ae89b4b2c00596cf88fcb35fd4b5b20e +Author: William Hubbs +Commit: William Hubbs + + added back the declaration for softFD + +commit af5717b8cb3d9c2232f20f90d32601c0f7021fca +Author: William Hubbs +Commit: William Hubbs + + moved queue_add_xxx functions to softsynth thread + +commit c6b57885c9479f4d85831b2082206bef685cd74d +Author: William Hubbs +Commit: William Hubbs + + removed declaration of rate from main + +commit d82bfcd09ccd4145d17473bc9ae60af223a5f66e +Author: Christopher Brannon +Commit: William Hubbs + + Make one thread responsible for handling espeak interaction. + + Most of the idea for this change came from William: + Renamed queue_runner to espeak_thread. Moved espeak initialization + and termination to espeak_thread. The while loops that process + the queue now use the variable should_run. + +commit 0fdca827b851fd0beb9f476c52ec5568ed36174e +Author: William Hubbs +Commit: William Hubbs + + check for terminalFD after select() + + If terminalFD has something to read, we break out of the loop in the + softsynth thread. + +commit 474580b08b32d713ffb6f23c486685f1927e12c0 +Author: William Hubbs +Commit: William Hubbs + + add pipe to wake up the softsynth thread + + This adds a pipe to wake up the softsynth thread, in case we receive a + signal while it is in a select. Thanks to Chris Brannon. + +commit c5fce64f259bce473cd3c9371d7b095639a87fe5 +Author: William Hubbs +Commit: William Hubbs + + removed open_softsynth and close_softsynth + + The thread can now handle the softsynth device, so main doesn't need to + call these functions. + +commit a58f93cd74fead43927093d36fc775a976788a4b +Author: William Hubbs +Commit: William Hubbs + + renamed reader_thread to softsynth_thread + +commit dfc9bbff6518b2de6e4464fd348ae460766606fb +Author: William Hubbs +Commit: William Hubbs + + fixed should_run declaration + + Removed the local declaration of should_run and set up the extern. + +commit 9d1cabdd0d513c45bafdf7cc9c62b503f4a0f31d +Author: William Hubbs +Commit: William Hubbs + + started work on multi-threading more of the program + + The goal is to create threads for the reader, que runner/espeak + processing and signal handling. + As of this commit, this code is still being worked on, so it is broken. + +commit f58d9984ce6d615158d53a6cf1b5d503296973ab +Author: William Hubbs +Commit: William Hubbs + + Now the queue runner/softsynth handler clears the queue + + Thanks to Chris Brannon for the patch. + +commit 24e7d667bce7568585e1e644b1935c8fe0709b75 +Author: William Hubbs +Commit: William Hubbs + + queue fixes + + This adds retry processing back to the queue functions. queue_remove + should only be called after the head entry on the queue is processed + successfully. + +commit 26ab109bd8e14fd3d26a434cac2e5760b23dbf0a +Author: William Hubbs +Commit: William Hubbs + + moved the check for stop out of the loop + + In the callback, we should check to see if the stopped flag is true + whether or not we are processing audio. + +commit b108764b02e0d6eb1e8a3074cf2f85f10eb01d03 +Author: William Hubbs +Commit: William Hubbs + + removed the audio_callback variable + +commit 739d79cff89f2792aa47813e08bdcbb3065c32de +Author: Christopher Brannon +Commit: William Hubbs + + Select audio mode before initializing espeak. + +commit ec9d8b1ee23095afadd07bd05cbf1ca21df11b8f +Author: Christopher Brannon +Commit: William Hubbs + + Add error-checking to the snd_pcm_set_* calls. + + These can fail. They do more than simply manipulate a structure. + +commit a5d1a48f42bbb3de67551113c1f15da10f7b916d +Author: Christopher Brannon +Commit: William Hubbs + + Obtain sample rate from the value of espeak_Initialize. + + espeak uses a sample rate of 22050 HZ, but let's not rely on that knowledge. + espeak_Initialize returns the sample rate on success, + so rely on that value when selecting a rate. + +commit 3bb78df86c3a135660864e1e07c1d5266a575bce +Author: William Hubbs +Commit: William Hubbs + + Do not set the period. + +commit 94e23a3a027dfd887f6713e745a0b97ec09dfbc7 +Author: William Hubbs +Commit: William Hubbs + + fixed error condition check in alsa.c + + The check was looking for a specific error when it should have been just + checking for failure. + +commit a69342fcada7fe6533b81c1ae0bad23f983a399a +Author: William Hubbs +Commit: William Hubbs + + removed some blank lines and put the variables at the top of the file + +commit 91b8960b6add66a982327e68d51f75d25f828af8 +Author: Christopher Brannon +Commit: William Hubbs + + Protect the stopped variable with a mutex. + + An oversight. Should have done this in the initial commit. + volatile does not imply atomic. + +commit 0ad70b4eaa35d57867f20c631f60841fde824e20 +Author: William Hubbs +Commit: William Hubbs + + Revert "fixed stop_speech issue" + + This reverts commit 1c440e5a42ef2606c0330f816b00172ab309505c. + +commit 1d02169aa584ebb8c8739c4b1255abd3ee51e709 +Author: William Hubbs +Commit: William Hubbs + + alsa support is conditional + + This commit updates the makefile and the documentation to explain how to + build alsa support. It has not been fully tested, so it is not built by + default. Also, I was able to remove the conditional compile directives + from the source. + +commit 1c440e5a42ef2606c0330f816b00172ab309505c +Author: William Hubbs +Commit: William Hubbs + + fixed stop_speech issue + + The stop_speech function needs to test the return code from + espeak_Cancel() to be sure the operation was successful before + signaling the callback to stop the audio. + +commit 08e46c58a804c380f73a8be3403663af790a48bd +Author: William Hubbs +Commit: William Hubbs + + indentation fixes + +commit d373fb2aa7fbf673594cd98225877c6998dc99ad +Author: Christopher Brannon +Commit: William Hubbs + + An initial stab at ALSA support. + + It's very raw right now. + +commit b31985f97c30b043dba7b77c5af0b42d3a65fcdd +Author: William Hubbs +Commit: William Hubbs + + released v0.71 + +commit d7dd0f919dc82cc0e497700412980ce771a5d7df +Author: William Hubbs +Commit: William Hubbs + + fixed initialization issues + + We were not returning exit codes properly if we were unable to open the + softsynth or if the daemon was already running. + +commit 2db53856a90a82c99c759399a1dfa5e704ce4f4a +Author: William Hubbs +Commit: William Hubbs + + fixed typo in tarball script + +commit 55f8ebf98a0fd2caef675e22499798b8ead99b12 +Author: William Hubbs +Commit: William Hubbs + + released v0.70 + +commit 69f1e8554a65b3eb0bdfcaf56bbcea86acc7e926 +Author: William Hubbs +Commit: William Hubbs + + The tarball script now adds a ChangeLog + +commit 0e47c95015a8d0ca3c777717f3187bafc615f201 +Author: William Hubbs +Commit: William Hubbs + + updated README + +commit c235a3b063a524cd308f2512c14502b5dee71434 +Author: William Hubbs +Commit: William Hubbs + + added .indent.pro to the repository + +commit d7c81f5117442d66358efb52232d51f45a90d4e8 +Author: William Hubbs +Commit: William Hubbs + + indentation fixes + +commit 3ddbb94e37a5183a0010a2e1ae46f4a64d39bba4 +Author: Christopher Brannon +Commit: William Hubbs + + multithreading + + Make espeakup a multi-threaded program. One thread reads from the softsynth + device, queuing text and synthesis commands. The other thread processes + items from the queue. + +commit 3a8323f98c702443f65b35bbfa84d3ae2c4c9b39 +Author: William Hubbs +Commit: William Hubbs + + Fixed typo in README + +commit e7d300a183668d24cc1250083bd09ab1abcc4cfb +Author: William Hubbs +Commit: William Hubbs + + turn off espeak's default processing of uppercase letters + + This needs to be turned off since speakup processes upper case by + raising the pitch. + +commit a1510b5e93de11dbf70fec2295b30a87656b4824 +Author: William Hubbs +Commit: William Hubbs + + indentation fixes + +commit 3dbdcb21cbb28dc6cebd80077a6e774cc2673bb6 +Author: William Hubbs +Commit: William Hubbs + + Aespeakup should not drop all non-ascii characters. + + This fixes an issue with non-english languages. + Thanks to Samuel Thibault for the patch. + +commit 9551ba81d9bffad667f0d5f864d07c767e2e70e6 +Author: William Hubbs +Commit: William Hubbs + + espeakup 0.60 + +commit 6366b41bdf7b28b392de8ca0c2a246a8360f9293 +Author: William Hubbs +Commit: William Hubbs + + espeakup v0.6 + +commit 40f152e11fb4a89546e459861ac0348c58c8d449 +Author: William Hubbs +Commit: William Hubbs + + allow users to override CFLAGS + + This fixes an issue with the Makefile that was not allowing users to + override cflags and keeping -Wall in the flags when compiling. + +commit 4e7ae23757290ef299a3ba4285bc031de425d788 +Author: William Hubbs +Commit: William Hubbs + + created tarball script + + This commit adds a script to create a tarball from the repository and + removes this functionality from the makefile. + +commit 9ee3fd433cb2513462327fd815f108dc9abc8e8e +Author: William Hubbs +Commit: William Hubbs + + documented --default-voice in man page + + This commit adds the documentation for --default-voice to the espeakup + man page. + +commit e2493db48e69307eeee3390d9329212cb6403613 +Author: William Hubbs +Commit: William Hubbs + + add --default-voice option to the help and README + + This commit adds the documentation to the help and README files for the + --default-voice command line option. + +commit 2351b5d489454c32c4a5c2ccdb1da609ded03b70 +Author: William Hubbs +Commit: William Hubbs + + add support for setting the default voice + + This adds support for a --default-voice or -V (upper case) command line + option which will set the default voice espeakup uses. This takes a + name of an espeak voice -- for example: + + espeakup --default-voice=en-us + + or + + espeakup -V en-us + +commit da15136aa7b8c12024d9178d1ba6b29037984a75 +Author: William Hubbs +Commit: William Hubbs + + only one espeakup daemon should be running + + This fixes a bug which would allow espeakup in debug mode to be run even + if espeakup was already running as a daemon. + +commit 8dca597f29e0ef54525f5f717a7058a037d2e9fc +Author: William Hubbs +Commit: William Hubbs + + Added a version script + + I added a version script. This is used in the Makefile to get the + version of espeakup when none is specified when a tarball is created. + +commit bbf77d918dac93e1bec7fc90c0b8b34dfb5a8e65 +Author: William Hubbs +Commit: William Hubbs + + Cleaned up warnings and adjusted CFLAGS + + This commit cleans up warnings and adjusts CFLAGS. Thanks to + samuel.thibault@ens-lyon.org. + +commit 7db55303088588a19fcde1c804268c984f6008d8 +Author: William Hubbs +Commit: William Hubbs + + Espeakup version 0.51. + +commit 341fa7ba425892c12ae293584aacd9028d520e62 +Author: William Hubbs +Commit: William Hubbs + + fixed install command in makefile. + +commit 0f24afef95c2bdda474d77bc774f19003015da46 +Author: William Hubbs +Commit: William Hubbs + + espeakup v0.5 + +commit c12ec3e1b060b6e3ec1ac53db33b6f87877e9109 +Author: William Hubbs +Commit: William Hubbs + + moved version definition + + This commit moves the version definition to espeakup.c instead of cli.c + +commit a8876a79644f36453a7edaef4c0860c7d2402c9b +Author: William Hubbs +Commit: William Hubbs + + fixed the license in the man page + + The man page said that espeakup is under gpl version 2 or later, but it + is under version 3 or later, so I fixed the man page. + +commit 2b96dd2a026bb2220071699fc51cdf11b9412d82 +Author: William Hubbs +Commit: William Hubbs + + updated man page + + This commit re-words the description of espeakup in the man page. + +commit 17553c3c391e011a1ccf90179c634003d2a61519 +Author: William Hubbs +Commit: William Hubbs + + fixed the makefile + + This commit removes the definitions for CC, RM and INSTALL from the + makefile so that it will use system defaults for these commands. + +commit ace8acf7d01cc256c1df96d3b03e21806772edb5 +Author: William Hubbs +Commit: William Hubbs + + fixed hyphenation + + This commit turns off hypenation in the man page. + +commit 84c473b690633999f47478dbf00c766d1a31628b +Author: William Hubbs +Commit: William Hubbs + + added man page + + This commit adds a man page for espeakup. + Thanks to Chris Brannon for writing it. + +commit f7ddd8dc77927d21a07479f80969df031af396f2 +Author: William Hubbs +Commit: William Hubbs + + Released v0.4. + +commit a3901a7e4c0d273f2ad5352f939714fe235166e4 +Author: William Hubbs +Commit: William Hubbs + + fixed a bug in process_command + + One of the switch statements in process_command did not have a default + label, which lead to undefined behavior. + Thanks to Chris Brannon for the patch. + +commit 36b05aec419a7ab7bc3b66358f62122096ec9ce2 +Author: William Hubbs +Commit: William Hubbs + + Added support for the punctuation command from speakup + +commit c48b05d7437435c0c7513e9d98ab04b565c87f92 +Author: William Hubbs +Commit: William Hubbs + + moved all variable definitions to the top of the Makefile. + +commit 82fa63600b9377fa590a2c97ed737fd8c85a622c +Author: William Hubbs +Commit: William Hubbs + + fixed the makefile + + Added espeakup.h as a dependency in the makefile so that the sources + will be compiled if it changes. + +commit d7e8dc2b342b5a810ec561535ca0426969f519ea +Author: William Hubbs +Commit: William Hubbs + + Revert "fixed the length calculation when a flush is processed." + + This reverts commit 66cb5a7b5cfe0e569525935d03b0843ee85a8afc. + +commit 66cb5a7b5cfe0e569525935d03b0843ee85a8afc +Author: William Hubbs +Commit: William Hubbs + + fixed the length calculation when a flush is processed. + +commit 62deb008bc658d925bd86fb4172b12779b9cad18 +Author: William Hubbs +Commit: William Hubbs + + fixed the number of bytes to move in the memmove() call + +commit 14858818d3cf38886aef5089982522feb9a8edfb +Author: William Hubbs +Commit: William Hubbs + + changed strcpy to memmove + + The areas pointed to by strcpy() cannot overlap, so we need to use + memmove() in case that happens. + Thanks to Chris Brannon for pointing this out. + +commit 6bec55ca5789e26ee315e890f4937c1451b8cd07 +Author: William Hubbs +Commit: William Hubbs + + changed process_buffer to use the isprint() call. + +commit 1b608481a4062f3a8f98192e50acfcb73cf577e2 +Author: William Hubbs +Commit: William Hubbs + + the main loop now uses strrchr and strcpy + + The idea for this change came from another patch submitted by Chris + Brannon. We now use strrchr to look for the flush character and strcpy + to move the remainder of the buffer to the beginning. + +commit faab1893893fa0c97263a0edf965cf4f67bd1294 +Author: William Hubbs +Commit: William Hubbs + + Fixed the select call + + The select call was moved to be in the if statement below it since the + return code is not needed after that statement is processed. + +commit 24607b1cc8000d4d95128e96662240dbce385358 +Author: William Hubbs +Commit: William Hubbs + + made the synth flush character a constant for readability + +commit c8e2a35763624463d1006a83ab0125603813d239 +Author: William Hubbs +Commit: William Hubbs + + fixed an off-by-one error + + The loop can start at length-1 since we know that the last character in + the buffer is a null. + Thanks again to Chris Brannon for finding this. + +commit f76d00f6afefb8de92bf205d16d84f488b91615d +Author: William Hubbs +Commit: William Hubbs + + removed the callback function + + This commit removes the synthcallback function since it wasn't doing + anything. Also, it has been reported that this may be causing the + sluggishness when espeakup is asked to shut up. + Thanks to Chris Brannon for finding this. + +commit 17f07e8cd175520c8fe16880f9f578e0f49579fc +Author: William Hubbs +Commit: William Hubbs + + released v0.3. + +commit 9b0c6a8224980c8637302d9e680cccef4ed0043d +Author: William Hubbs +Commit: William Hubbs + + fixed the volume multiplier + + The volume range is actually 0-200 instead of 0-100, so the multiplier + needed to be adjusted. + +commit c7e3835fbd2ab4d9ae5162488163d22c8bd9c811 +Author: William Hubbs +Commit: William Hubbs + + Updated ToDo list + +commit 527fb136de9d01c752f6f6d03d2ac42b89a94499 +Author: William Hubbs +Commit: William Hubbs + + starting work toward supporting changing voices + + This commit adds a set_voice() function which will ultimately allow the + user to switch voices. + +commit f52c03ec2be8cc67e680eda0cdb6bbb051b858cd +Author: William Hubbs +Commit: William Hubbs + + Fixed a typo. + +commit 8d3552c9642aec00f5ecc89dbbccd181244d9bfa +Author: William Hubbs +Commit: William Hubbs + + updated readme + +commit 1f784be8911bd2917e697630de3da05da2814ab4 +Author: William Hubbs +Commit: William Hubbs + + added support for long command line options + +commit 037019de3a74c191349bebc03289a11ab7cead42 +Author: William Hubbs +Commit: William Hubbs + + Espeakup v0.2 + +commit 943ff9d3dc50184a359ee7b39d57b4baaba0657c +Author: William Hubbs +Commit: William Hubbs + + updated README + +commit 5ddeb1e978bc637b4db22f19d0db8e448599f5e0 +Author: William Hubbs +Commit: William Hubbs + + indentation fixes + +commit ccc9c4aa4ed3f16d3781b92fbd6d6ec013627c5c +Author: William Hubbs +Commit: William Hubbs + + modified rate offset + + This commit moves the rate offset to 84 instead of 80 so that the + highest espeak rate can be reached by setting the speakup rate to + the maximum. + +commit 96a3b198508172e30bb0614563db94f83e45ce03 +Author: William Hubbs +Commit: William Hubbs + + fix flush processing + + This removes flush processing from process_command() and fixes + the code in the main loop so that it does not ignore the 0 position + in the buffer. + +commit 5bc67dc49d61468968b25cda1340091fced573a0 +Author: William Hubbs +Commit: William Hubbs + + updated ToDo list. + +commit 02e72bda39b4c26bcc1a67d701a405427e3a6f8a +Author: William Hubbs +Commit: William Hubbs + + adjusted the rate multiplier + + This gets us closer to espeak's top speed, which is 390 wpm. + +commit ebcbcac9d2b230a37347f60aa3e2715a07bb13a6 +Author: William Hubbs +Commit: William Hubbs + + removed an extra assignment statement + +commit d2d763b36ba477c18a04933ee49b68f71dd641a2 +Author: William Hubbs +Commit: William Hubbs + + moved flush processing into main loop + + This patch from Kirk Reiser attempts to increase + responsiveness by moving the flush processing into the main loop. + +commit 564db7981e1aeda4eb84958d1f66c6474803991f +Author: William Hubbs +Commit: William Hubbs + + put back the select code + + This needed to be put back to keep espeakup from using 100% of the cpu. + +commit 5005b9ddde90aeab3948f9123491463d0e319528 +Author: William Hubbs +Commit: William Hubbs + + removed code that uses select + + I was using the wrong type for the return value for read(). + +commit 3e7e5be2b78bdc1dbaa400d3b8e35ac66eab3cbd +Author: William Hubbs +Commit: William Hubbs + + fixed bug with volume setting + + Now the volume setting should be announced again. + +commit f973c9ec3fa92560279acede8386beeaa5f6835b +Author: William Hubbs +Commit: William Hubbs + + cleaned up prototypes + + This commit gets rid of extra spaces in some function prototypes. + +commit 498ce65db7d789b9639b96240555e48ab3a910b6 +Author: William Hubbs +Commit: William Hubbs + + cleaned up process_command + +commit aac77a3cf1edd6b503bcaada06a575ac06efa6f7 +Author: William Hubbs +Commit: William Hubbs + + ignore object files + +commit de8d4d9dc3bb7afd51eef89c0c7c2fb6d630b7a7 +Author: William Hubbs +Commit: William Hubbs + + fixed an include for gcc 4.3 + +commit b34e397717bae998bd2280a0774a04cd37ea1791 +Author: William Hubbs +Commit: William Hubbs + + clear the queue when we catch a signal + +commit 4c30dac5e16c84d92f12aa06c3cf5279c726d8db +Author: William Hubbs +Commit: William Hubbs + + added prototypes for queue functions + +commit 2bf3b17ffcbb3705afc23957e77fba2dc7abbda9 +Author: William Hubbs +Commit: William Hubbs + + removed debug flag from cflags + +commit 655894ee2a240036e966a5854fc71bb788aebe25 +Author: William Hubbs +Commit: William Hubbs + + added queueing support + + I have added queueing support so that when we read from the softsynth we + can put the text and commands we have read into a queue. This will + allow us to retry calling espeak_synth() if we fill espeak's internal + buffer. + +commit 86e93edeb09774d3689cca7f9fe96aa484f3bd6d +Author: William Hubbs +Commit: William Hubbs + + removed softsynth code from main module + +commit 261c6db032a0c4654c0b77055701223bee055dcb +Author: William Hubbs +Commit: William Hubbs + + Added ToDo list + +commit 029dd03251d24dc5c0a1b0e5a16706c0ca73180d +Author: William Hubbs +Commit: William Hubbs + + modularize the code + + This commit just re-arranges the source so that it is easier to work with. + +commit 882e9c20a547707c2d63a70414de951c50e5d4db +Author: William Hubbs +Commit: William Hubbs + + clean up the main function + + This commit cleans up the main function and moves command line processing + to a separate function. + +commit 4d2f76d6e111bb45cdf336f4be8140bcab3d51b6 +Author: William Hubbs +Commit: William Hubbs + + removed makedist + + The functionality to create a tarball has been moved into the makefile. + Now it is possible to create a tarball by doing: + make tarball - creates a tarball of the llast tagged version. + make TAG=gittag tarball creates a tarball based on the tag that is given to it. + +commit 1802877912be8e4b68541ed07d738841947463fd +Author: William Hubbs +Commit: William Hubbs + + Removed init scripts. + + It will be best to let packagers write init scripts for their distributions, + so I am removing them from this repository. + +commit 3d83e0f6d152035890d7dbecb5961ee79234d476 +Author: William Hubbs +Commit: William Hubbs + + updated readme + + I added an acknowledgements section. + +commit b76fada0b61873bb5228246e2585fea3ca690aba +Author: William Hubbs +Commit: William Hubbs + + fixed makefile + + The reference to $(PROGRAM) should have been $<. + This is fixed. + +commit c2c1d429db31693a60b8e93479a4d4fe5d31588a +Author: William Hubbs +Commit: William Hubbs + + added redhat init script, thanks to William Acker. + +commit c7bece776d13a1c5ac1a52967ffb5cd1b3ed9a9c +Author: William Hubbs +Commit: William Hubbs + + fixed makefile + + There was a bug in the makefile which was not installing the binary correctly. + This is now fixed. + +commit 22ea5c4d1d5db2d4d24e5a89437fac0d6940edf7 +Author: William Hubbs +Commit: William Hubbs + + updated makedist + + The makedist script now excludes itself and .gitignore when creating a tarball. + +commit 9402716c32c124fff4614b1555f7219f0bbe7135 +Author: William Hubbs +Commit: William Hubbs + + cleaned up command line option processing + +commit 05b115abbb8aa1d14b0f1c38c1212918fc9d8c24 +Author: William Hubbs +Commit: William Hubbs + + fixed typos in makedist script. + +commit 16beed096923abea8a7768d1ee6224419faabd0b +Author: William Hubbs +Commit: William Hubbs + + added a script to make tarball releases. + +commit 6ecc3182dab397d7b197e18d7bf78ca8c1316f71 +Author: William Hubbs +Commit: William Hubbs + + added a version command line option and variable. + +commit 96871c66201b77fddf5b80106b8f136fe825df87 +Author: William Hubbs +Commit: William Hubbs + + added destdir and prefix to the makefile for packaging. + +commit c7e0e28ad1102c395958c3baab70b4a8d20203bc +Author: William Hubbs +Commit: William Hubbs + + added gpl + +commit 02c88e949a9e44e16fa7ad6c289f3c476e0becb2 +Author: William Hubbs +Commit: William Hubbs + + adjusted multipliers + + I adjusted the pitch and volume multipliers. + This should allow us to come closer to the maximum espeak settings. + +commit d7de943a3a1b748e2cb27f42af483339de8aa444 +Author: William Hubbs +Commit: William Hubbs + + added frequency support + + This patch, also from Kirk Reiser, adds frequency support. + +commit cddead8aa951e0ad68ba241456a8e5f36c6fb2f5 +Author: William Hubbs +Commit: William Hubbs + + pid file support + + This commit adds support for a pid file so that we can be stopped and + started by init systems. + +commit b51cf9d774cc5a2abd13480238b951e20680ec24 +Author: William Hubbs +Commit: William Hubbs + + Added a signal handler + + This commit adds a signal handler so that espeakup will terminate cleanly. + +commit 61aac5ecb58ac49fc9060d19dde2dbda996e8e9f +Author: William Hubbs +Commit: William Hubbs + + moved some variables + + This commit removes the softsynth file descriptor and the debug flag + from the synth structure. These will need to be accessed from a signal + handler and there is no way to pass the structure to it. + Also, the process_data function now works with local variables and assigns + them to the synth structure, avoiding allocating a buffer with malloc/free. + +commit eb5cb3d36d35887907e13aeee0cad8fcc1b73baa +Author: William Hubbs +Commit: William Hubbs + + fixed volume + + I applied another patch from Kirk Reiser which fixes the volume setting. + Thanks to Kirk for the patch. + +commit 7604cac68c53dd3c01cfc0e131e2a7f985b40ff7 +Author: William Hubbs +Commit: William Hubbs + + 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". + +commit b745e0c48b614143fb4df04ba878af29f4ece587 +Author: William Hubbs +Commit: William Hubbs + + more error checking + + I moved the read call out of process_data and into the main loop. + Also, error checking was added for select() and read(). + +commit c3b0e8d0da9efdf9e719ba3fbe599640a5db7dce +Author: William Hubbs +Commit: William Hubbs + + code cleanup + + This patch adds the length of the buffer to the synth structure and + clears the buffer before we use it. + Thanks to Kirk Reiser for the patch. + +commit c4839ac78b967b4677531afe7568156c907e6bda +Author: William Hubbs +Commit: William Hubbs + + added maxBufferSize constant + +commit 754358f1731e58990b4c4131d4b900a5d2a5049a +Author: William Hubbs +Commit: William Hubbs + + added cli option support + + This commit adds support for command line options and also adds a debug option. + +commit 572f33337811973091f44e54e6b4fcb13ae689d9 +Author: William Hubbs +Commit: William Hubbs + + added volume support + + I added support for setting the volume. + +commit 4e3bbdb0b02eb1f12c087909e6437a31a9c60d7b +Author: William Hubbs +Commit: William Hubbs + + initial import From e21b746eb9f20827232da5ba43b184a6917c3bd0 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Tue, 14 Mar 2017 21:45:26 -0500 Subject: [PATCH 126/181] version 0.81 --- espeakup.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/espeakup.h b/espeakup.h index 4d1bcf7..8fc0ee2 100644 --- a/espeakup.h +++ b/espeakup.h @@ -28,7 +28,7 @@ #include "queue.h" -#define PACKAGE_VERSION "0.80" +#define PACKAGE_VERSION "0.81" #define PACKAGE_BUGREPORT "http://github.com/williamh/espeakup/issues" enum espeakup_mode_t { From b7fe3af320226600c6162252f040b21d6323e07c Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Tue, 14 Mar 2017 21:52:14 -0500 Subject: [PATCH 127/181] add unicode variant of /dev/softsynth --- softsynth.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/softsynth.c b/softsynth.c index 3394434..efa2351 100644 --- a/softsynth.c +++ b/softsynth.c @@ -235,7 +235,10 @@ int open_softsynth(void) } /* open the softsynth. */ - softFD = open("/dev/softsynth", O_RDWR | O_NONBLOCK); + softFD = open("/dev/softsynthu", O_RDWR | O_NONBLOCK); + if (softFD < 0 && errno == ENOENT) + /* Kernel without unicode support? Try without unicode. */ + softFD = open("/dev/softsynth", O_RDWR | O_NONBLOCK); if (softFD < 0) { perror("Unable to open the softsynth device"); rc = -1; From a5b655ddb066eb5915117452f62937b2a9bf3256 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Tue, 14 Mar 2017 21:56:31 -0500 Subject: [PATCH 128/181] fix speaking spaces Espeak doesn't speak spaces unless it is specifically told to do so. --- espeak.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/espeak.c b/espeak.c index f09d3c4..f1f8064 100644 --- a/espeak.c +++ b/espeak.c @@ -170,9 +170,13 @@ static espeak_ERROR speak_text(struct synth_t *s) if (espeakup_mode == ESPEAKUP_MODE_SPEAKUP && (s->len == 1)) { char *buf; int n; - n = asprintf(&buf, - "%c", - s->buf[0]); + if (s->buf[0] == ' ') + n = asprintf(&buf, + " "); + else + n = asprintf(&buf, + "%c", + s->buf[0]); if (n == -1) { /* D'oh. Not much to do on allocation failure. * Perhaps espeak will happen to say the character */ From 5339da3144f394eb6e6dd3df116b854d78476565 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sat, 30 Jun 2018 15:41:20 +0200 Subject: [PATCH 129/181] Support audio pauses When the Linux console is e.g. switched to a graphical VT, the kernel emits \x01P to notify that it is not able to read the screen any more, and the software synthesis can thus release the audio card, for other screen readers to take over. This implements it by adding a paused_espeak variable that tracks whether we have suspended espeak. When more text comes, we can simply reinitialize espeak. This fixes #10. --- espeak.c | 40 ++++++++++++++++++++++++++++++++++++++++ espeakup.c | 3 ++- espeakup.h | 2 ++ softsynth.c | 3 +++ 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/espeak.c b/espeak.c index f1f8064..5fd9342 100644 --- a/espeak.c +++ b/espeak.c @@ -40,6 +40,7 @@ const int rateOffset = 80; const int volumeMultiplier = 22; volatile int stop_requested = 0; +int paused_espeak = 1; static int acsint_callback(short *wav, int numsamples, espeak_EVENT * events) { @@ -211,6 +212,32 @@ static void synth_queue_clear() } } +static void reinitialize_espeak(struct synth_t *s) +{ + int rate; + + /* Re-initialize espeak */ + rate = espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 50, NULL, 0); + if (rate < 0) { + fprintf(stderr, "Unable to initialize espeak.\n"); + return; + } + + /* We need a callback in acsint mode, but not in speakup mode. */ + if (espeakup_mode == ESPEAKUP_MODE_ACSINT) + espeak_SetSynthCallback(acsint_callback); + + /* Set parameters again */ + espeak_SetVoiceByName(s->voice); + espeak_SetParameter(espeakRANGE, s->frequency * frequencyMultiplier, 0); + espeak_SetParameter(espeakPITCH, s->pitch * pitchMultiplier, 0); + espeak_SetParameter(espeakRATE, s->rate * rateMultiplier + rateOffset, 0); + espeak_SetParameter(espeakVOLUME, (s->volume + 1) * volumeMultiplier, 0); + espeak_SetParameter(espeakCAPITALS, 0, 0); + paused_espeak = 0; + return; +} + static void queue_process_entry(struct synth_t *s) { espeak_ERROR error; @@ -222,6 +249,11 @@ static void queue_process_entry(struct synth_t *s) current = (struct espeak_entry_t *) queue_remove(synth_queue); } pthread_mutex_unlock(&queue_guard); + + if (current->cmd != CMD_PAUSE && paused_espeak) { + reinitialize_espeak(s); + } + switch (current->cmd) { case CMD_SET_FREQUENCY: error = set_frequency(s, current->value, current->adjust); @@ -246,6 +278,13 @@ static void queue_process_entry(struct synth_t *s) s->len = current->len; error = speak_text(s); break; + case CMD_PAUSE: + if (!paused_espeak) { + espeak_Cancel(); + espeak_Terminate(); + paused_espeak = 1; + } + break; default: break; } @@ -282,6 +321,7 @@ int initialize_espeak(struct synth_t *s) set_rate(s, defaultRate, ADJ_SET); set_volume(s, defaultVolume, ADJ_SET); espeak_SetParameter(espeakCAPITALS, 0, 0); + paused_espeak = 0; return 0; } diff --git a/espeakup.c b/espeakup.c index 1981430..eda3e9c 100644 --- a/espeakup.c +++ b/espeakup.c @@ -231,7 +231,8 @@ int main(int argc, char **argv) pthread_join(softsynth_thread_id, NULL); pthread_join(espeak_thread_id, NULL); - espeak_Terminate(); + if (!paused_espeak) + espeak_Terminate(); close_softsynth(); out: diff --git a/espeakup.h b/espeakup.h index 8fc0ee2..e8e89a7 100644 --- a/espeakup.h +++ b/espeakup.h @@ -45,6 +45,7 @@ enum command_t { CMD_SET_VOLUME, CMD_SPEAK_TEXT, CMD_FLUSH, + CMD_PAUSE, CMD_UNKNOWN, }; @@ -86,6 +87,7 @@ extern void close_softsynth(void); extern void *softsynth_thread(void *arg); extern volatile int should_run; extern volatile int stop_requested; +extern int paused_espeak; extern int self_pipe_fds[2]; #define PIPE_READ_FD (self_pipe_fds[0]) #define PIPE_WRITE_FD (self_pipe_fds[1]) diff --git a/softsynth.c b/softsynth.c index efa2351..ca9c5c3 100644 --- a/softsynth.c +++ b/softsynth.c @@ -133,6 +133,9 @@ static int process_command(struct synth_t *s, char *buf, int start) case 'v': cmd = CMD_SET_VOLUME; break; + case 'P': + cmd = CMD_PAUSE; + break; default: cmd = CMD_UNKNOWN; break; From 5f01999726b606c038fa1cd38df421a8ba10baee Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sat, 30 Jun 2018 15:43:56 +0200 Subject: [PATCH 130/181] Make empty voice name select the default voice See http://bugs.debian.org/872194 This fixes #11. --- espeak.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/espeak.c b/espeak.c index 5fd9342..8871d1b 100644 --- a/espeak.c +++ b/espeak.c @@ -311,7 +311,7 @@ int initialize_espeak(struct synth_t *s) espeak_SetSynthCallback(acsint_callback); /* Setup initial voice parameters */ - if (defaultVoice) { + if (defaultVoice && defaultVoice[0]) { set_voice(s, defaultVoice); free(defaultVoice); defaultVoice = NULL; From e69d61b2d88d8dc679558dea03c48130127102ac Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sat, 30 Jun 2018 15:45:24 +0200 Subject: [PATCH 131/181] signal: Add missing mutex_lock/unlock around the while loop This fixes #12. --- signal.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/signal.c b/signal.c index 102c3cf..3096b30 100644 --- a/signal.c +++ b/signal.c @@ -63,7 +63,9 @@ void *signal_thread(void *arg) printf("espeakup caught signal %d\n", sig); break; } + pthread_mutex_lock(&queue_guard); } + pthread_mutex_unlock(&queue_guard); /* Tell the reader to stop, if it is in a select() call. */ write(PIPE_WRITE_FD, STOP_MSG, strlen(STOP_MSG)); return NULL; From 1e3100809115596922c1e22a6f99f188117fd9f2 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 18 Aug 2019 20:29:55 +0200 Subject: [PATCH 132/181] pass '\n' to espeak too for e.g. proper pause --- softsynth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/softsynth.c b/softsynth.c index ca9c5c3..fffef44 100644 --- a/softsynth.c +++ b/softsynth.c @@ -171,7 +171,7 @@ static void process_buffer(struct synth_t *s, char *buf, ssize_t length) start = 0; end = 0; while (start < length) { - while ((buf[end] < 0 || buf[end] >= ' ') && end < length) + while ((buf[end] < 0 || buf[end] >= ' ' || buf[end] == '\n') && end < length) end++; if (end != start) { txtLen = end - start; From a9657bbb2b2520f80869ba9ffb91eeab4c17acba Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sat, 25 Apr 2020 21:47:00 +0200 Subject: [PATCH 133/181] Support pitch range configuration This allows to let users choose expressiveness of their synth. --- espeak.c | 21 +++++++++++++++++++++ espeakup.h | 2 ++ softsynth.c | 3 +++ 3 files changed, 26 insertions(+) diff --git a/espeak.c b/espeak.c index 8871d1b..0ce680f 100644 --- a/espeak.c +++ b/espeak.c @@ -28,6 +28,7 @@ /* default voice settings */ const int defaultFrequency = 5; const int defaultPitch = 5; +const int defaultRange = 5; const int defaultRate = 2; const int defaultVolume = 5; char *defaultVoice = NULL; @@ -35,6 +36,7 @@ char *defaultVoice = NULL; /* multipliers and offsets */ const int frequencyMultiplier = 11; const int pitchMultiplier = 11; +const int rangeMultiplier = 11; const int rateMultiplier = 41; const int rateOffset = 80; const int volumeMultiplier = 22; @@ -87,6 +89,21 @@ static espeak_ERROR set_pitch(struct synth_t *s, int pitch, return rc; } +static espeak_ERROR set_range(struct synth_t *s, int range, + enum adjust_t adj) +{ + espeak_ERROR rc; + + if (adj == ADJ_DEC) + range = -range; + if (adj != ADJ_SET) + range += s->range; + rc = espeak_SetParameter(espeakRANGE, range * rangeMultiplier, 0); + if (rc == EE_OK) + s->range = range; + return rc; +} + static espeak_ERROR set_punctuation(struct synth_t *s, int punct, enum adjust_t adj) { @@ -261,6 +278,9 @@ static void queue_process_entry(struct synth_t *s) case CMD_SET_PITCH: error = set_pitch(s, current->value, current->adjust); break; + case CMD_SET_RANGE: + error = set_range(s, current->value, current->adjust); + break; case CMD_SET_PUNCTUATION: error = set_punctuation(s, current->value, current->adjust); break; @@ -318,6 +338,7 @@ int initialize_espeak(struct synth_t *s) } set_frequency(s, defaultFrequency, ADJ_SET); set_pitch(s, defaultPitch, ADJ_SET); + set_range(s, defaultRange, ADJ_SET); set_rate(s, defaultRate, ADJ_SET); set_volume(s, defaultVolume, ADJ_SET); espeak_SetParameter(espeakCAPITALS, 0, 0); diff --git a/espeakup.h b/espeakup.h index e8e89a7..2e2295f 100644 --- a/espeakup.h +++ b/espeakup.h @@ -39,6 +39,7 @@ enum espeakup_mode_t { enum command_t { CMD_SET_FREQUENCY, CMD_SET_PITCH, + CMD_SET_RANGE, CMD_SET_PUNCTUATION, CMD_SET_RATE, CMD_SET_VOICE, @@ -66,6 +67,7 @@ struct espeak_entry_t { struct synth_t { int frequency; int pitch; + int range; int punct; int rate; char voice[10]; diff --git a/softsynth.c b/softsynth.c index ca9c5c3..c006015 100644 --- a/softsynth.c +++ b/softsynth.c @@ -127,6 +127,9 @@ static int process_command(struct synth_t *s, char *buf, int start) case 'p': cmd = CMD_SET_PITCH; break; + case 'r': + cmd = CMD_SET_RANGE; + break; case 's': cmd = CMD_SET_RATE; break; From 53665b8eabaefeb0f067ba536295515ceec2f9c6 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Wed, 29 Apr 2020 02:25:54 +0200 Subject: [PATCH 134/181] Support setting ALSA volume in addition to espeak volume This allows to make sure to reach the maximum volume permitted by the hardware. This makes the default volume (5) set ALSA volume to 80%, like the default ALSA scripts do. This is not enabled by default, since users will probably want to use a mixer to fine-tune their volume. But for e.g. installation images, this allows to spare the use of a mixer and just use the speakup volume control. --- Makefile | 2 +- cli.c | 6 ++++ espeak.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ad67b61..3cbb608 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ DEPFLAGS = -MMD WARNFLAGS = -Wall CFLAGS += ${DEPFLAGS} ${WARNFLAGS} -LDLIBS = -lespeak -lpthread +LDLIBS = -lespeak -lpthread -lasound -lm INSTALL = install BINMODE = 0755 diff --git a/cli.c b/cli.c index 31db4b0..b8a6543 100644 --- a/cli.c +++ b/cli.c @@ -30,11 +30,15 @@ extern char *pidPath; /* default voice */ extern char *defaultVoice; +/* Whether to drive ALSA volume */ +extern int alsaVolume; + /* command line options */ const char *shortOptions = "P:V:adhv"; const struct option longOptions[] = { {"pid-path", required_argument, NULL, 'P'}, {"default-voice", required_argument, NULL, 'V'}, + {"alsa-volume", no_argument, &alsaVolume, 1}, {"acsint", no_argument, NULL, 'a'}, {"debug", no_argument, NULL, 'd'}, {"help", no_argument, NULL, 'h'}, @@ -48,6 +52,7 @@ static void show_help() printf("Options are as follows:\n"); printf(" --pid-path=path, -P path\t\tSet path for pid file.\n"); printf(" --default-voice=voice, -V voice\tSet default voice.\n"); + printf(" --alsa-volume\t\t\t\tDrive the ALSA volume.\n"); printf(" --debug, -d\t\t\t\tDebug mode (stay in the foreground).\n"); printf(" --help, -h\t\t\t\tShow this help.\n"); printf(" --version, -v\t\t\t\tDisplay the software version.\n"); @@ -93,6 +98,7 @@ void process_cli(int argc, char **argv) show_version(); break; case -1: + case 0: break; default: show_help(); diff --git a/espeak.c b/espeak.c index 8871d1b..5d6fc96 100644 --- a/espeak.c +++ b/espeak.c @@ -22,6 +22,8 @@ #include #include #include +#include +#include #include "espeakup.h" @@ -31,6 +33,7 @@ const int defaultPitch = 5; const int defaultRate = 2; const int defaultVolume = 5; char *defaultVoice = NULL; +int alsaVolume = 0; /* multipliers and offsets */ const int frequencyMultiplier = 11; @@ -135,6 +138,86 @@ static espeak_ERROR set_voice(struct synth_t *s, char *voice) return rc; } +static void set_alsa_volume(int vol) +{ + snd_mixer_t *m; + snd_mixer_elem_t *e; + int err; + + err = snd_mixer_open(&m, 0); + if (err < 0) + { + fprintf(stderr, "ALSA mixer open error: %s\n", snd_strerror(err)); + return; + } + + err = snd_mixer_attach(m, "default"); + if (err < 0) + { + fprintf(stderr, "ALSA mixer attach error: %s\n", snd_strerror(err)); + return; + } + err = snd_mixer_selem_register(m, NULL, NULL); + if (err < 0) + { + fprintf(stderr, "ALSA mixer load error: %s\n", snd_strerror(err)); + return; + } + err = snd_mixer_load(m); + if (err < 0) + { + fprintf(stderr, "ALSA mixer load error: %s\n", snd_strerror(err)); + return; + } + + /* Turn vol value to volume %. + * We do not want to soften that much with ALSA, espeak is already + * doing it. We want the default value (5) to be the usual default + * volume (80%), and make higher values increase ALSA volume, up to + * 100%. */ + + int volume = (vol+1) * 50 / 10 + 50; + + for (e = snd_mixer_first_elem(m); e; e = snd_mixer_elem_next(e)) + { + if (snd_mixer_elem_get_type(e) != SND_MIXER_ELEM_SIMPLE) + continue; + if (snd_mixer_selem_is_enumerated(e)) + continue; + + if (snd_mixer_selem_has_playback_switch(e)) { + snd_mixer_selem_set_playback_switch_all(e, 1); + } + + if (snd_mixer_selem_has_playback_volume(e)) { + long min, max, set; + + err = snd_mixer_selem_get_playback_dB_range(e, &min, &max); + if (err == 0 && min < max) { + if (max - min < 2400) { + /* 24dB amplitude is too small for using a logscale */ + set = min + volume * (max-min) / 100; + } else { + /* Use a logscale */ + double volf = volume / 100.; + if (min != SND_CTL_TLV_DB_GAIN_MUTE) + { + double minf = pow(10, (min-max) / 6000.); + volf = volf * (1 - minf) + minf; + } + set = 6000. * log10(volf) + max; + } + snd_mixer_selem_set_playback_dB_all(e, set, 0); + } else { + /* No dB setting, try a linear scale */ + snd_mixer_selem_get_playback_volume_range(e, &min, &max); + set = min + volume * (max-min) / 100; + snd_mixer_selem_set_playback_volume_all(e, set); + } + } + } +} + static espeak_ERROR set_volume(struct synth_t *s, int vol, enum adjust_t adj) { @@ -147,7 +230,11 @@ static espeak_ERROR set_volume(struct synth_t *s, int vol, rc = espeak_SetParameter(espeakVOLUME, (vol + 1) * volumeMultiplier, 0); if (rc == EE_OK) + { s->volume = vol; + if (alsaVolume) + set_alsa_volume(vol); + } return rc; } From 171bb517a08dbadb9c05442a8e678b776aa5f604 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Mon, 15 Jun 2020 11:55:32 +0200 Subject: [PATCH 135/181] Let espeak choose the buffer size The default is already quite small, and choosing a too small one may lead to broken speech. Fixes #13 --- espeak.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/espeak.c b/espeak.c index f9998fc..a32bde8 100644 --- a/espeak.c +++ b/espeak.c @@ -321,7 +321,7 @@ static void reinitialize_espeak(struct synth_t *s) int rate; /* Re-initialize espeak */ - rate = espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 50, NULL, 0); + rate = espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 0, NULL, 0); if (rate < 0) { fprintf(stderr, "Unable to initialize espeak.\n"); return; @@ -407,7 +407,7 @@ int initialize_espeak(struct synth_t *s) int rate; /* initialize espeak */ - rate = espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 50, NULL, 0); + rate = espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 0, NULL, 0); if (rate < 0) { fprintf(stderr, "Unable to initialize espeak.\n"); return -1; From 70ae4dece7b30153291539b04e8b9e6d069d5ba1 Mon Sep 17 00:00:00 2001 From: Alexander Epaneshnikov Date: Wed, 22 Apr 2020 18:38:06 +0300 Subject: [PATCH 136/181] enlaarge voice buf this will fix #9 --- espeakup.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/espeakup.h b/espeakup.h index 2e2295f..70e3b5e 100644 --- a/espeakup.h +++ b/espeakup.h @@ -70,7 +70,7 @@ struct synth_t { int range; int punct; int rate; - char voice[10]; + char voice[20]; int volume; char *buf; int len; From ee05f278f245e9986ff805d05d4941a5bc36a3b3 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Mon, 9 Nov 2020 20:37:46 +0100 Subject: [PATCH 137/181] Add support for indexing --- espeak.c | 19 ++++++++++--------- espeakup.h | 2 ++ softsynth.c | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/espeak.c b/espeak.c index a32bde8..acee6e1 100644 --- a/espeak.c +++ b/espeak.c @@ -47,7 +47,7 @@ const int volumeMultiplier = 22; volatile int stop_requested = 0; int paused_espeak = 1; -static int acsint_callback(short *wav, int numsamples, espeak_EVENT * events) +static int callback(short *wav, int numsamples, espeak_EVENT * events) { int i; for (i = 0; events[i].type != espeakEVENT_LIST_TERMINATED; i++) { @@ -55,8 +55,7 @@ static int acsint_callback(short *wav, int numsamples, espeak_EVENT * events) int mark = atoi(events[i].id.name); if ((mark < 0) || (mark > 255)) continue; - putchar(mark); - fflush(stdout); + softsynth_reportindex(mark); } } return 0; @@ -327,9 +326,7 @@ static void reinitialize_espeak(struct synth_t *s) return; } - /* We need a callback in acsint mode, but not in speakup mode. */ - if (espeakup_mode == ESPEAKUP_MODE_ACSINT) - espeak_SetSynthCallback(acsint_callback); + espeak_SetSynthCallback(callback); /* Set parameters again */ espeak_SetVoiceByName(s->voice); @@ -345,6 +342,7 @@ static void reinitialize_espeak(struct synth_t *s) static void queue_process_entry(struct synth_t *s) { espeak_ERROR error; + char markbuff[50]; static struct espeak_entry_t *current = NULL; if (current != queue_peek(synth_queue)) { @@ -362,6 +360,11 @@ static void queue_process_entry(struct synth_t *s) case CMD_SET_FREQUENCY: error = set_frequency(s, current->value, current->adjust); break; + case CMD_SET_MARK: + snprintf(markbuff, sizeof(markbuff), "", current->value); + error = espeak_Synth(markbuff, strlen(markbuff)+1, 0, POS_CHARACTER, + 0, espeakSSML, NULL, NULL); + break; case CMD_SET_PITCH: error = set_pitch(s, current->value, current->adjust); break; @@ -413,9 +416,7 @@ int initialize_espeak(struct synth_t *s) return -1; } - /* We need a callback in acsint mode, but not in speakup mode. */ - if (espeakup_mode == ESPEAKUP_MODE_ACSINT) - espeak_SetSynthCallback(acsint_callback); + espeak_SetSynthCallback(callback); /* Setup initial voice parameters */ if (defaultVoice && defaultVoice[0]) { diff --git a/espeakup.h b/espeakup.h index 70e3b5e..b0c685b 100644 --- a/espeakup.h +++ b/espeakup.h @@ -38,6 +38,7 @@ enum espeakup_mode_t { enum command_t { CMD_SET_FREQUENCY, + CMD_SET_MARK, CMD_SET_PITCH, CMD_SET_RANGE, CMD_SET_PUNCTUATION, @@ -87,6 +88,7 @@ extern void *espeak_thread(void *arg); extern int open_softsynth(void); extern void close_softsynth(void); extern void *softsynth_thread(void *arg); +extern void softsynth_reportindex(int index); extern volatile int should_run; extern volatile int stop_requested; extern int paused_espeak; diff --git a/softsynth.c b/softsynth.c index 574d37e..9e1d66f 100644 --- a/softsynth.c +++ b/softsynth.c @@ -124,6 +124,9 @@ static int process_command(struct synth_t *s, char *buf, int start) case 'f': cmd = CMD_SET_FREQUENCY; break; + case 'i': + cmd = CMD_SET_MARK; + break; case 'p': cmd = CMD_SET_PITCH; break; @@ -328,3 +331,16 @@ void *softsynth_thread(void *arg) pthread_mutex_unlock(&queue_guard); return NULL; } + +void softsynth_reportindex(int index) +{ + if (espeakup_mode == ESPEAKUP_MODE_ACSINT) { + putchar(index); + fflush(stdout); + } else { + char buf[16]; + snprintf(buf, sizeof(buf), "%d", index); + if (write(softFD, buf, strlen(buf)) < 0) + perror("Writing index failed"); + } +} From 9ccabf55b6848fea02285f038f39debc8bef82e0 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Mon, 14 Jun 2021 12:56:57 -0500 Subject: [PATCH 138/181] update README - Remove the unnecessary references to tarballs since this is now a standard github project. - Point people to the bug tracker for filing bugs. --- README | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/README b/README index b8ed359..610f224 100644 --- a/README +++ b/README @@ -41,19 +41,6 @@ Espeakup currently accepts the following command line options: --help, -h Show this help. --version, -v Display the software version. -Getting the Latest Version -========================== - -It is possible to download a tarball from github of any released version -as follows: - -wget http://www.github.com/williamh/espeakup/tarball/vx.y - -If you need a tarball for packaging purposes, one is available from -ftp://ftp.linux-speakup.org/pub/linux/goodies/espeakup-x.y.tar.bz2. - -The url for the git repository is git://github.com/williamh/espeakup.git. - Acknowledgements ================ @@ -62,9 +49,9 @@ TTSynth connector, on which this work is based. Also, I would like to thank Kirk Reiser and Jonathan Duddington, the authors of Speakup and Espeak, respectively, for their work. -Questions -========= +Filing Bugs +==== + +Bugs should be filed on our bug tracker at +https://github.com/linux-speakup/issues. -You can contact me with questions, bugs, patches, etc, at -w.d.hubbs@gmail.com or on the speakup mailing list. I hope you find -this software to be useful. From a464461f0e0cbcb126c7c25829ec5f7ac3ded1b8 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Mon, 14 Jun 2021 13:09:34 -0500 Subject: [PATCH 139/181] convert README to markdown --- README => README.md | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) rename README => README.md (88%) diff --git a/README b/README.md similarity index 88% rename from README rename to README.md index 610f224..ebe56bc 100644 --- a/README +++ b/README.md @@ -1,12 +1,10 @@ -espeakup connector -======================= +# espeakup connector espeakup is a program which makes it possible for speakup to use the espeak software synthesizer. It does this by reading speakup's softsynth device and passing the text to espeak which actually speaks. -Requirements -============ +## Requirements This program works with the speakup screen reader, which can be obtained from http://linux-speakup.org, and the espeak software speech @@ -14,8 +12,7 @@ synthesizer which can be obtained from http://espeak.sourceforge.net. You must have both of these installed and operational. Setting them up is beyond the scope of this document. -Installation -============ +## Installation The preferred way to install espeakup is using your distribution's packaging system, but if your distribution does not have a package for @@ -23,16 +20,14 @@ espeakup yet, espeakup just uses a Makefile, so you should be able to change to the source directory, then type make, then as root, make install. -Starting Up -=========== +## Starting Up This program should be run after speakup is set up to communicate with a software synthesizer and after /dev/softsynth exists. The way this is done is distribution specific, so it is beyond the scope of this documentation. -Command Line Options -==================== +## Command Line Options Espeakup currently accepts the following command line options: @@ -41,16 +36,14 @@ Espeakup currently accepts the following command line options: --help, -h Show this help. --version, -v Display the software version. -Acknowledgements -================ +## Acknowledgements I would like to thank Marc Mulcahy, the author of the speakup to TTSynth connector, on which this work is based. Also, I would like to thank Kirk Reiser and Jonathan Duddington, the authors of Speakup and Espeak, respectively, for their work. -Filing Bugs -==== +## Filing Bugs Bugs should be filed on our bug tracker at https://github.com/linux-speakup/issues. From 201ae667ee9ae4dcd0f8ff5a7cc35537ccae6056 Mon Sep 17 00:00:00 2001 From: Alexander Epaneshnikov Date: Mon, 14 Jun 2021 21:45:53 +0300 Subject: [PATCH 140/181] link with espeak-ng by default (#25) --- Makefile | 2 +- README.md | 11 ++++++----- espeakup.h | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 3cbb608..362e488 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ DEPFLAGS = -MMD WARNFLAGS = -Wall CFLAGS += ${DEPFLAGS} ${WARNFLAGS} -LDLIBS = -lespeak -lpthread -lasound -lm +LDLIBS = -lespeak-ng -lpthread -lasound -lm INSTALL = install BINMODE = 0755 diff --git a/README.md b/README.md index ebe56bc..a69a5df 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,16 @@ # espeakup connector espeakup is a program which makes it possible for speakup to use -the espeak software synthesizer. It does this by reading speakup's -softsynth device and passing the text to espeak which actually speaks. +the espeak-ng software synthesizer. It does this by reading speakup's +softsynth device and passing the text to espeak-ng which actually speaks. ## Requirements This program works with the speakup screen reader, which can be obtained -from http://linux-speakup.org, and the espeak software speech -synthesizer which can be obtained from http://espeak.sourceforge.net. +from http://linux-speakup.org, and the +[espeak-ng](https://github.com/espeak-ng/espeak-ng) software speech +synthesizer. + You must have both of these installed and operational. Setting them up is beyond the scope of this document. @@ -47,4 +49,3 @@ authors of Speakup and Espeak, respectively, for their work. Bugs should be filed on our bug tracker at https://github.com/linux-speakup/issues. - diff --git a/espeakup.h b/espeakup.h index b0c685b..49c17c4 100644 --- a/espeakup.h +++ b/espeakup.h @@ -24,7 +24,7 @@ #include #include -#include +#include #include "queue.h" From b5c1aef849c04dfcb5d670a6ba2db6bb9581af22 Mon Sep 17 00:00:00 2001 From: Alexander Epaneshnikov Date: Sun, 26 Apr 2020 19:26:46 +0300 Subject: [PATCH 141/181] add systemd unit --- autostart/systemd/espeakup.conf | 1 + autostart/systemd/espeakup.service | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 autostart/systemd/espeakup.conf create mode 100644 autostart/systemd/espeakup.service diff --git a/autostart/systemd/espeakup.conf b/autostart/systemd/espeakup.conf new file mode 100644 index 0000000..56aebc1 --- /dev/null +++ b/autostart/systemd/espeakup.conf @@ -0,0 +1 @@ +default_voice= diff --git a/autostart/systemd/espeakup.service b/autostart/systemd/espeakup.service new file mode 100644 index 0000000..85c1f55 --- /dev/null +++ b/autostart/systemd/espeakup.service @@ -0,0 +1,16 @@ +[Unit] +Description=Software speech output for Speakup +# espeakup needs to start after the audio devices appear, hopefully this should go away in the future +Wants=systemd-udev-settle.service +After=systemd-udev-settle.service sound.target + +[Service] +Type=forking +EnvironmentFile=/etc/conf.d/espeakup +PIDFile=/run/espeakup.pid +ExecStart=/usr/bin/espeakup --default-voice=${default_voice} +ExecReload=/bin/kill -HUP $MAINPID +Restart=always + +[Install] +WantedBy=sound.target From 6689948a8a609d09a3a874b6343db8267cb8844a Mon Sep 17 00:00:00 2001 From: Alexander Epaneshnikov Date: Thu, 28 Jan 2021 01:24:25 +0300 Subject: [PATCH 142/181] add espeakup manual in unit file --- autostart/systemd/espeakup.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autostart/systemd/espeakup.service b/autostart/systemd/espeakup.service index 85c1f55..c27a5eb 100644 --- a/autostart/systemd/espeakup.service +++ b/autostart/systemd/espeakup.service @@ -1,6 +1,6 @@ [Unit] Description=Software speech output for Speakup -# espeakup needs to start after the audio devices appear, hopefully this should go away in the future +Documentation=man:espeakup(8) Wants=systemd-udev-settle.service After=systemd-udev-settle.service sound.target From 3fb775cc335a1e65c75245288a7ac811e2e792a6 Mon Sep 17 00:00:00 2001 From: Alexander Epaneshnikov Date: Thu, 28 Jan 2021 02:23:19 +0300 Subject: [PATCH 143/181] load speakup_soft kernel module --- autostart/systemd/espeakup.service | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/autostart/systemd/espeakup.service b/autostart/systemd/espeakup.service index c27a5eb..b840489 100644 --- a/autostart/systemd/espeakup.service +++ b/autostart/systemd/espeakup.service @@ -8,8 +8,9 @@ After=systemd-udev-settle.service sound.target Type=forking EnvironmentFile=/etc/conf.d/espeakup PIDFile=/run/espeakup.pid +ExecStartPre=+/sbin/modprobe speakup_soft ExecStart=/usr/bin/espeakup --default-voice=${default_voice} -ExecReload=/bin/kill -HUP $MAINPID +ExecReload=kill -HUP $MAINPID Restart=always [Install] From 335d748a6388567fd49b95c3288300d87a228686 Mon Sep 17 00:00:00 2001 From: Alexander Epaneshnikov Date: Thu, 23 Apr 2020 14:47:12 +0300 Subject: [PATCH 144/181] new src structure to make it more understandable and convenient for further improvements. --- .gitignore | 5 ++--- Makefile | 19 +++++++------------ ChangeLog => doc/ChangeLog | 0 TODO => doc/TODO | 0 espeakup.8 => doc/espeakup.8 | 0 cli.c => src/cli.c | 0 espeak.c => src/espeak.c | 0 espeakup.c => src/espeakup.c | 0 espeakup.h => src/espeakup.h | 0 queue.c => src/queue.c | 0 queue.h => src/queue.h | 0 signal.c => src/signal.c | 0 softsynth.c => src/softsynth.c | 0 stringhandling.c => src/stringhandling.c | 0 stringhandling.h => src/stringhandling.h | 0 15 files changed, 9 insertions(+), 15 deletions(-) rename ChangeLog => doc/ChangeLog (100%) rename TODO => doc/TODO (100%) rename espeakup.8 => doc/espeakup.8 (100%) rename cli.c => src/cli.c (100%) rename espeak.c => src/espeak.c (100%) rename espeakup.c => src/espeakup.c (100%) rename espeakup.h => src/espeakup.h (100%) rename queue.c => src/queue.c (100%) rename queue.h => src/queue.h (100%) rename signal.c => src/signal.c (100%) rename softsynth.c => src/softsynth.c (100%) rename stringhandling.c => src/stringhandling.c (100%) rename stringhandling.h => src/stringhandling.h (100%) diff --git a/.gitignore b/.gitignore index 7870fbc..d1c8b4b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ espeakup -*.d -*.o -*.swp +src/*.d +src/*.o diff --git a/Makefile b/Makefile index 362e488..a2680ca 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ PREFIX = /usr/local BINDIR = ${PREFIX}/bin MANDIR = ${PREFIX}/share/man +SRC_DIR = src DEPFLAGS = -MMD WARNFLAGS = -Wall @@ -13,15 +14,8 @@ BINMODE = 0755 MANMODE = 0644 CHANGELOG_LIMIT?= --after="1 year ago" -SRCS = cli.c \ - espeak.c \ - espeakup.c \ - queue.c \ - signal.c \ - softsynth.c \ - stringhandling.c - -OBJS = ${SRCS:.c=.o} +SRC = $(wildcard $(SRC_DIR)/*.c) +OBJECTS := $(patsubst %.c,%.o,$(wildcard $(SRC_DIR)/*.c)) all: espeakup @@ -32,12 +26,13 @@ install: espeakup ${INSTALL} -d ${DESTDIR}${BINDIR} ${INSTALL} -m ${BINMODE} $< ${DESTDIR}${BINDIR} ${INSTALL} -d ${DESTDIR}${MANDIR}/man8 - ${INSTALL} -m ${MANMODE} espeakup.8 ${DESTDIR}${MANDIR}/man8 + ${INSTALL} -m ${MANMODE} doc/espeakup.8 ${DESTDIR}${MANDIR}/man8 -espeakup: ${OBJS} +espeakup: ${OBJECTS} + cc $(LDLIBS) -o ./espeakup $(OBJECTS) clean: - ${RM} *.d *.o + ${RM} $(SRC_DIR)/*.d $(SRC_DIR)/*.o distclean: clean ${RM} espeakup diff --git a/ChangeLog b/doc/ChangeLog similarity index 100% rename from ChangeLog rename to doc/ChangeLog diff --git a/TODO b/doc/TODO similarity index 100% rename from TODO rename to doc/TODO diff --git a/espeakup.8 b/doc/espeakup.8 similarity index 100% rename from espeakup.8 rename to doc/espeakup.8 diff --git a/cli.c b/src/cli.c similarity index 100% rename from cli.c rename to src/cli.c diff --git a/espeak.c b/src/espeak.c similarity index 100% rename from espeak.c rename to src/espeak.c diff --git a/espeakup.c b/src/espeakup.c similarity index 100% rename from espeakup.c rename to src/espeakup.c diff --git a/espeakup.h b/src/espeakup.h similarity index 100% rename from espeakup.h rename to src/espeakup.h diff --git a/queue.c b/src/queue.c similarity index 100% rename from queue.c rename to src/queue.c diff --git a/queue.h b/src/queue.h similarity index 100% rename from queue.h rename to src/queue.h diff --git a/signal.c b/src/signal.c similarity index 100% rename from signal.c rename to src/signal.c diff --git a/softsynth.c b/src/softsynth.c similarity index 100% rename from softsynth.c rename to src/softsynth.c diff --git a/stringhandling.c b/src/stringhandling.c similarity index 100% rename from stringhandling.c rename to src/stringhandling.c diff --git a/stringhandling.h b/src/stringhandling.h similarity index 100% rename from stringhandling.h rename to src/stringhandling.h From 512a958dad044c1e19bfa619b41a80c562d45d98 Mon Sep 17 00:00:00 2001 From: Alexander Epaneshnikov Date: Fri, 22 Jan 2021 01:24:48 +0300 Subject: [PATCH 145/181] remove changelog we can do better than that. --- doc/ChangeLog | 1806 ------------------------------------------------- 1 file changed, 1806 deletions(-) delete mode 100644 doc/ChangeLog diff --git a/doc/ChangeLog b/doc/ChangeLog deleted file mode 100644 index b276f00..0000000 --- a/doc/ChangeLog +++ /dev/null @@ -1,1806 +0,0 @@ -commit 2964310b2411c10756712ba902687e8388c78142 -Author: William Hubbs -Commit: William Hubbs - - makefile: add target to generate changelog - -commit 918e8853cdd8270c77f641c69871851effe18416 -Author: William Hubbs -Commit: William Hubbs - - version 0.80 - -commit 3e5815429bd702d9b0af68d793e6c83f035f9e23 -Author: William Hubbs -Commit: William Hubbs - - Add my email address to the copyright statement - -commit 8b49d9d211f917f7ee2009569f746659ec9096a8 -Author: Christopher Brannon -Commit: William Hubbs - - Fix implicit function declaration warning. - - This fixes #7 - -commit 97adab70de5e49dde3ac26774a636cbca48558c0 -Author: Christopher Brannon -Commit: William Hubbs - - Replace usage of daemon(3). - - Original patch and commit message courtesy of: - Samuel Thibault - - currently espeakup uses daemon() to do the daemonizing stuff. - Unfortunately, daemon() does things not very appropriately, and there - is notably a delay between the parent exit()ing and the child writing - the pid file. The attached patch reimplements it properly, espeakup - then notably plays much more nicely with systemd. - - Modified by Chris to apply to master. - This fixes #8. - -commit 92903254894d2b6f2c398a104e78d15553de6017 -Author: Christopher Brannon -Commit: William Hubbs - - Fix spelling keystrokes and char-by-char echo. - - Use ssml's interpret-as="characters" setting when the kernel reports - just one character. This allows the use of espeak's internationalized - spelling of letters instead of having to maintain spelling ourselves in speakup. - - Original patch courtesy of - Samuel Thibault - and modified to work with the current code by Chris. - - This fixes #6. - -commit ee099174d849e32bf7b555e458963d27f84c64b2 -Author: Samuel Thibault -Commit: William Hubbs - - Allow a voice to be selected by language name - - This allows the -V option on the command line to be a language name. - -commit c1ad891f2e321b052802a2c3c121522757948e61 -Author: Samuel Thibault -Commit: William Hubbs - - Create pid file when espeakup is really ready - - This makes sure that we do not report that we are ready until everything - is initialized. - -commit d97724373556e5ad6d632249bcc0ba4ef7aec4d8 -Author: Christopher Brannon -Commit: William Hubbs - - Add a missing #include, so that this can be built with musl. - - This closes #5. - -commit d95ee07775f6a63d80323e5ea242c530adf9c79b -Author: William Hubbs -Commit: William Hubbs - - Revert "add indexing support" - - This reverts commit e84e000b3ec9d393d720845a5f5fd05aa2ee7302. - I need to think more about how to implement this. - -commit e84e000b3ec9d393d720845a5f5fd05aa2ee7302 -Author: William Hubbs -Commit: William Hubbs - - add indexing support - -commit 3fbbdf19224c26b80b161666b37cec70ac5dd6d2 -Author: William Hubbs -Commit: William Hubbs - - Do not try to remove the pid file unless we are in speakup mode - -commit 58ed438f00c0f79c87885b73292c3b4e5c44e0d4 -Author: William Hubbs -Commit: William Hubbs - - rework two if statements - - These if statements were executing code if we were not in acsint mode. - They have been combined and the code is now executed when we are in - speakup mode, which is what we want. - -commit b2bd1d33a8a8d08ea9316bcf3cf8169545e7df78 -Author: William Hubbs -Commit: William Hubbs - - make espeakup's default rate closer to espeak's default - -commit 3b4b6d0cbc98d175f00a9f1e744406e3491c6d85 -Author: William Hubbs -Commit: William Hubbs - - change code to use allocMem wrapper for memory allocation - - One of the new string handling routines is a wrapper for allocating - memory. This commit changes the rest of the code to take advantage of - that wrapper. - -commit 6180ff6e49371d9fc1cfb5afb05941222d925d70 -Author: Christopher Brannon -Commit: Christopher Brannon - - Don't check to see if espeakup is running in acsint mode. - - This check is important when running with speakup, since there can only - be one instance accessing /dev/softsynth. - It is unnecessary in acsint mode. - -commit ba316a4cd4ad42b5cf7a550953c1dc26338e3569 -Author: William Hubbs -Commit: William Hubbs - - separate string handling routines into their own module - -commit c06f18c4544a6e9e3d28b8f037bc40588fbff3f5 -Author: Christopher Brannon -Commit: William Hubbs - - support adapters using the acsint module - -commit 70f74657c274d37f94cf7a4eabcd1d06bafbfcb5 -Author: William Hubbs -Commit: William Hubbs - - fix Makefile to use MANMODE to install man pages - -commit 999e6551b5999f5779299e51858e4bbb587f5561 -Author: William Hubbs -Commit: William Hubbs - - add pid path option to help - -commit 3353241a79f0e2b130dce5e98d656284a7da84f8 -Author: William Hubbs -Commit: William Hubbs - - add command line option to change the pid path - - This adds a -P or --pid-path option to the command line which - allows the user to change the path and the name of the pid file created - when espeakup is running as a daemon. - - I would like to thank Chris Brannon for the original idea for this. - -commit 49dcacb2eca6f808f1f52a4faaf96f1fae24e4b5 -Author: William Hubbs -Commit: William Hubbs - - adjust rate offset and multiplier for espeak 1.45.04 - -commit 2154d1a23157cc2b0ff72f1ed51e5c8a26b452cb -Author: William Hubbs -Commit: William Hubbs - - use memset to initialize sigaction structure - -commit 1990e8e25d23fd4cbaa924ac7af480e2a079b9dc -Author: Christopher Brannon -Commit: William Hubbs - - Properly initialize sigaction struct. - - The sigaction struct used in signal_thread was stored in an automatic - variable. The fields which were not set manually had undefined values. - -commit 701074fd9685ce4133672fbb35f046e76ab13422 -Author: William Hubbs -Commit: William Hubbs - - go back to just using a makefile - - The reason I went to autotools was the multiple sound systems, but since - we are now just using espeak's audio processing we can go back to a more - simple build system. - -commit 7bf2eee07a6c5d2120e62d13e0385e4c8e9c6782 -Author: William Hubbs -Commit: William Hubbs - - remove experimental alsa support - - The direct alsa support was experimental and never worked well. It had a - setting which was system specific. Also, I feel that it is better to let - espeak control the audio processing. - -commit c7ae47dfe59481b29ec80de2faaa6c8d3bd63379 -Author: William Hubbs -Commit: William Hubbs - - add experimental support for building a static binary - - This is done by adding a --enable-standalone switch to the configure - script. - -commit 3bfc662bae54038172de1c52b04e9c589d2f7bd0 -Author: William Hubbs -Commit: William Hubbs - - update location of latest version and git repository - -commit 037e6422179424dd40667765039c6584ac306514 -Author: William Hubbs -Commit: William Hubbs - - rename todo file - -commit 0d9d7b61419eb37247e8f7afb6c5b7ff198f0ab7 -Author: William Hubbs -Commit: William Hubbs - - update readme - -commit 056dcf70fe5a6850b73193ea06480bd955695e2e -Author: William Hubbs -Commit: William Hubbs - - convert to autotools - -commit d1630432ba55033c82da0dcae4a409f14da8d03f -Author: William Hubbs -Commit: William Hubbs - - re-organized the makefile. - -commit 8fda956e020abcde9365c20c6e14f3ebc15cd2e1 -Author: William Hubbs -Commit: William Hubbs - - fixed permissions in makefile - - It turns out that the install commands need to have the permission - options otherwise the permission of everything that is installed is 755, - which is not correct. - -commit 4cfcd7ba116ddd3e1c80744b4eb7e0b83438ec86 -Author: William Hubbs -Commit: William Hubbs - - fixed mandir - - the mandir variable in the makefile should point only to the top level - of the man tree. - -commit 1a10788c5f140f75e0f54a2baaf8625125bb52ac -Author: William Hubbs -Commit: William Hubbs - - lowered latency setting to 1/40 of a second. - -commit edb5e50fcd52d6f0ed9d2decb5c874dfd9395998 -Author: William Hubbs -Commit: William Hubbs - - make alsa code more readable - - This changes the code to use constants for the parameters to - snd_pcm_set_params. This makes it easier to read the code and to update - the values if needed. - -commit dec561324df67bd64eede09bcb2eb25273a04081 -Author: William Hubbs -Commit: William Hubbs - - updates to alsa support - - After studying pcm_min.c in the alsa library git repository, I updated - the alsa support to be similar to what I saw there. - -commit 486fe27f47d12a0482060aac4fc6c1568fab0613 -Author: William Hubbs -Commit: William Hubbs - - removed permission settings from makefile - -commit 311b6911959263a81f4dd74b44ad93af53a981b1 -Author: William Hubbs -Commit: William Hubbs - - fix makefile to not define variables if they are already defined - -commit ffe397fb911b0de8a14cacfc69bf9e683c9ef402 -Author: William Hubbs -Commit: William Hubbs - - removed the minimum function - - This function really wasn't needed. I also attempted to make the - callback functionn more like the test code in the alsa library git - repository. - -commit e66311bb992122ca4797eab1d2a79b1619c71b9b -Author: William Hubbs -Commit: William Hubbs - - added automatic dependency tracking to the Makefile - -commit 11cc053d822d563b9c040ce50341f8c8cd8b4f86 -Author: William Hubbs -Commit: William Hubbs - - reworked the makefile - - This version of the makefile should be more compatible with allowing - users to pass in cflags. - -commit 48fa03faf5529a4072ae50fe9ff983333bc6fca0 -Author: William Hubbs -Commit: William Hubbs - - renamed espeak_sound.c to portaudio.c - - This better describes the sound system that espeak uses natively. - -commit 654fc810fe981907d3f17d212ae51d9d6124fa42 -Author: William Hubbs -Commit: William Hubbs - - default prefix to /usr/local - - Without packaging, we should be installing espeakup in /usr/local. - -commit e4e3f0979e1820712a6a88bfcf60da34a8a747f0 -Author: William Hubbs -Commit: William Hubbs - - the status handle should be static - -commit 57547e8efa0dcf9f7f1750d7e8472f7207d20329 -Author: William Hubbs -Commit: William Hubbs - - renamed synth.c to espeak.c - - The name was changed because it describes the function of this code more - accurately. - -commit ac9e12414b2f4a1b38f8dabdaf7eb5ae33276008 -Author: William Hubbs -Commit: William Hubbs - - made stop_requested a global variable - - The two variables, stop_requested and runner_must_stop were performing - the same function, so I am using one variable, stop_requested for this - function. - -commit 18ebab3247934c71320abed559021fe6eebab530 -Author: William Hubbs -Commit: William Hubbs - - indentation fixes - -commit cc7e77eb9db904f27b9de12f4b25b17c2f6d5b02 -Author: William Hubbs -Commit: William Hubbs - - move stop_audio call to synth thread - - Since there is no reason currently for the softsynth thread to do this, - it makes better sense to have the synth thread control all interaction - with espeak. - -commit 32d848cb76de9853564d7e2ea37725c1f9af1ae4 -Author: William Hubbs -Commit: William Hubbs - - make callback honor should_run - - The callback should return and abort synthesis if should_run is 0. This - fixes slow shutdown times in alsa mode. - -commit 4de82bf24cff9e5a82a2645f30af0dbfae6ded05 -Author: William Hubbs -Commit: William Hubbs - - added a couple of #defines to the alsa code - -commit 739e074072100dd420b10eb1d8b8d55451b9bdea -Author: William Hubbs -Commit: William Hubbs - - reworked the queue_remove function - - Now, when queue_remove is called, it returns the pointer to the data of - the first entry in the queue and removes the entry. - -commit 014d27b7aa218db968ab19b2b493fe95406b4b8b -Author: William Hubbs -Commit: William Hubbs - - removed some unlock_audio_mutex() calls - -commit 82490a98d253d5201f93f309289346fff5169abc -Author: William Hubbs -Commit: William Hubbs - - call snd_pcm_prepare after snd_pcm_drop in stop_audio - -commit 101e14901e0517f6f09024dc8dc1f47dc682227a -Author: William Hubbs -Commit: William Hubbs - - removed white space in the makefile - -commit dc056e6c773e203af74d290393819b7fdc4043e0 -Author: William Hubbs -Commit: William Hubbs - - broke the queue definitions out into their own header file - -commit 0a9a8cce9bcb0310903aaffafd2dbdbe5a6458c4 -Author: William Hubbs -Commit: William Hubbs - - small style changes - -commit 40479540b4c8dd6a876b084bce0e6c806033da06 -Author: Christopher Brannon -Commit: William Hubbs - - Fix a memory leak. - - If we fail to add entries to the queue in queue_add_cmd or - queue_add_text, properly free the entry. - -commit ccb8cea91ee1537e24070dbd3cc568e6f24ddb28 -Author: William Hubbs -Commit: William Hubbs - - stop speech before clearing the queue - - Thanks to Kirk Reiser for pointing out that this makes the cancel - response faster. - -commit 31ad5f04ca691228889bd839852d8b19321c86c1 -Author: Christopher Brannon -Commit: William Hubbs - - Completely data-agnostic queue functions. - - The functions in queue.c no longer use static variables. We can now use - them for multiple queues, if necessary. - -commit 011ec271627615be44e1bacd6d269745c86028e9 -Author: Christopher Brannon -Commit: William Hubbs - - Create pipe before starting the signal handler thread. - - The thread can write to the pipe, so the pipe must be initialized - before the thread starts. - -commit 04d10d88ec0bb2161885bc3358a9bc6b5e06ce35 -Author: William Hubbs -Commit: William Hubbs - - more sound updates - - removed the user_data processing code and put the call to snd_pcm_drop - in stop_audio. - -commit ceaae3640a51fad408386f27bb30fe2063cdf58e -Author: William Hubbs -Commit: William Hubbs - - audio should be stopped in softsynth_thread not espeak_thread - -commit c9f871f687c6bd6ef1a562000c53c6762cfa7205 -Author: William Hubbs -Commit: William Hubbs - - see if we need to silence speech before we process the queue - -commit a82bbd81400cfa002835c35ce46a956cc81460ad -Author: William Hubbs -Commit: William Hubbs - - fixed a memory leak - - If we processed an entry from the queue successfully, we were removing - the entry itself from the queue but not freeing the memory allocated to - the entry. - -commit 58f09983f856703e8a06d9b16ef17b7d8728eb4d -Author: William Hubbs -Commit: William Hubbs - - fixed callback return code - - The callback should use the value of stop_requested as its return code. - -commit 0238baa5c29f9fef26b4608be24e4f63b2927e82 -Author: William Hubbs -Commit: William Hubbs - - more alsa updates - - Made an 'if' statement in the callback more clear and added some locking - for the audio mutex. - -commit bcd64cb263745e3994484156713a601db1b59990 -Author: William Hubbs -Commit: William Hubbs - - created a start_audio function - - This moves audio control to the specific files, espeak_sound.c and - alsa.c, which are tied to the sound systems. - -commit 9b7dcebb6d3dd84d19a448e7e79a1746cd939a62 -Author: William Hubbs -Commit: William Hubbs - - alsa updates - - The first while loop in the callback doesn't need to be a loop. If the - audio fails, we can just print an error and return. - -commit 46bf3d99d51960c7a179d9bfd6724c4a428e0658 -Author: William Hubbs -Commit: William Hubbs - - all access of the audio mutex should go through our functions - -commit 87ab6c6ea822f9f7b393d1cb83c9f579d728326a -Author: William Hubbs -Commit: William Hubbs - - make sure that snd_pcm_drop is successful. - - This was suggested by Kirk Reiser and Chris Brannon. - -commit 4889572ad18a8be877916d131d9a101b6563773c -Author: William Hubbs -Commit: William Hubbs - - use user_data to detect old events - - When espeak_Cancel is called, change the value of user_data that is - passed to the events, and, in the callback, use this to test to see if - cancel was received. If the value of user_data has changed, discarde - events that have the old value. This patch is from Chris Brannon. - -commit a9398bdeb413f8c9b88178756e0cdc7ede55b0bc -Author: William Hubbs -Commit: William Hubbs - - Added another error check for alsa - -commit be879d206b52221546e4b8e00b60e0c0cf70f855 -Author: William Hubbs -Commit: William Hubbs - - alsa update - - I changed the name of the callback to alsa_callback and removed a line - that was making the amount of data written to the sound card very small. - -commit c1d33d673838faf8b70cc42c72c119f5c0002d44 -Author: William Hubbs -Commit: William Hubbs - - Set the espeak audio buffer size to 50 ms - - This should help make the cancel command more responsive. - -commit 0471ff47f4dc031cf70b14eb15128fd60fb185dd -Author: William Hubbs -Commit: William Hubbs - - add support for the user_data parameter to espeak_synth - - The user_data parameter is just a pointer that is passed into the - espeak_synth call that is passed back to the callback. In native mode, - we are not using it since there is not a callback. However, in alsa - mode, it will be used to indicate when a cancel was processed. - -commit 520bbae36512731bc075870c0baa9339929b4fde -Author: William Hubbs -Commit: William Hubbs - - renamed stopped to stop_requested - - This is more descriptive of what the variable actually does. It signals - the callback to stop the audio. - -commit 8f3e8f196711d729de6c2dc1ed1ef2d086f99955 -Author: William Hubbs -Commit: William Hubbs - - moved the audio_mutex code to alsa - - This is not needed for native sound support, so it has been moved into - the alsa specific code. - -commit e49acbb59acdbad827da2fc4dd7061e7fe2de35a -Author: William Hubbs -Commit: William Hubbs - - removed a debug print - -commit 24bcdf5666d2546b9177b54b25d2fbfc54ab804b -Author: William Hubbs -Commit: William Hubbs - - another termination fix - - espeak_thread needs to signal softsynth_thread once more as it is going - town so that softsynth_thread will see that should_run is now 0 and - terminate. - -commit 5ec3809c599981f79db87f41f4b181eb5456a4f7 -Author: William Hubbs -Commit: William Hubbs - - wake up espeak_thread when softsynth_thread terminates - - espeak_thread needs a signal since it might be sleeping and - should_run has changed. This makes sure it terminates. - -commit 5ebe506026cf2a5953ba9773d2e2c434e8bbc6f4 -Author: William Hubbs -Commit: William Hubbs - - more mutex fixes - - Make sure that should_run is protected by the mutex in the softsynth - thread. - -commit d5fd5d69b84cdcde67357a5a934b343e46a32cb2 -Author: Chris Brannon -Commit: William Hubbs - - don't wait on a condition variable if should_run is false - -commit 633743117c7067bb7f7a7a12f2edbe6bb463a366 -Author: William Hubbs -Commit: William Hubbs - - mutex fixes - - We need to make sure that should_run is protected by the mutex. - -commit 1750b92cfb0e5d5a39564ea8d949113c4e0c3409 -Author: William Hubbs -Commit: William Hubbs - - fixed signal handling issue - - The signal handler stopped working after I moved the initialization - calls to the main function. Creating the signal handler thread first - fixed this issue. - -commit eb74a3ce171515dd1f2970dfb3d1b6c2f07c6d79 -Author: William Hubbs -Commit: William Hubbs - - removed an unnecessary call to espeak_Terminate() - -commit dd00775695f713667b2fc295feab6a2a2fe1926e -Author: William Hubbs -Commit: William Hubbs - - initialization update - - The main function now initializes espeak and opens the softsynth before - starting the threads. This insures that the resources we need are - active. - -commit 6a15f2cccf4d98e112f09ae64e68773c028b76f6 -Author: William Hubbs -Commit: William Hubbs - - fixed first wait in softsynth thread - - The thread should wait if there is nothing in the queue and if there is - not a request to stop. - Thanks to Chris Brannon for the patch. - -commit 3687f16b09d7ff37f73ca0f98acd8dedd4ce18c1 -Author: William Hubbs -Commit: William Hubbs - - wait for acknowledgements correctly - - pthread_cond_wait() can have spurious wakeups, so we need to be sure - that the condition is actually true when we return from this function. - Thanks to Chris Brannon for the patch. - -commit 938e10b66a14237cdff734ae5b97525f9c4ae9cc -Author: William Hubbs -Commit: William Hubbs - - removed a nested lock/unlock - -commit 975765289b3348219d0db8b2d64e2f4f7747f9f2 -Author: William Hubbs -Commit: William Hubbs - - made sure all cond_wait and cond_signal calls are inside lock/unlock - calls - -commit b8c7247feb05a07bab653cab2a6be50a4a17fd5d -Author: William Hubbs -Commit: William Hubbs - - removed acknowledge_guard and substituted queue_guard - -commit 1091182f884cb8187ce3cdaf3723243deaa4dcb2 -Author: William Hubbs -Commit: William Hubbs - - removed a debug print call - -commit 0bf2cae5a6cd35ea7ee78fbb136ccb58f6937b3e -Author: William Hubbs -Commit: William Hubbs - - moved lock/unlock in queue_process_entry - - The only time queue_process_entry should lock the queue gard is when it - is removing the item from the queue. This happens only when the item - was successfully processed. - -commit 554a03d26c147958b99b78690214e195cda65c41 -Author: William Hubbs -Commit: William Hubbs - - white space fix - -commit b7f324072f26fa31a8d9772f38bdf1f920504223 -Author: Christopher Brannon -Commit: William Hubbs - - Fix concurrency bugs. - - 1. Don't lock or unlock queue_guard during queue_clear. - It is locked when queue_clear is called, and it should remain so. - 2. Protect runner_must_stop with queue_guard in - the request_espeak_stop function. - The following condition should always hold: queue_guard is locked while - testing or modifying runner_must_stop. - 3. Rename stop_guard to acknowledge_guard. This is a more - descriptive name. This mutex simply protects the acknowledgement of - the stop request from being lost. - 4. Remove the pthread_mutex_lock from the top of queue_process_entry, - because queue_guard is already locked when the function is called. - -commit a8cad20de898002465fad6f3cf42f381f2a33812 -Author: William Hubbs -Commit: William Hubbs - - more multithreading work - - Rearranged the queue handling code so that queue.c is generic. Also - rearranged several functions in the threads. - -commit 42c3f76a083890c49fcb7d92a2f695f69e4882b4 -Author: William Hubbs -Commit: William Hubbs - - moved include for pthread.h to espeakup.h - -commit 3e8e7d12ae89b4b2c00596cf88fcb35fd4b5b20e -Author: William Hubbs -Commit: William Hubbs - - added back the declaration for softFD - -commit af5717b8cb3d9c2232f20f90d32601c0f7021fca -Author: William Hubbs -Commit: William Hubbs - - moved queue_add_xxx functions to softsynth thread - -commit c6b57885c9479f4d85831b2082206bef685cd74d -Author: William Hubbs -Commit: William Hubbs - - removed declaration of rate from main - -commit d82bfcd09ccd4145d17473bc9ae60af223a5f66e -Author: Christopher Brannon -Commit: William Hubbs - - Make one thread responsible for handling espeak interaction. - - Most of the idea for this change came from William: - Renamed queue_runner to espeak_thread. Moved espeak initialization - and termination to espeak_thread. The while loops that process - the queue now use the variable should_run. - -commit 0fdca827b851fd0beb9f476c52ec5568ed36174e -Author: William Hubbs -Commit: William Hubbs - - check for terminalFD after select() - - If terminalFD has something to read, we break out of the loop in the - softsynth thread. - -commit 474580b08b32d713ffb6f23c486685f1927e12c0 -Author: William Hubbs -Commit: William Hubbs - - add pipe to wake up the softsynth thread - - This adds a pipe to wake up the softsynth thread, in case we receive a - signal while it is in a select. Thanks to Chris Brannon. - -commit c5fce64f259bce473cd3c9371d7b095639a87fe5 -Author: William Hubbs -Commit: William Hubbs - - removed open_softsynth and close_softsynth - - The thread can now handle the softsynth device, so main doesn't need to - call these functions. - -commit a58f93cd74fead43927093d36fc775a976788a4b -Author: William Hubbs -Commit: William Hubbs - - renamed reader_thread to softsynth_thread - -commit dfc9bbff6518b2de6e4464fd348ae460766606fb -Author: William Hubbs -Commit: William Hubbs - - fixed should_run declaration - - Removed the local declaration of should_run and set up the extern. - -commit 9d1cabdd0d513c45bafdf7cc9c62b503f4a0f31d -Author: William Hubbs -Commit: William Hubbs - - started work on multi-threading more of the program - - The goal is to create threads for the reader, que runner/espeak - processing and signal handling. - As of this commit, this code is still being worked on, so it is broken. - -commit f58d9984ce6d615158d53a6cf1b5d503296973ab -Author: William Hubbs -Commit: William Hubbs - - Now the queue runner/softsynth handler clears the queue - - Thanks to Chris Brannon for the patch. - -commit 24e7d667bce7568585e1e644b1935c8fe0709b75 -Author: William Hubbs -Commit: William Hubbs - - queue fixes - - This adds retry processing back to the queue functions. queue_remove - should only be called after the head entry on the queue is processed - successfully. - -commit 26ab109bd8e14fd3d26a434cac2e5760b23dbf0a -Author: William Hubbs -Commit: William Hubbs - - moved the check for stop out of the loop - - In the callback, we should check to see if the stopped flag is true - whether or not we are processing audio. - -commit b108764b02e0d6eb1e8a3074cf2f85f10eb01d03 -Author: William Hubbs -Commit: William Hubbs - - removed the audio_callback variable - -commit 739d79cff89f2792aa47813e08bdcbb3065c32de -Author: Christopher Brannon -Commit: William Hubbs - - Select audio mode before initializing espeak. - -commit ec9d8b1ee23095afadd07bd05cbf1ca21df11b8f -Author: Christopher Brannon -Commit: William Hubbs - - Add error-checking to the snd_pcm_set_* calls. - - These can fail. They do more than simply manipulate a structure. - -commit a5d1a48f42bbb3de67551113c1f15da10f7b916d -Author: Christopher Brannon -Commit: William Hubbs - - Obtain sample rate from the value of espeak_Initialize. - - espeak uses a sample rate of 22050 HZ, but let's not rely on that knowledge. - espeak_Initialize returns the sample rate on success, - so rely on that value when selecting a rate. - -commit 3bb78df86c3a135660864e1e07c1d5266a575bce -Author: William Hubbs -Commit: William Hubbs - - Do not set the period. - -commit 94e23a3a027dfd887f6713e745a0b97ec09dfbc7 -Author: William Hubbs -Commit: William Hubbs - - fixed error condition check in alsa.c - - The check was looking for a specific error when it should have been just - checking for failure. - -commit a69342fcada7fe6533b81c1ae0bad23f983a399a -Author: William Hubbs -Commit: William Hubbs - - removed some blank lines and put the variables at the top of the file - -commit 91b8960b6add66a982327e68d51f75d25f828af8 -Author: Christopher Brannon -Commit: William Hubbs - - Protect the stopped variable with a mutex. - - An oversight. Should have done this in the initial commit. - volatile does not imply atomic. - -commit 0ad70b4eaa35d57867f20c631f60841fde824e20 -Author: William Hubbs -Commit: William Hubbs - - Revert "fixed stop_speech issue" - - This reverts commit 1c440e5a42ef2606c0330f816b00172ab309505c. - -commit 1d02169aa584ebb8c8739c4b1255abd3ee51e709 -Author: William Hubbs -Commit: William Hubbs - - alsa support is conditional - - This commit updates the makefile and the documentation to explain how to - build alsa support. It has not been fully tested, so it is not built by - default. Also, I was able to remove the conditional compile directives - from the source. - -commit 1c440e5a42ef2606c0330f816b00172ab309505c -Author: William Hubbs -Commit: William Hubbs - - fixed stop_speech issue - - The stop_speech function needs to test the return code from - espeak_Cancel() to be sure the operation was successful before - signaling the callback to stop the audio. - -commit 08e46c58a804c380f73a8be3403663af790a48bd -Author: William Hubbs -Commit: William Hubbs - - indentation fixes - -commit d373fb2aa7fbf673594cd98225877c6998dc99ad -Author: Christopher Brannon -Commit: William Hubbs - - An initial stab at ALSA support. - - It's very raw right now. - -commit b31985f97c30b043dba7b77c5af0b42d3a65fcdd -Author: William Hubbs -Commit: William Hubbs - - released v0.71 - -commit d7dd0f919dc82cc0e497700412980ce771a5d7df -Author: William Hubbs -Commit: William Hubbs - - fixed initialization issues - - We were not returning exit codes properly if we were unable to open the - softsynth or if the daemon was already running. - -commit 2db53856a90a82c99c759399a1dfa5e704ce4f4a -Author: William Hubbs -Commit: William Hubbs - - fixed typo in tarball script - -commit 55f8ebf98a0fd2caef675e22499798b8ead99b12 -Author: William Hubbs -Commit: William Hubbs - - released v0.70 - -commit 69f1e8554a65b3eb0bdfcaf56bbcea86acc7e926 -Author: William Hubbs -Commit: William Hubbs - - The tarball script now adds a ChangeLog - -commit 0e47c95015a8d0ca3c777717f3187bafc615f201 -Author: William Hubbs -Commit: William Hubbs - - updated README - -commit c235a3b063a524cd308f2512c14502b5dee71434 -Author: William Hubbs -Commit: William Hubbs - - added .indent.pro to the repository - -commit d7c81f5117442d66358efb52232d51f45a90d4e8 -Author: William Hubbs -Commit: William Hubbs - - indentation fixes - -commit 3ddbb94e37a5183a0010a2e1ae46f4a64d39bba4 -Author: Christopher Brannon -Commit: William Hubbs - - multithreading - - Make espeakup a multi-threaded program. One thread reads from the softsynth - device, queuing text and synthesis commands. The other thread processes - items from the queue. - -commit 3a8323f98c702443f65b35bbfa84d3ae2c4c9b39 -Author: William Hubbs -Commit: William Hubbs - - Fixed typo in README - -commit e7d300a183668d24cc1250083bd09ab1abcc4cfb -Author: William Hubbs -Commit: William Hubbs - - turn off espeak's default processing of uppercase letters - - This needs to be turned off since speakup processes upper case by - raising the pitch. - -commit a1510b5e93de11dbf70fec2295b30a87656b4824 -Author: William Hubbs -Commit: William Hubbs - - indentation fixes - -commit 3dbdcb21cbb28dc6cebd80077a6e774cc2673bb6 -Author: William Hubbs -Commit: William Hubbs - - Aespeakup should not drop all non-ascii characters. - - This fixes an issue with non-english languages. - Thanks to Samuel Thibault for the patch. - -commit 9551ba81d9bffad667f0d5f864d07c767e2e70e6 -Author: William Hubbs -Commit: William Hubbs - - espeakup 0.60 - -commit 6366b41bdf7b28b392de8ca0c2a246a8360f9293 -Author: William Hubbs -Commit: William Hubbs - - espeakup v0.6 - -commit 40f152e11fb4a89546e459861ac0348c58c8d449 -Author: William Hubbs -Commit: William Hubbs - - allow users to override CFLAGS - - This fixes an issue with the Makefile that was not allowing users to - override cflags and keeping -Wall in the flags when compiling. - -commit 4e7ae23757290ef299a3ba4285bc031de425d788 -Author: William Hubbs -Commit: William Hubbs - - created tarball script - - This commit adds a script to create a tarball from the repository and - removes this functionality from the makefile. - -commit 9ee3fd433cb2513462327fd815f108dc9abc8e8e -Author: William Hubbs -Commit: William Hubbs - - documented --default-voice in man page - - This commit adds the documentation for --default-voice to the espeakup - man page. - -commit e2493db48e69307eeee3390d9329212cb6403613 -Author: William Hubbs -Commit: William Hubbs - - add --default-voice option to the help and README - - This commit adds the documentation to the help and README files for the - --default-voice command line option. - -commit 2351b5d489454c32c4a5c2ccdb1da609ded03b70 -Author: William Hubbs -Commit: William Hubbs - - add support for setting the default voice - - This adds support for a --default-voice or -V (upper case) command line - option which will set the default voice espeakup uses. This takes a - name of an espeak voice -- for example: - - espeakup --default-voice=en-us - - or - - espeakup -V en-us - -commit da15136aa7b8c12024d9178d1ba6b29037984a75 -Author: William Hubbs -Commit: William Hubbs - - only one espeakup daemon should be running - - This fixes a bug which would allow espeakup in debug mode to be run even - if espeakup was already running as a daemon. - -commit 8dca597f29e0ef54525f5f717a7058a037d2e9fc -Author: William Hubbs -Commit: William Hubbs - - Added a version script - - I added a version script. This is used in the Makefile to get the - version of espeakup when none is specified when a tarball is created. - -commit bbf77d918dac93e1bec7fc90c0b8b34dfb5a8e65 -Author: William Hubbs -Commit: William Hubbs - - Cleaned up warnings and adjusted CFLAGS - - This commit cleans up warnings and adjusts CFLAGS. Thanks to - samuel.thibault@ens-lyon.org. - -commit 7db55303088588a19fcde1c804268c984f6008d8 -Author: William Hubbs -Commit: William Hubbs - - Espeakup version 0.51. - -commit 341fa7ba425892c12ae293584aacd9028d520e62 -Author: William Hubbs -Commit: William Hubbs - - fixed install command in makefile. - -commit 0f24afef95c2bdda474d77bc774f19003015da46 -Author: William Hubbs -Commit: William Hubbs - - espeakup v0.5 - -commit c12ec3e1b060b6e3ec1ac53db33b6f87877e9109 -Author: William Hubbs -Commit: William Hubbs - - moved version definition - - This commit moves the version definition to espeakup.c instead of cli.c - -commit a8876a79644f36453a7edaef4c0860c7d2402c9b -Author: William Hubbs -Commit: William Hubbs - - fixed the license in the man page - - The man page said that espeakup is under gpl version 2 or later, but it - is under version 3 or later, so I fixed the man page. - -commit 2b96dd2a026bb2220071699fc51cdf11b9412d82 -Author: William Hubbs -Commit: William Hubbs - - updated man page - - This commit re-words the description of espeakup in the man page. - -commit 17553c3c391e011a1ccf90179c634003d2a61519 -Author: William Hubbs -Commit: William Hubbs - - fixed the makefile - - This commit removes the definitions for CC, RM and INSTALL from the - makefile so that it will use system defaults for these commands. - -commit ace8acf7d01cc256c1df96d3b03e21806772edb5 -Author: William Hubbs -Commit: William Hubbs - - fixed hyphenation - - This commit turns off hypenation in the man page. - -commit 84c473b690633999f47478dbf00c766d1a31628b -Author: William Hubbs -Commit: William Hubbs - - added man page - - This commit adds a man page for espeakup. - Thanks to Chris Brannon for writing it. - -commit f7ddd8dc77927d21a07479f80969df031af396f2 -Author: William Hubbs -Commit: William Hubbs - - Released v0.4. - -commit a3901a7e4c0d273f2ad5352f939714fe235166e4 -Author: William Hubbs -Commit: William Hubbs - - fixed a bug in process_command - - One of the switch statements in process_command did not have a default - label, which lead to undefined behavior. - Thanks to Chris Brannon for the patch. - -commit 36b05aec419a7ab7bc3b66358f62122096ec9ce2 -Author: William Hubbs -Commit: William Hubbs - - Added support for the punctuation command from speakup - -commit c48b05d7437435c0c7513e9d98ab04b565c87f92 -Author: William Hubbs -Commit: William Hubbs - - moved all variable definitions to the top of the Makefile. - -commit 82fa63600b9377fa590a2c97ed737fd8c85a622c -Author: William Hubbs -Commit: William Hubbs - - fixed the makefile - - Added espeakup.h as a dependency in the makefile so that the sources - will be compiled if it changes. - -commit d7e8dc2b342b5a810ec561535ca0426969f519ea -Author: William Hubbs -Commit: William Hubbs - - Revert "fixed the length calculation when a flush is processed." - - This reverts commit 66cb5a7b5cfe0e569525935d03b0843ee85a8afc. - -commit 66cb5a7b5cfe0e569525935d03b0843ee85a8afc -Author: William Hubbs -Commit: William Hubbs - - fixed the length calculation when a flush is processed. - -commit 62deb008bc658d925bd86fb4172b12779b9cad18 -Author: William Hubbs -Commit: William Hubbs - - fixed the number of bytes to move in the memmove() call - -commit 14858818d3cf38886aef5089982522feb9a8edfb -Author: William Hubbs -Commit: William Hubbs - - changed strcpy to memmove - - The areas pointed to by strcpy() cannot overlap, so we need to use - memmove() in case that happens. - Thanks to Chris Brannon for pointing this out. - -commit 6bec55ca5789e26ee315e890f4937c1451b8cd07 -Author: William Hubbs -Commit: William Hubbs - - changed process_buffer to use the isprint() call. - -commit 1b608481a4062f3a8f98192e50acfcb73cf577e2 -Author: William Hubbs -Commit: William Hubbs - - the main loop now uses strrchr and strcpy - - The idea for this change came from another patch submitted by Chris - Brannon. We now use strrchr to look for the flush character and strcpy - to move the remainder of the buffer to the beginning. - -commit faab1893893fa0c97263a0edf965cf4f67bd1294 -Author: William Hubbs -Commit: William Hubbs - - Fixed the select call - - The select call was moved to be in the if statement below it since the - return code is not needed after that statement is processed. - -commit 24607b1cc8000d4d95128e96662240dbce385358 -Author: William Hubbs -Commit: William Hubbs - - made the synth flush character a constant for readability - -commit c8e2a35763624463d1006a83ab0125603813d239 -Author: William Hubbs -Commit: William Hubbs - - fixed an off-by-one error - - The loop can start at length-1 since we know that the last character in - the buffer is a null. - Thanks again to Chris Brannon for finding this. - -commit f76d00f6afefb8de92bf205d16d84f488b91615d -Author: William Hubbs -Commit: William Hubbs - - removed the callback function - - This commit removes the synthcallback function since it wasn't doing - anything. Also, it has been reported that this may be causing the - sluggishness when espeakup is asked to shut up. - Thanks to Chris Brannon for finding this. - -commit 17f07e8cd175520c8fe16880f9f578e0f49579fc -Author: William Hubbs -Commit: William Hubbs - - released v0.3. - -commit 9b0c6a8224980c8637302d9e680cccef4ed0043d -Author: William Hubbs -Commit: William Hubbs - - fixed the volume multiplier - - The volume range is actually 0-200 instead of 0-100, so the multiplier - needed to be adjusted. - -commit c7e3835fbd2ab4d9ae5162488163d22c8bd9c811 -Author: William Hubbs -Commit: William Hubbs - - Updated ToDo list - -commit 527fb136de9d01c752f6f6d03d2ac42b89a94499 -Author: William Hubbs -Commit: William Hubbs - - starting work toward supporting changing voices - - This commit adds a set_voice() function which will ultimately allow the - user to switch voices. - -commit f52c03ec2be8cc67e680eda0cdb6bbb051b858cd -Author: William Hubbs -Commit: William Hubbs - - Fixed a typo. - -commit 8d3552c9642aec00f5ecc89dbbccd181244d9bfa -Author: William Hubbs -Commit: William Hubbs - - updated readme - -commit 1f784be8911bd2917e697630de3da05da2814ab4 -Author: William Hubbs -Commit: William Hubbs - - added support for long command line options - -commit 037019de3a74c191349bebc03289a11ab7cead42 -Author: William Hubbs -Commit: William Hubbs - - Espeakup v0.2 - -commit 943ff9d3dc50184a359ee7b39d57b4baaba0657c -Author: William Hubbs -Commit: William Hubbs - - updated README - -commit 5ddeb1e978bc637b4db22f19d0db8e448599f5e0 -Author: William Hubbs -Commit: William Hubbs - - indentation fixes - -commit ccc9c4aa4ed3f16d3781b92fbd6d6ec013627c5c -Author: William Hubbs -Commit: William Hubbs - - modified rate offset - - This commit moves the rate offset to 84 instead of 80 so that the - highest espeak rate can be reached by setting the speakup rate to - the maximum. - -commit 96a3b198508172e30bb0614563db94f83e45ce03 -Author: William Hubbs -Commit: William Hubbs - - fix flush processing - - This removes flush processing from process_command() and fixes - the code in the main loop so that it does not ignore the 0 position - in the buffer. - -commit 5bc67dc49d61468968b25cda1340091fced573a0 -Author: William Hubbs -Commit: William Hubbs - - updated ToDo list. - -commit 02e72bda39b4c26bcc1a67d701a405427e3a6f8a -Author: William Hubbs -Commit: William Hubbs - - adjusted the rate multiplier - - This gets us closer to espeak's top speed, which is 390 wpm. - -commit ebcbcac9d2b230a37347f60aa3e2715a07bb13a6 -Author: William Hubbs -Commit: William Hubbs - - removed an extra assignment statement - -commit d2d763b36ba477c18a04933ee49b68f71dd641a2 -Author: William Hubbs -Commit: William Hubbs - - moved flush processing into main loop - - This patch from Kirk Reiser attempts to increase - responsiveness by moving the flush processing into the main loop. - -commit 564db7981e1aeda4eb84958d1f66c6474803991f -Author: William Hubbs -Commit: William Hubbs - - put back the select code - - This needed to be put back to keep espeakup from using 100% of the cpu. - -commit 5005b9ddde90aeab3948f9123491463d0e319528 -Author: William Hubbs -Commit: William Hubbs - - removed code that uses select - - I was using the wrong type for the return value for read(). - -commit 3e7e5be2b78bdc1dbaa400d3b8e35ac66eab3cbd -Author: William Hubbs -Commit: William Hubbs - - fixed bug with volume setting - - Now the volume setting should be announced again. - -commit f973c9ec3fa92560279acede8386beeaa5f6835b -Author: William Hubbs -Commit: William Hubbs - - cleaned up prototypes - - This commit gets rid of extra spaces in some function prototypes. - -commit 498ce65db7d789b9639b96240555e48ab3a910b6 -Author: William Hubbs -Commit: William Hubbs - - cleaned up process_command - -commit aac77a3cf1edd6b503bcaada06a575ac06efa6f7 -Author: William Hubbs -Commit: William Hubbs - - ignore object files - -commit de8d4d9dc3bb7afd51eef89c0c7c2fb6d630b7a7 -Author: William Hubbs -Commit: William Hubbs - - fixed an include for gcc 4.3 - -commit b34e397717bae998bd2280a0774a04cd37ea1791 -Author: William Hubbs -Commit: William Hubbs - - clear the queue when we catch a signal - -commit 4c30dac5e16c84d92f12aa06c3cf5279c726d8db -Author: William Hubbs -Commit: William Hubbs - - added prototypes for queue functions - -commit 2bf3b17ffcbb3705afc23957e77fba2dc7abbda9 -Author: William Hubbs -Commit: William Hubbs - - removed debug flag from cflags - -commit 655894ee2a240036e966a5854fc71bb788aebe25 -Author: William Hubbs -Commit: William Hubbs - - added queueing support - - I have added queueing support so that when we read from the softsynth we - can put the text and commands we have read into a queue. This will - allow us to retry calling espeak_synth() if we fill espeak's internal - buffer. - -commit 86e93edeb09774d3689cca7f9fe96aa484f3bd6d -Author: William Hubbs -Commit: William Hubbs - - removed softsynth code from main module - -commit 261c6db032a0c4654c0b77055701223bee055dcb -Author: William Hubbs -Commit: William Hubbs - - Added ToDo list - -commit 029dd03251d24dc5c0a1b0e5a16706c0ca73180d -Author: William Hubbs -Commit: William Hubbs - - modularize the code - - This commit just re-arranges the source so that it is easier to work with. - -commit 882e9c20a547707c2d63a70414de951c50e5d4db -Author: William Hubbs -Commit: William Hubbs - - clean up the main function - - This commit cleans up the main function and moves command line processing - to a separate function. - -commit 4d2f76d6e111bb45cdf336f4be8140bcab3d51b6 -Author: William Hubbs -Commit: William Hubbs - - removed makedist - - The functionality to create a tarball has been moved into the makefile. - Now it is possible to create a tarball by doing: - make tarball - creates a tarball of the llast tagged version. - make TAG=gittag tarball creates a tarball based on the tag that is given to it. - -commit 1802877912be8e4b68541ed07d738841947463fd -Author: William Hubbs -Commit: William Hubbs - - Removed init scripts. - - It will be best to let packagers write init scripts for their distributions, - so I am removing them from this repository. - -commit 3d83e0f6d152035890d7dbecb5961ee79234d476 -Author: William Hubbs -Commit: William Hubbs - - updated readme - - I added an acknowledgements section. - -commit b76fada0b61873bb5228246e2585fea3ca690aba -Author: William Hubbs -Commit: William Hubbs - - fixed makefile - - The reference to $(PROGRAM) should have been $<. - This is fixed. - -commit c2c1d429db31693a60b8e93479a4d4fe5d31588a -Author: William Hubbs -Commit: William Hubbs - - added redhat init script, thanks to William Acker. - -commit c7bece776d13a1c5ac1a52967ffb5cd1b3ed9a9c -Author: William Hubbs -Commit: William Hubbs - - fixed makefile - - There was a bug in the makefile which was not installing the binary correctly. - This is now fixed. - -commit 22ea5c4d1d5db2d4d24e5a89437fac0d6940edf7 -Author: William Hubbs -Commit: William Hubbs - - updated makedist - - The makedist script now excludes itself and .gitignore when creating a tarball. - -commit 9402716c32c124fff4614b1555f7219f0bbe7135 -Author: William Hubbs -Commit: William Hubbs - - cleaned up command line option processing - -commit 05b115abbb8aa1d14b0f1c38c1212918fc9d8c24 -Author: William Hubbs -Commit: William Hubbs - - fixed typos in makedist script. - -commit 16beed096923abea8a7768d1ee6224419faabd0b -Author: William Hubbs -Commit: William Hubbs - - added a script to make tarball releases. - -commit 6ecc3182dab397d7b197e18d7bf78ca8c1316f71 -Author: William Hubbs -Commit: William Hubbs - - added a version command line option and variable. - -commit 96871c66201b77fddf5b80106b8f136fe825df87 -Author: William Hubbs -Commit: William Hubbs - - added destdir and prefix to the makefile for packaging. - -commit c7e0e28ad1102c395958c3baab70b4a8d20203bc -Author: William Hubbs -Commit: William Hubbs - - added gpl - -commit 02c88e949a9e44e16fa7ad6c289f3c476e0becb2 -Author: William Hubbs -Commit: William Hubbs - - adjusted multipliers - - I adjusted the pitch and volume multipliers. - This should allow us to come closer to the maximum espeak settings. - -commit d7de943a3a1b748e2cb27f42af483339de8aa444 -Author: William Hubbs -Commit: William Hubbs - - added frequency support - - This patch, also from Kirk Reiser, adds frequency support. - -commit cddead8aa951e0ad68ba241456a8e5f36c6fb2f5 -Author: William Hubbs -Commit: William Hubbs - - pid file support - - This commit adds support for a pid file so that we can be stopped and - started by init systems. - -commit b51cf9d774cc5a2abd13480238b951e20680ec24 -Author: William Hubbs -Commit: William Hubbs - - Added a signal handler - - This commit adds a signal handler so that espeakup will terminate cleanly. - -commit 61aac5ecb58ac49fc9060d19dde2dbda996e8e9f -Author: William Hubbs -Commit: William Hubbs - - moved some variables - - This commit removes the softsynth file descriptor and the debug flag - from the synth structure. These will need to be accessed from a signal - handler and there is no way to pass the structure to it. - Also, the process_data function now works with local variables and assigns - them to the synth structure, avoiding allocating a buffer with malloc/free. - -commit eb5cb3d36d35887907e13aeee0cad8fcc1b73baa -Author: William Hubbs -Commit: William Hubbs - - fixed volume - - I applied another patch from Kirk Reiser which fixes the volume setting. - Thanks to Kirk for the patch. - -commit 7604cac68c53dd3c01cfc0e131e2a7f985b40ff7 -Author: William Hubbs -Commit: William Hubbs - - 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". - -commit b745e0c48b614143fb4df04ba878af29f4ece587 -Author: William Hubbs -Commit: William Hubbs - - more error checking - - I moved the read call out of process_data and into the main loop. - Also, error checking was added for select() and read(). - -commit c3b0e8d0da9efdf9e719ba3fbe599640a5db7dce -Author: William Hubbs -Commit: William Hubbs - - code cleanup - - This patch adds the length of the buffer to the synth structure and - clears the buffer before we use it. - Thanks to Kirk Reiser for the patch. - -commit c4839ac78b967b4677531afe7568156c907e6bda -Author: William Hubbs -Commit: William Hubbs - - added maxBufferSize constant - -commit 754358f1731e58990b4c4131d4b900a5d2a5049a -Author: William Hubbs -Commit: William Hubbs - - added cli option support - - This commit adds support for command line options and also adds a debug option. - -commit 572f33337811973091f44e54e6b4fcb13ae689d9 -Author: William Hubbs -Commit: William Hubbs - - added volume support - - I added support for setting the volume. - -commit 4e3bbdb0b02eb1f12c087909e6437a31a9c60d7b -Author: William Hubbs -Commit: William Hubbs - - initial import From 2f3d1718634cd112935725467a89140026a41150 Mon Sep 17 00:00:00 2001 From: Alexander Epaneshnikov Date: Tue, 15 Jun 2021 00:25:10 +0300 Subject: [PATCH 146/181] update issue url --- src/espeakup.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/espeakup.h b/src/espeakup.h index 49c17c4..9518c6d 100644 --- a/src/espeakup.h +++ b/src/espeakup.h @@ -29,7 +29,7 @@ #include "queue.h" #define PACKAGE_VERSION "0.81" -#define PACKAGE_BUGREPORT "http://github.com/williamh/espeakup/issues" +#define PACKAGE_BUGREPORT "https://github.com/linux-speakup/espeakup/issues" enum espeakup_mode_t { ESPEAKUP_MODE_SPEAKUP, From c69d98cde62dcab91c4f7042558208ba58cbc116 Mon Sep 17 00:00:00 2001 From: Alexander Epaneshnikov Date: Sat, 9 May 2020 20:30:36 +0300 Subject: [PATCH 147/181] clean makefile get rid of unnecessary targets. add warning options. --- Makefile | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index a2680ca..d8d47a5 100644 --- a/Makefile +++ b/Makefile @@ -2,9 +2,10 @@ PREFIX = /usr/local BINDIR = ${PREFIX}/bin MANDIR = ${PREFIX}/share/man SRC_DIR = src - DEPFLAGS = -MMD -WARNFLAGS = -Wall +WARNFLAGS = -Wall -Wpedantic \ + -Wextra + CFLAGS += ${DEPFLAGS} ${WARNFLAGS} LDLIBS = -lespeak-ng -lpthread -lasound -lm @@ -12,16 +13,12 @@ LDLIBS = -lespeak-ng -lpthread -lasound -lm INSTALL = install BINMODE = 0755 MANMODE = 0644 -CHANGELOG_LIMIT?= --after="1 year ago" SRC = $(wildcard $(SRC_DIR)/*.c) OBJECTS := $(patsubst %.c,%.o,$(wildcard $(SRC_DIR)/*.c)) all: espeakup -changelog: - git log ${CHANGELOG_LIMIT} --format=full > ChangeLog - install: espeakup ${INSTALL} -d ${DESTDIR}${BINDIR} ${INSTALL} -m ${BINMODE} $< ${DESTDIR}${BINDIR} From 2d8d2c55c090b5695487537a7a56e0637be25da6 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Tue, 15 Jun 2021 00:20:04 -0500 Subject: [PATCH 148/181] rename autostart directory to services --- {autostart => services}/systemd/espeakup.conf | 0 {autostart => services}/systemd/espeakup.service | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename {autostart => services}/systemd/espeakup.conf (100%) rename {autostart => services}/systemd/espeakup.service (100%) diff --git a/autostart/systemd/espeakup.conf b/services/systemd/espeakup.conf similarity index 100% rename from autostart/systemd/espeakup.conf rename to services/systemd/espeakup.conf diff --git a/autostart/systemd/espeakup.service b/services/systemd/espeakup.service similarity index 100% rename from autostart/systemd/espeakup.service rename to services/systemd/espeakup.service From 30ef2145e7c670b07da03e10ef9e62790721fd6f Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Tue, 15 Jun 2021 00:43:46 -0500 Subject: [PATCH 149/181] remove TODO This file is no longer needed since we have an official bug tracker. --- doc/TODO | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 doc/TODO diff --git a/doc/TODO b/doc/TODO deleted file mode 100644 index ec1d210..0000000 --- a/doc/TODO +++ /dev/null @@ -1,11 +0,0 @@ -This file contains a list of improvements that need to be made to -espeakup. - -Voice and language support should be added at some point. -This will consist of the following: -- add a function which will allow switching voices. (completed on 9/27) -- add a function/command which will allow speakup to find out which - voices espeak supports. -- define and add the command to speakup which will allow it to switch - voices. - From 0c09fe5449c8c9aaac454f964b808b9b881202d2 Mon Sep 17 00:00:00 2001 From: Alexander Epaneshnikov Date: Sat, 19 Jun 2021 05:53:04 +0300 Subject: [PATCH 150/181] switch to meson (#30) switch to a meson-based build system --- .gitignore | 4 +- Makefile | 37 ------------------- README.md | 12 ++++-- doc/meson.build | 1 + meson.build | 21 +++++++++++ meson_options.txt | 2 + services/meson.build | 4 ++ services/systemd/espeakup.conf | 1 - .../{espeakup.service => espeakup.service.in} | 6 +-- services/systemd/meson.build | 17 +++++++++ src/cli.c | 1 + src/espeakup.h | 1 - src/meson.build | 12 ++++++ src/version.h.in | 25 +++++++++++++ 14 files changed, 96 insertions(+), 48 deletions(-) delete mode 100644 Makefile create mode 100644 doc/meson.build create mode 100644 meson.build create mode 100644 meson_options.txt create mode 100644 services/meson.build delete mode 100644 services/systemd/espeakup.conf rename services/systemd/{espeakup.service => espeakup.service.in} (67%) create mode 100644 services/systemd/meson.build create mode 100644 src/meson.build create mode 100644 src/version.h.in diff --git a/.gitignore b/.gitignore index d1c8b4b..1b2211d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1 @@ -espeakup -src/*.d -src/*.o +build* diff --git a/Makefile b/Makefile deleted file mode 100644 index d8d47a5..0000000 --- a/Makefile +++ /dev/null @@ -1,37 +0,0 @@ -PREFIX = /usr/local -BINDIR = ${PREFIX}/bin -MANDIR = ${PREFIX}/share/man -SRC_DIR = src -DEPFLAGS = -MMD -WARNFLAGS = -Wall -Wpedantic \ - -Wextra - -CFLAGS += ${DEPFLAGS} ${WARNFLAGS} - -LDLIBS = -lespeak-ng -lpthread -lasound -lm - -INSTALL = install -BINMODE = 0755 -MANMODE = 0644 - -SRC = $(wildcard $(SRC_DIR)/*.c) -OBJECTS := $(patsubst %.c,%.o,$(wildcard $(SRC_DIR)/*.c)) - -all: espeakup - -install: espeakup - ${INSTALL} -d ${DESTDIR}${BINDIR} - ${INSTALL} -m ${BINMODE} $< ${DESTDIR}${BINDIR} - ${INSTALL} -d ${DESTDIR}${MANDIR}/man8 - ${INSTALL} -m ${MANMODE} doc/espeakup.8 ${DESTDIR}${MANDIR}/man8 - -espeakup: ${OBJECTS} - cc $(LDLIBS) -o ./espeakup $(OBJECTS) - -clean: - ${RM} $(SRC_DIR)/*.d $(SRC_DIR)/*.o - -distclean: clean - ${RM} espeakup - --include ${SRCS:.c=.d} diff --git a/README.md b/README.md index a69a5df..d05278f 100644 --- a/README.md +++ b/README.md @@ -18,9 +18,15 @@ is beyond the scope of this document. The preferred way to install espeakup is using your distribution's packaging system, but if your distribution does not have a package for -espeakup yet, espeakup just uses a Makefile, so you should be able to -change to the source directory, then type make, then as root, make -install. +espeakup yet, espeakup just uses meson, so you should be able to +change to the source directory, then type: + +```bash +meson . ./build +cd ./build +ninja +sudo ninja install +``` ## Starting Up diff --git a/doc/meson.build b/doc/meson.build new file mode 100644 index 0000000..7726ab6 --- /dev/null +++ b/doc/meson.build @@ -0,0 +1 @@ +install_man('espeakup.8') diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..261df7e --- /dev/null +++ b/meson.build @@ -0,0 +1,21 @@ +project('espeakup', 'c', + default_options : ['buildtype=debugoptimized', 'c_std=gnu11', 'warning_level=3'], + license : 'GPL-3.0-or-later', + version : '0.81', + meson_version : '>=0.47.0') + +cc = meson.get_compiler('c') +thread_dep = dependency('threads') +espeak_dep = dependency('espeak-ng') +alsa_dep = dependency('alsa') +math_dep = cc.find_library('m', required : false) + +subdir('doc') +subdir('services') +subdir('src') + +executable('espeakup', + espeakup_version, + espeakup_sources, + dependencies : [thread_dep, espeak_dep, alsa_dep, math_dep], + install : true) diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 0000000..45e3a33 --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,2 @@ +option('systemd', type : 'feature', value : 'auto', + description :'enable systemd support') diff --git a/services/meson.build b/services/meson.build new file mode 100644 index 0000000..0be40f1 --- /dev/null +++ b/services/meson.build @@ -0,0 +1,4 @@ +systemd = dependency('systemd', required: get_option('systemd')) +if systemd.found() + subdir('systemd') +endif diff --git a/services/systemd/espeakup.conf b/services/systemd/espeakup.conf deleted file mode 100644 index 56aebc1..0000000 --- a/services/systemd/espeakup.conf +++ /dev/null @@ -1 +0,0 @@ -default_voice= diff --git a/services/systemd/espeakup.service b/services/systemd/espeakup.service.in similarity index 67% rename from services/systemd/espeakup.service rename to services/systemd/espeakup.service.in index b840489..ec5f4da 100644 --- a/services/systemd/espeakup.service +++ b/services/systemd/espeakup.service.in @@ -6,10 +6,10 @@ After=systemd-udev-settle.service sound.target [Service] Type=forking -EnvironmentFile=/etc/conf.d/espeakup PIDFile=/run/espeakup.pid -ExecStartPre=+/sbin/modprobe speakup_soft -ExecStart=/usr/bin/espeakup --default-voice=${default_voice} +Environment="default_voice=" +ExecStartPre=+modprobe speakup_soft +ExecStart=@bindir@/espeakup --default-voice=${default_voice} ExecReload=kill -HUP $MAINPID Restart=always diff --git a/services/systemd/meson.build b/services/systemd/meson.build new file mode 100644 index 0000000..4a693ed --- /dev/null +++ b/services/systemd/meson.build @@ -0,0 +1,17 @@ +unitdir = systemd.get_pkgconfig_variable('systemdsystemunitdir') +prefixdir = get_option('prefix') +bindir = join_paths(prefixdir, get_option('bindir')) + +unit_conf = configuration_data() + +unit_conf.set('bindir', bindir) + +service_file = configure_file( + input : 'espeakup.service.in', + output : 'espeakup.service', + configuration : unit_conf +) + +install_data(service_file, + install_dir : unitdir +) diff --git a/src/cli.c b/src/cli.c index b8a6543..280b507 100644 --- a/src/cli.c +++ b/src/cli.c @@ -23,6 +23,7 @@ #include #include "espeakup.h" +#include "version.h" /* pid path */ extern char *pidPath; diff --git a/src/espeakup.h b/src/espeakup.h index 9518c6d..d6daaf0 100644 --- a/src/espeakup.h +++ b/src/espeakup.h @@ -28,7 +28,6 @@ #include "queue.h" -#define PACKAGE_VERSION "0.81" #define PACKAGE_BUGREPORT "https://github.com/linux-speakup/espeakup/issues" enum espeakup_mode_t { diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 0000000..f1c4610 --- /dev/null +++ b/src/meson.build @@ -0,0 +1,12 @@ +espeakup_version = vcs_tag(input : 'version.h.in', output : 'version.h') + + +espeakup_sources = files([ + 'cli.c', + 'espeak.c', + 'espeakup.c', + 'queue.c', + 'signal.c', + 'softsynth.c', + 'stringhandling.c' +]) diff --git a/src/version.h.in b/src/version.h.in new file mode 100644 index 0000000..8c0038e --- /dev/null +++ b/src/version.h.in @@ -0,0 +1,25 @@ +/* + * espeakup - interface which allows speakup to use espeak + * + * Copyright (C) 2008 William Hubbs + * + * This program 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. + * + * This program 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 this program. If not, see . + */ + +#ifndef __VERSION_H +#define __VERSION_H + +#define PACKAGE_VERSION "@VCS_TAG@" + +#endif From ca1d6b42e2b71e2b5d6154754d7b7c34b48fa27b Mon Sep 17 00:00:00 2001 From: Alexander Epaneshnikov Date: Mon, 14 Jun 2021 02:40:09 +0300 Subject: [PATCH 151/181] generate man page from markdown Use ronn to convert markdown to a man page This simplifies maintaining the documentation. This fixes #31. --- doc/espeakup.8 | 78 --------------------------------------------- doc/espeakup.8.ronn | 77 ++++++++++++++++++++++++++++++++++++++++++++ doc/meson.build | 9 +++++- meson_options.txt | 2 ++ 4 files changed, 87 insertions(+), 79 deletions(-) delete mode 100644 doc/espeakup.8 create mode 100644 doc/espeakup.8.ronn diff --git a/doc/espeakup.8 b/doc/espeakup.8 deleted file mode 100644 index 092c776..0000000 --- a/doc/espeakup.8 +++ /dev/null @@ -1,78 +0,0 @@ -.\" Hey, Emacs! This is an -*- nroff -*- source file. -.\" Espeakup is Copyright 2008 by William Hubbs. -.\" This is free software; see the GNU General Public Licence version 3 -.\" or later for copying conditions. There is NO warranty. -.TH ESPEAKUP 8 "5 Nov 2008" "0.60" -.nh -.SH NAME -espeakup \(em connect Speakup to the ESpeak TTS engine -.SH SYNOPSIS -.B espeakup -[ -.B \-\^\-pid-path=path -] -[ -.B \-\^\-default-voice=voicename -] -[ -.B \-\^\-debug -] -[ -.B \-\^\-help -] -[ -.B \-\^\-version -] -.SH OPTIONS -.TP -.B \-P path, \-\^\-pid-path=path -Set the full path for the pid file espeakup uses when in daemon mode. -.TP -.B \-V voicename, \-\^\-default-voice=voicename -Set the espeak voice to be used by default. -.TP -.B \-d, \-\^\-debug -run in the foreground, rather than becoming a daemon process. -.TP -.B \-h, \-\^\-help -display a brief help message and exit. -.TP -.B \-v, \-\^\-version -output version information and exit. -.SH DESCRIPTION -Espeakup bridges the gap between two tools: the Speakup screen review -system and the ESppeak text-to-speech engine. Each of these tools -performs a well-defined task. Speakup is a kernel-based screen reader -for the Linux console. It extracts and processes the text that is -displayed on the foreground virtual console. It supports several -hardware based speech synthesizers directly. However, since it is in -kernel space, it cannot support a software speech synthesizer directly -since these are in user space. -ESpeak is a popular software speech synthesizer. It is small, light -weight, very responsive, and supports multiple languages. -Espeakup is a connector which will read text sent to it by speakup and -forward it to ESpeak. This allows Speakup to use ESpeak as its speech -synthesizer. -.PP -Espeakup is a daemon. Typically, it is started at boot time, and it terminates -when the system is halted or rebooted. It should be started by the -system's init scripts. This process varies among Linux distributions, -but the details are usually managed by the person who packaged Espeakup for -your distribution. -From the perspective of an average user, Espeakup's operation is invisible. -.SH BUGS -.PP -Espeakup is still classified as alpha software. Bugs are periodically found -and fixed. If you find a bug, please do report it to the author. You -might also consider mentioning it on the mailing list for the Speakup -screenreader. Visit http://speech.braille.uwo.ca/mailman/listinfo/speakup -to learn more about the mailing list. -.SH SEE ALSO -.PP -For more information about Speakup, visit its homepage: http://linux-speakup.org. -ESpeak's home page is http://espeak.sourceforge.net. -.SH AUTHOR -.PP -William Hubbs is the author and maintainer of Espeakup. He may be reached -via the email address . This manual page was written -by Chris Brannon, and his email address is . diff --git a/doc/espeakup.8.ronn b/doc/espeakup.8.ronn new file mode 100644 index 0000000..40b9d9c --- /dev/null +++ b/doc/espeakup.8.ronn @@ -0,0 +1,77 @@ + + +# espeakup(8) --- connect Speakup to the espeak-ng TTS engine + +## SYNOPSIS + +`espeakup` [`--pid-path=`] [`--alsa-volume`] +[`--default-voice=`[]] [`--debug`] [`--help`] [`--version`] + +## OPTIONS + + * `-P` , `--pid-path=`: + Set the full path for the pid file espeakup uses when in daemon mode. + + * `--alsa-volume`: + Drive the ALSA volume. useful for live environments where volume + adjustments maybe impossible. + + * `-V` , `--default-voice=`: + Set the espeak-ng voice to be used by default. + + * `-d`, `--debug`: + run in the foreground, rather than becoming a daemon process. + + * `-h`, `--help`: + display a brief help message and exit. + + * `-v`, `--version`: + output version information and exit. + +## DESCRIPTION + +espeakup bridges the gap between two tools: the Speakup screen review system and +the espeak-ng text-to-speech engine. Each of these tools performs a +well-defined task. + +Speakup is a kernel-based screen reader for the Linux console. It extracts and +processes the text that is displayed on the foreground virtual console. It +supports several hardware based speech synthesizers directly. However, since it +is in kernel space, it cannot support a software speech synthesizer directly +since these are in user space. + +espeak-ng is a popular software speech synthesizer. It is small, light weight, +very responsive, and supports multiple languages. espeakup is a connector which +will read text sent to it by speakup and forward it to espeak-ng. This allows +Speakup to use espeak-ng as its speech synthesizer. + +espeakup is a daemon. Typically, it is started at boot time, and it terminates +when the system is halted or rebooted. It should be started by the system's init +scripts. This process varies among Linux distributions, but the details are +usually managed by the person who packaged espeakup for your distribution. From +the perspective of an average user, espeakup's operation is invisible. + +## BUGS + +If you find a bug, please create a +[github issue](https://github.com/linux-speakup/espeakup/issues) +You might also consider mentioning it on the mailing list for the Speakup +screenreader. Visit +[list page](https://linux-speakup.org/cgi-bin/mailman/listinfo/speakup) +to learn more about the mailing list. + +## SEE ALSO + +For more information about Speakup, visit its +[homepage](https://linux-speakup.org). + +espeak-ng can be found at [github](https://github.com/espeak-ng/espeak-ng) + +## AUTHOR + +William Hubbs is the author of espeakup. + +This manual page was written by Chris Brannon . + +current authors and maintainers can be found at +[github](https://github.com/linux-speakup/espeakup/graphs/contributors) diff --git a/doc/meson.build b/doc/meson.build index 7726ab6..9645649 100644 --- a/doc/meson.build +++ b/doc/meson.build @@ -1 +1,8 @@ -install_man('espeakup.8') +ronn = find_program('ronn', required: get_option('man')) + +if ronn.found() + custom_target('man', input:files('espeakup.8.ronn'), + output:'espeakup.8', + command:[ronn, '--output-dir', '@OUTDIR@', '--roff', '@INPUT@'], + install: true, install_dir: join_paths(get_option('mandir'),'man8')) +endif diff --git a/meson_options.txt b/meson_options.txt index 45e3a33..c7e35d9 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,2 +1,4 @@ option('systemd', type : 'feature', value : 'auto', description :'enable systemd support') +option('man', type : 'feature', value : 'auto', + description : 'build manpage with ronn') From dd2dcb68bf9b33bc2c5adf0b2af0fa7df9494711 Mon Sep 17 00:00:00 2001 From: Alexander Epaneshnikov Date: Tue, 15 Jun 2021 23:46:30 +0300 Subject: [PATCH 152/181] use clang-format for code styling --- .clang-format | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..16c7f08 --- /dev/null +++ b/.clang-format @@ -0,0 +1,41 @@ +--- +Language: Cpp +BasedOnStyle: LLVM + +AlignAfterOpenBracket: Align +AlignEscapedNewlines: Left +AlignOperands: AlignAfterOperator +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortEnumsOnASingleLine: false +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +BinPackArguments: true +BinPackParameters: true +BreakBeforeBraces: Linux +ColumnLimit: 80 +IndentPPDirectives: BeforeHash +IndentWidth: 4 +InsertTrailingCommas: None +KeepEmptyLinesAtTheStartOfBlocks: false +PointerAlignment: Right +ReflowComments: true +SortIncludes: true +SpaceAfterCStyleCast: true +SpaceAfterLogicalNot: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceAroundPointerQualifiers: Before +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 5 +TabWidth: 4 +UseTab: AlignWithSpaces +... From c528913ad9719279fc262a1ebfa98f7ccbd8e46a Mon Sep 17 00:00:00 2001 From: Alexander Epaneshnikov Date: Thu, 17 Jun 2021 12:57:40 +0300 Subject: [PATCH 153/181] format code --- src/cli.c | 3 +- src/espeak.c | 90 +++++++++++++++++++------------------------- src/espeakup.c | 20 +++++----- src/espeakup.h | 11 ++++-- src/queue.h | 2 +- src/signal.c | 2 +- src/softsynth.c | 24 ++++++------ src/stringhandling.c | 6 +-- 8 files changed, 72 insertions(+), 86 deletions(-) diff --git a/src/cli.c b/src/cli.c index 280b507..cc1a9d9 100644 --- a/src/cli.c +++ b/src/cli.c @@ -44,8 +44,7 @@ const struct option longOptions[] = { {"debug", no_argument, NULL, 'd'}, {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'v'}, - {0, 0, 0, 0} -}; + {0, 0, 0, 0}}; static void show_help() { diff --git a/src/espeak.c b/src/espeak.c index acee6e1..6f64901 100644 --- a/src/espeak.c +++ b/src/espeak.c @@ -18,12 +18,12 @@ */ #define _GNU_SOURCE +#include #include +#include #include #include #include -#include -#include #include "espeakup.h" @@ -47,10 +47,10 @@ const int volumeMultiplier = 22; volatile int stop_requested = 0; int paused_espeak = 1; -static int callback(short *wav, int numsamples, espeak_EVENT * events) +static int callback(short *wav, int numsamples, espeak_EVENT *events) { int i; - for (i = 0; events[i].type != espeakEVENT_LIST_TERMINATED; i++) { + for (i = 0; events[i].type != espeakEVENT_LIST_TERMINATED; i++) { if (events[i].type == espeakEVENT_MARK) { int mark = atoi(events[i].id.name); if ((mark < 0) || (mark > 255)) @@ -62,7 +62,7 @@ static int callback(short *wav, int numsamples, espeak_EVENT * events) } static espeak_ERROR set_frequency(struct synth_t *s, int freq, - enum adjust_t adj) + enum adjust_t adj) { espeak_ERROR rc; @@ -76,8 +76,7 @@ static espeak_ERROR set_frequency(struct synth_t *s, int freq, return rc; } -static espeak_ERROR set_pitch(struct synth_t *s, int pitch, - enum adjust_t adj) +static espeak_ERROR set_pitch(struct synth_t *s, int pitch, enum adjust_t adj) { espeak_ERROR rc; @@ -91,8 +90,7 @@ static espeak_ERROR set_pitch(struct synth_t *s, int pitch, return rc; } -static espeak_ERROR set_range(struct synth_t *s, int range, - enum adjust_t adj) +static espeak_ERROR set_range(struct synth_t *s, int range, enum adjust_t adj) { espeak_ERROR rc; @@ -107,7 +105,7 @@ static espeak_ERROR set_range(struct synth_t *s, int range, } static espeak_ERROR set_punctuation(struct synth_t *s, int punct, - enum adjust_t adj) + enum adjust_t adj) { espeak_ERROR rc; @@ -121,8 +119,7 @@ static espeak_ERROR set_punctuation(struct synth_t *s, int punct, return rc; } -static espeak_ERROR set_rate(struct synth_t *s, int rate, - enum adjust_t adj) +static espeak_ERROR set_rate(struct synth_t *s, int rate, enum adjust_t adj) { espeak_ERROR rc; @@ -130,8 +127,7 @@ static espeak_ERROR set_rate(struct synth_t *s, int rate, rate = -rate; if (adj != ADJ_SET) rate += s->rate; - rc = espeak_SetParameter(espeakRATE, - rate * rateMultiplier + rateOffset, 0); + rc = espeak_SetParameter(espeakRATE, rate * rateMultiplier + rateOffset, 0); if (rc == EE_OK) s->rate = rate; return rc; @@ -143,8 +139,7 @@ static espeak_ERROR set_voice(struct synth_t *s, char *voice) espeak_VOICE voice_select; rc = espeak_SetVoiceByName(voice); - if (rc != EE_OK) - { + if (rc != EE_OK) { memset(&voice_select, 0, sizeof(voice_select)); voice_select.languages = voice; rc = espeak_SetVoiceByProperties(&voice_select); @@ -161,27 +156,23 @@ static void set_alsa_volume(int vol) int err; err = snd_mixer_open(&m, 0); - if (err < 0) - { + if (err < 0) { fprintf(stderr, "ALSA mixer open error: %s\n", snd_strerror(err)); return; } err = snd_mixer_attach(m, "default"); - if (err < 0) - { + if (err < 0) { fprintf(stderr, "ALSA mixer attach error: %s\n", snd_strerror(err)); return; } err = snd_mixer_selem_register(m, NULL, NULL); - if (err < 0) - { + if (err < 0) { fprintf(stderr, "ALSA mixer load error: %s\n", snd_strerror(err)); return; } err = snd_mixer_load(m); - if (err < 0) - { + if (err < 0) { fprintf(stderr, "ALSA mixer load error: %s\n", snd_strerror(err)); return; } @@ -192,10 +183,9 @@ static void set_alsa_volume(int vol) * volume (80%), and make higher values increase ALSA volume, up to * 100%. */ - int volume = (vol+1) * 50 / 10 + 50; + int volume = (vol + 1) * 50 / 10 + 50; - for (e = snd_mixer_first_elem(m); e; e = snd_mixer_elem_next(e)) - { + for (e = snd_mixer_first_elem(m); e; e = snd_mixer_elem_next(e)) { if (snd_mixer_elem_get_type(e) != SND_MIXER_ELEM_SIMPLE) continue; if (snd_mixer_selem_is_enumerated(e)) @@ -212,13 +202,12 @@ static void set_alsa_volume(int vol) if (err == 0 && min < max) { if (max - min < 2400) { /* 24dB amplitude is too small for using a logscale */ - set = min + volume * (max-min) / 100; + set = min + volume * (max - min) / 100; } else { /* Use a logscale */ double volf = volume / 100.; - if (min != SND_CTL_TLV_DB_GAIN_MUTE) - { - double minf = pow(10, (min-max) / 6000.); + if (min != SND_CTL_TLV_DB_GAIN_MUTE) { + double minf = pow(10, (min - max) / 6000.); volf = volf * (1 - minf) + minf; } set = 6000. * log10(volf) + max; @@ -227,15 +216,14 @@ static void set_alsa_volume(int vol) } else { /* No dB setting, try a linear scale */ snd_mixer_selem_get_playback_volume_range(e, &min, &max); - set = min + volume * (max-min) / 100; + set = min + volume * (max - min) / 100; snd_mixer_selem_set_playback_volume_all(e, set); } } } } -static espeak_ERROR set_volume(struct synth_t *s, int vol, - enum adjust_t adj) +static espeak_ERROR set_volume(struct synth_t *s, int vol, enum adjust_t adj) { espeak_ERROR rc; @@ -243,10 +231,8 @@ static espeak_ERROR set_volume(struct synth_t *s, int vol, vol = -vol; if (adj != ADJ_SET) vol += s->volume; - rc = espeak_SetParameter(espeakVOLUME, (vol + 1) * volumeMultiplier, - 0); - if (rc == EE_OK) - { + rc = espeak_SetParameter(espeakVOLUME, (vol + 1) * volumeMultiplier, 0); + if (rc == EE_OK) { s->volume = vol; if (alsaVolume) set_alsa_volume(vol); @@ -276,24 +262,24 @@ static espeak_ERROR speak_text(struct synth_t *s) int n; if (s->buf[0] == ' ') n = asprintf(&buf, - " "); + " "); else n = asprintf(&buf, - "%c", - s->buf[0]); + "%c", + s->buf[0]); if (n == -1) { /* D'oh. Not much to do on allocation failure. * Perhaps espeak will happen to say the character */ - rc = espeak_Synth(s->buf, s->len + 1, 0, POS_CHARACTER, - 0, synth_mode, NULL, NULL); + rc = espeak_Synth(s->buf, s->len + 1, 0, POS_CHARACTER, 0, + synth_mode, NULL, NULL); } else { - rc = espeak_Synth(buf, n + 1, 0, POS_CHARACTER, 0, - espeakSSML, NULL, NULL); + rc = espeak_Synth(buf, n + 1, 0, POS_CHARACTER, 0, espeakSSML, NULL, + NULL); free(buf); } } else - rc = espeak_Synth(s->buf, s->len + 1, 0, POS_CHARACTER, 0, - synth_mode, NULL, NULL); + rc = espeak_Synth(s->buf, s->len + 1, 0, POS_CHARACTER, 0, synth_mode, + NULL, NULL); return rc; } @@ -361,9 +347,10 @@ static void queue_process_entry(struct synth_t *s) error = set_frequency(s, current->value, current->adjust); break; case CMD_SET_MARK: - snprintf(markbuff, sizeof(markbuff), "", current->value); - error = espeak_Synth(markbuff, strlen(markbuff)+1, 0, POS_CHARACTER, - 0, espeakSSML, NULL, NULL); + snprintf(markbuff, sizeof(markbuff), "", + current->value); + error = espeak_Synth(markbuff, strlen(markbuff) + 1, 0, POS_CHARACTER, + 0, espeakSSML, NULL, NULL); break; case CMD_SET_PITCH: error = set_pitch(s, current->value, current->adjust); @@ -452,14 +439,13 @@ int initialize_espeak(struct synth_t *s) * The main thread can add items to the queue in exactly two situations: * 1. We are waiting on runner_awake, or * 2. We are processing an entry that has just been removed from the queue. -*/ + */ void *espeak_thread(void *arg) { struct synth_t *s = (struct synth_t *) arg; pthread_mutex_lock(&queue_guard); while (should_run) { - while (should_run && !queue_peek(synth_queue) && !stop_requested) pthread_cond_wait(&runner_awake, &queue_guard); diff --git a/src/espeakup.c b/src/espeakup.c index eda3e9c..3328d74 100644 --- a/src/espeakup.c +++ b/src/espeakup.c @@ -18,13 +18,13 @@ */ #include +#include #include #include #include #include -#include -#include #include +#include #include "espeakup.h" @@ -78,7 +78,7 @@ int espeakup_start_daemon(void) /* Child */ if (chdir("/") < 0) { c = 1; - (void)write(fds[1], &c, 1); + (void) write(fds[1], &c, 1); exit(1); } return fds[1]; @@ -99,14 +99,12 @@ int espeakup_is_running(void) } if (flock(pidFile, LOCK_EX) < 0) { - printf("Can not lock the pid file %s: %s\n", pidPath, - strerror(errno)); + printf("Can not lock the pid file %s: %s\n", pidPath, strerror(errno)); goto error; } n = read(pidFile, s, sizeof(s) - 1); if (n < 0) { - printf("Can not read the pid file %s: %s\n", pidPath, - strerror(errno)); + printf("Can not read the pid file %s: %s\n", pidPath, strerror(errno)); goto error; } s[n] = 0; @@ -197,13 +195,13 @@ int main(int argc, char **argv) sigaddset(&sigset, SIGTERM); sigprocmask(SIG_BLOCK, &sigset, NULL); -/* Initialize espeak */ + /* Initialize espeak */ if (initialize_espeak(&s) < 0) { ret = 2; goto out; } -/* open the softsynth */ + /* open the softsynth */ if (open_softsynth() < 0) { ret = 2; goto out; @@ -224,7 +222,7 @@ int main(int argc, char **argv) } if (!debug && espeakup_mode == ESPEAKUP_MODE_SPEAKUP) - (void)write(fd, &ret, 1); + (void) write(fd, &ret, 1); /* wait for the threads to shut down. */ pthread_join(signal_thread_id, NULL); @@ -240,7 +238,7 @@ out: if (ret != 1) unlink(pidPath); if (ret != 0) - (void)write(fd, &ret, 1); + (void) write(fd, &ret, 1); /* If ret was 0, the status byte was written before joining * the threads. */ } diff --git a/src/espeakup.h b/src/espeakup.h index d6daaf0..6629371 100644 --- a/src/espeakup.h +++ b/src/espeakup.h @@ -21,8 +21,8 @@ #define __ESPEAKUP_H /* This was added for gcc 4.3 */ -#include #include +#include #include @@ -30,12 +30,14 @@ #define PACKAGE_BUGREPORT "https://github.com/linux-speakup/espeakup/issues" -enum espeakup_mode_t { +enum espeakup_mode_t +{ ESPEAKUP_MODE_SPEAKUP, ESPEAKUP_MODE_ACSINT }; -enum command_t { +enum command_t +{ CMD_SET_FREQUENCY, CMD_SET_MARK, CMD_SET_PITCH, @@ -50,7 +52,8 @@ enum command_t { CMD_UNKNOWN, }; -enum adjust_t { +enum adjust_t +{ ADJ_DEC, ADJ_SET, ADJ_INC, diff --git a/src/queue.h b/src/queue.h index 249f3ba..a6a2a76 100644 --- a/src/queue.h +++ b/src/queue.h @@ -20,7 +20,7 @@ #ifndef __QUEUE_H #define __QUEUE_H -struct queue_t; /* An opaque type. */ +struct queue_t; /* An opaque type. */ extern struct queue_t *new_queue(void); extern int queue_add(struct queue_t *q, void *entry); diff --git a/src/signal.c b/src/signal.c index 3096b30..f6a6a39 100644 --- a/src/signal.c +++ b/src/signal.c @@ -40,7 +40,7 @@ void *signal_thread(void *arg) sigset_t sigset; int sig; - memset(&temp, 0, sizeof (struct sigaction)); + memset(&temp, 0, sizeof(struct sigaction)); /* install dummy handlers for the signals we want to process */ temp.sa_handler = dummy_handler; sigemptyset(&temp.sa_mask); diff --git a/src/softsynth.c b/src/softsynth.c index 9e1d66f..085582d 100644 --- a/src/softsynth.c +++ b/src/softsynth.c @@ -17,14 +17,14 @@ * along with this program. If not, see . */ +#include #include #include #include #include -#include -#include #include -#include +#include +#include #include "espeakup.h" #include "stringhandling.h" @@ -155,8 +155,7 @@ static int process_command(struct synth_t *s, char *buf, int start) } if (cmd != CMD_FLUSH && cmd != CMD_UNKNOWN) { - if (espeakup_mode == ESPEAKUP_MODE_ACSINT - && textAccumulator_l != 0) { + if (espeakup_mode == ESPEAKUP_MODE_ACSINT && textAccumulator_l != 0) { queue_add_text(textAccumulator, textAccumulator_l); free(textAccumulator); textAccumulator = initString(&textAccumulator_l); @@ -177,7 +176,8 @@ static void process_buffer(struct synth_t *s, char *buf, ssize_t length) start = 0; end = 0; while (start < length) { - while ((buf[end] < 0 || buf[end] >= ' ' || buf[end] == '\n') && end < length) + while ((buf[end] < 0 || buf[end] >= ' ' || buf[end] == '\n') && + end < length) end++; if (end != start) { txtLen = end - start; @@ -192,8 +192,7 @@ static void process_buffer(struct synth_t *s, char *buf, ssize_t length) } } -static void process_buffer_acsint(struct synth_t *s, char *buf, - ssize_t length) +static void process_buffer_acsint(struct synth_t *s, char *buf, ssize_t length) { int start = 0; int i; @@ -207,8 +206,8 @@ static void process_buffer_acsint(struct synth_t *s, char *buf, break; } if (i > start) - stringAndBytes(&textAccumulator, &textAccumulator_l, - buf + start, i - start); + stringAndBytes(&textAccumulator, &textAccumulator_l, buf + start, + i - start); if (flushIt) { if (textAccumulator != EMPTYSTRING) { queue_add_text(textAccumulator, textAccumulator_l); @@ -228,9 +227,10 @@ static void request_espeak_stop(void) { pthread_mutex_lock(&queue_guard); stop_requested = 1; - pthread_cond_signal(&runner_awake); /* Wake runner, if necessary. */ + pthread_cond_signal(&runner_awake); /* Wake runner, if necessary. */ while (should_run && stop_requested) - pthread_cond_wait(&stop_acknowledged, &queue_guard); /* wait for acknowledgement. */ + pthread_cond_wait(&stop_acknowledged, + &queue_guard); /* wait for acknowledgement. */ pthread_mutex_unlock(&queue_guard); } diff --git a/src/stringhandling.c b/src/stringhandling.c index 8c18a39..1adf7ae 100644 --- a/src/stringhandling.c +++ b/src/stringhandling.c @@ -75,9 +75,9 @@ void stringAndString(char **s, int *l, const char *t) oldlen = *l; newlen = oldlen + strlen(t); *l = newlen; - ++newlen; /* room for the 0 */ + ++newlen; /* room for the 0 */ x = oldlen ^ newlen; - if (x > oldlen) { /* must realloc */ + if (x > oldlen) { /* must realloc */ newlen |= (newlen >> 1); newlen |= (newlen >> 2); newlen |= (newlen >> 4); @@ -98,7 +98,7 @@ void stringAndBytes(char **s, int *l, const char *t, int cnt) *l = newlen; ++newlen; x = oldlen ^ newlen; - if (x > oldlen) { /* must realloc */ + if (x > oldlen) { /* must realloc */ newlen |= (newlen >> 1); newlen |= (newlen >> 2); newlen |= (newlen >> 4); From e13ceb3cce079ade07c2659e71d4409ca0c098a5 Mon Sep 17 00:00:00 2001 From: Alexander Epaneshnikov Date: Tue, 15 Jun 2021 23:55:43 +0300 Subject: [PATCH 154/181] edit by hand more formatting improvements --- src/cli.c | 2 +- src/espeak.c | 2 +- src/espeakup.c | 33 ++++++++++++++++----------------- src/espeakup.h | 4 ++-- src/queue.c | 2 +- src/queue.h | 4 ++-- src/signal.c | 9 +++++---- src/softsynth.c | 20 ++++++++++---------- src/stringhandling.c | 8 ++++---- src/stringhandling.h | 2 +- src/version.h.in | 2 +- 11 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/cli.c b/src/cli.c index cc1a9d9..a4cf48f 100644 --- a/src/cli.c +++ b/src/cli.c @@ -1,5 +1,5 @@ /* - * espeakup - interface which allows speakup to use espeak + * espeakup - interface which allows speakup to use espeak-ng * * Copyright (C) 2008 William Hubbs * diff --git a/src/espeak.c b/src/espeak.c index 6f64901..135c6b5 100644 --- a/src/espeak.c +++ b/src/espeak.c @@ -1,5 +1,5 @@ /* - * espeakup - interface which allows speakup to use espeak + * espeakup - interface which allows speakup to use espeak-ng * * Copyright (C) 2008 William Hubbs * diff --git a/src/espeakup.c b/src/espeakup.c index 3328d74..86b3a88 100644 --- a/src/espeakup.c +++ b/src/espeakup.c @@ -1,5 +1,5 @@ /* - * espeakup - interface which allows speakup to use espeak + * espeakup - interface which allows speakup to use espeak-ng * * Copyright (C) 2008 William Hubbs * @@ -28,7 +28,7 @@ #include "espeakup.h" -/* path to our pid file */ +// path to our pid file char *pidPath = "/var/run/espeakup.pid"; int debug = 0; @@ -60,7 +60,7 @@ int espeakup_start_daemon(void) exit(1); } if (pid) { - /* Parent, just wait for daemon */ + // Parent, just wait for daemon if (read(fds[0], &c, 1) < 0) { printf("Espeakup is already running!\n"); exit(1); @@ -68,14 +68,14 @@ int espeakup_start_daemon(void) exit(c); } - /* Child, create new session */ + // Child, create new session setsid(); pid = fork(); if (pid) - /* Intermediate child, just exit */ + // Intermediate child, just exit exit(0); - /* Child */ + // Child if (chdir("/") < 0) { c = 1; (void) write(fds[1], &c, 1); @@ -110,7 +110,7 @@ int espeakup_is_running(void) s[n] = 0; n = sscanf(s, "%d", &pid); if (n == 1 && (!kill(pid, 0) || errno != ESRCH)) { - /* Already running */ + // Already running close(pidFile); return 1; } @@ -153,13 +153,13 @@ int main(int argc, char **argv) return 2; } - /* set up the pipe used to wake the espeak thread */ + // set up the pipe used to wake the espeak thread if (pipe(self_pipe_fds) < 0) { perror("Unable to create pipe"); return 5; } - /* process command line options */ + // process command line options process_cli(argc, argv); if (!debug && espeakup_mode == ESPEAKUP_MODE_SPEAKUP) { @@ -179,7 +179,7 @@ int main(int argc, char **argv) close(devnull); } - /* create the signal processing thread here. */ + // create the signal processing thread here. err = pthread_create(&signal_thread_id, NULL, signal_thread, NULL); if (err != 0) { ret = 4; @@ -195,26 +195,26 @@ int main(int argc, char **argv) sigaddset(&sigset, SIGTERM); sigprocmask(SIG_BLOCK, &sigset, NULL); - /* Initialize espeak */ + // Initialize espeak if (initialize_espeak(&s) < 0) { ret = 2; goto out; } - /* open the softsynth */ + // open the softsynth if (open_softsynth() < 0) { ret = 2; goto out; } - /* Spawn our softsynth thread. */ + // Spawn our softsynth thread. err = pthread_create(&softsynth_thread_id, NULL, softsynth_thread, &s); if (err != 0) { ret = 4; goto out; } - /* Spawn our espeak-interacting thread. */ + // Spawn our espeak-interacting thread. err = pthread_create(&espeak_thread_id, NULL, espeak_thread, &s); if (err != 0) { ret = 4; @@ -224,7 +224,7 @@ int main(int argc, char **argv) if (!debug && espeakup_mode == ESPEAKUP_MODE_SPEAKUP) (void) write(fd, &ret, 1); - /* wait for the threads to shut down. */ + // wait for the threads to shut down. pthread_join(signal_thread_id, NULL); pthread_join(softsynth_thread_id, NULL); pthread_join(espeak_thread_id, NULL); @@ -239,8 +239,7 @@ out: unlink(pidPath); if (ret != 0) (void) write(fd, &ret, 1); - /* If ret was 0, the status byte was written before joining - * the threads. */ + // If ret was 0, the status byte was written before joining the threads. } return ret; } diff --git a/src/espeakup.h b/src/espeakup.h index 6629371..58d0f6e 100644 --- a/src/espeakup.h +++ b/src/espeakup.h @@ -1,5 +1,5 @@ /* - * espeakup - interface which allows speakup to use espeak + * espeakup - interface which allows speakup to use espeak-ng * * Copyright (C) 2008 William Hubbs * @@ -20,7 +20,7 @@ #ifndef __ESPEAKUP_H #define __ESPEAKUP_H -/* This was added for gcc 4.3 */ +// This was added for gcc 4.3 #include #include diff --git a/src/queue.c b/src/queue.c index 860ad94..63a5527 100644 --- a/src/queue.c +++ b/src/queue.c @@ -1,5 +1,5 @@ /* - * espeakup - interface which allows speakup to use espeak + * espeakup - interface which allows speakup to use espeak-ng * * Note that these functions are meant to be used in either a single or * multi-threaded environment, so they know nothing about mutexes, etc. diff --git a/src/queue.h b/src/queue.h index a6a2a76..a1a2a99 100644 --- a/src/queue.h +++ b/src/queue.h @@ -1,5 +1,5 @@ /* - * espeakup - interface which allows speakup to use espeak + * espeakup - interface which allows speakup to use espeak-ng * * Copyright (C) 2008 William Hubbs * @@ -20,7 +20,7 @@ #ifndef __QUEUE_H #define __QUEUE_H -struct queue_t; /* An opaque type. */ +struct queue_t; // An opaque type. extern struct queue_t *new_queue(void); extern int queue_add(struct queue_t *q, void *entry); diff --git a/src/signal.c b/src/signal.c index f6a6a39..f0b4d57 100644 --- a/src/signal.c +++ b/src/signal.c @@ -1,5 +1,5 @@ /* - * espeakup - interface which allows speakup to use espeak + * espeakup - interface which allows speakup to use espeak-ng * * Copyright (C) 2008 William Hubbs * @@ -21,10 +21,11 @@ #include #include #include -#define STOP_MSG "s" #include "espeakup.h" +#define STOP_MSG "s" + /* * We install a dummy signal handler to let the o/s know that we * do not want the default action to be performed since we are @@ -41,7 +42,7 @@ void *signal_thread(void *arg) int sig; memset(&temp, 0, sizeof(struct sigaction)); - /* install dummy handlers for the signals we want to process */ + // install dummy handlers for the signals we want to process temp.sa_handler = dummy_handler; sigemptyset(&temp.sa_mask); sigaction(SIGINT, &temp, NULL); @@ -66,7 +67,7 @@ void *signal_thread(void *arg) pthread_mutex_lock(&queue_guard); } pthread_mutex_unlock(&queue_guard); - /* Tell the reader to stop, if it is in a select() call. */ + // Tell the reader to stop, if it is in a select() call. write(PIPE_WRITE_FD, STOP_MSG, strlen(STOP_MSG)); return NULL; } diff --git a/src/softsynth.c b/src/softsynth.c index 085582d..7d14708 100644 --- a/src/softsynth.c +++ b/src/softsynth.c @@ -1,5 +1,5 @@ /* - * espeakup - interface which allows speakup to use espeak + * espeakup - interface which allows speakup to use espeak-ng * * Copyright (C) 2008 William Hubbs * @@ -29,15 +29,15 @@ #include "espeakup.h" #include "stringhandling.h" -/* max buffer size */ +// max buffer size static const size_t maxBufferSize = 16 * 1024 + 1; -/* synth flush character */ +// synth flush character static const int synthFlushChar = 0x18; static int softFD = 0; -/* Text accumulator: */ +// Text accumulator: char *textAccumulator; int textAccumulator_l; @@ -227,26 +227,26 @@ static void request_espeak_stop(void) { pthread_mutex_lock(&queue_guard); stop_requested = 1; - pthread_cond_signal(&runner_awake); /* Wake runner, if necessary. */ + pthread_cond_signal(&runner_awake); // Wake runner, if necessary. while (should_run && stop_requested) - pthread_cond_wait(&stop_acknowledged, - &queue_guard); /* wait for acknowledgement. */ + // wait for acknowledgement. + pthread_cond_wait(&stop_acknowledged, &queue_guard); pthread_mutex_unlock(&queue_guard); } int open_softsynth(void) { int rc = 0; - /* If we're in acsint mode, we read from stdin. No need to open. */ + // If we're in acsint mode, we read from stdin. No need to open. if (espeakup_mode == ESPEAKUP_MODE_ACSINT) { softFD = STDIN_FILENO; return 0; } - /* open the softsynth. */ + // open the softsynth. softFD = open("/dev/softsynthu", O_RDWR | O_NONBLOCK); if (softFD < 0 && errno == ENOENT) - /* Kernel without unicode support? Try without unicode. */ + // Kernel without unicode support? Try without unicode. softFD = open("/dev/softsynth", O_RDWR | O_NONBLOCK); if (softFD < 0) { perror("Unable to open the softsynth device"); diff --git a/src/stringhandling.c b/src/stringhandling.c index 1adf7ae..86ed965 100644 --- a/src/stringhandling.c +++ b/src/stringhandling.c @@ -1,5 +1,5 @@ /* - * espeakup - interface which allows speakup to use espeak + * espeakup - interface which allows speakup to use espeak-ng * * Copyright (C) 2011 William Hubbs * @@ -75,9 +75,9 @@ void stringAndString(char **s, int *l, const char *t) oldlen = *l; newlen = oldlen + strlen(t); *l = newlen; - ++newlen; /* room for the 0 */ + ++newlen; // room for the 0 x = oldlen ^ newlen; - if (x > oldlen) { /* must realloc */ + if (x > oldlen) { // must realloc newlen |= (newlen >> 1); newlen |= (newlen >> 2); newlen |= (newlen >> 4); @@ -98,7 +98,7 @@ void stringAndBytes(char **s, int *l, const char *t, int cnt) *l = newlen; ++newlen; x = oldlen ^ newlen; - if (x > oldlen) { /* must realloc */ + if (x > oldlen) { // must realloc newlen |= (newlen >> 1); newlen |= (newlen >> 2); newlen |= (newlen >> 4); diff --git a/src/stringhandling.h b/src/stringhandling.h index a7d7cea..d138933 100644 --- a/src/stringhandling.h +++ b/src/stringhandling.h @@ -1,5 +1,5 @@ /* - * espeakup - interface which allows speakup to use espeak + * espeakup - interface which allows speakup to use espeak-ng * * Copyright (C) 2011 William Hubbs * diff --git a/src/version.h.in b/src/version.h.in index 8c0038e..9ba36a9 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -1,5 +1,5 @@ /* - * espeakup - interface which allows speakup to use espeak + * espeakup - interface which allows speakup to use espeak-ng * * Copyright (C) 2008 William Hubbs * From c50e4eb08875c3db7c383200899c2b1b77256b9d Mon Sep 17 00:00:00 2001 From: Alexander Epaneshnikov Date: Sat, 19 Jun 2021 10:05:57 +0300 Subject: [PATCH 155/181] remove command line from README (#33) now when we have man documentation in markdown, no need to store the same information in two places. --- README.md | 9 --------- 1 file changed, 9 deletions(-) diff --git a/README.md b/README.md index d05278f..9028d0b 100644 --- a/README.md +++ b/README.md @@ -35,15 +35,6 @@ software synthesizer and after /dev/softsynth exists. The way this is done is distribution specific, so it is beyond the scope of this documentation. -## Command Line Options - -Espeakup currently accepts the following command line options: - - --default-voice=voice, -V voice Set default voice. - --debug, -d Debug mode (stay in the foreground). - --help, -h Show this help. - --version, -v Display the software version. - ## Acknowledgements I would like to thank Marc Mulcahy, the author of the speakup to From 569e9f5b0edbf427c5b877912ac4f016efd6a492 Mon Sep 17 00:00:00 2001 From: Alexander Epaneshnikov Date: Sat, 19 Jun 2021 10:26:15 +0300 Subject: [PATCH 156/181] bump version --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 261df7e..2ba7c86 100644 --- a/meson.build +++ b/meson.build @@ -1,7 +1,7 @@ project('espeakup', 'c', default_options : ['buildtype=debugoptimized', 'c_std=gnu11', 'warning_level=3'], license : 'GPL-3.0-or-later', - version : '0.81', + version : '0.90', meson_version : '>=0.47.0') cc = meson.get_compiler('c') From 3794e8e74bdb3786c35aa1de05037faa888ebd2a Mon Sep 17 00:00:00 2001 From: Christopher Brannon Date: Sun, 20 Jun 2021 02:25:05 -0700 Subject: [PATCH 157/181] Update my email address in the docs. --- doc/espeakup.8.ronn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/espeakup.8.ronn b/doc/espeakup.8.ronn index 40b9d9c..598611c 100644 --- a/doc/espeakup.8.ronn +++ b/doc/espeakup.8.ronn @@ -71,7 +71,7 @@ espeak-ng can be found at [github](https://github.com/espeak-ng/espeak-ng) William Hubbs is the author of espeakup. -This manual page was written by Chris Brannon . +This manual page was written by Chris Brannon . current authors and maintainers can be found at [github](https://github.com/linux-speakup/espeakup/graphs/contributors) From f077d0c042974043daaef50f853770deebad5711 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Fri, 2 Jul 2021 13:24:22 -0500 Subject: [PATCH 158/181] format build files consistently --- doc/meson.build | 10 +++++----- meson.build | 14 +++++++++----- meson_options.txt | 4 ++-- services/systemd/meson.build | 9 ++++----- src/meson.build | 4 +--- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/doc/meson.build b/doc/meson.build index 9645649..f055bb4 100644 --- a/doc/meson.build +++ b/doc/meson.build @@ -1,8 +1,8 @@ ronn = find_program('ronn', required: get_option('man')) - if ronn.found() - custom_target('man', input:files('espeakup.8.ronn'), - output:'espeakup.8', - command:[ronn, '--output-dir', '@OUTDIR@', '--roff', '@INPUT@'], - install: true, install_dir: join_paths(get_option('mandir'),'man8')) + custom_target('man', + input : files('espeakup.8.ronn'), + output : 'espeakup.8', + command : [ronn, '--output-dir', '@OUTDIR@', '--roff', '@INPUT@'], + install : true, install_dir: join_paths(get_option('mandir'),'man8')) endif diff --git a/meson.build b/meson.build index 2ba7c86..0002729 100644 --- a/meson.build +++ b/meson.build @@ -1,5 +1,9 @@ project('espeakup', 'c', - default_options : ['buildtype=debugoptimized', 'c_std=gnu11', 'warning_level=3'], + default_options : [ + 'buildtype=debugoptimized', + 'c_std=gnu11', + 'warning_level=3' + ], license : 'GPL-3.0-or-later', version : '0.90', meson_version : '>=0.47.0') @@ -15,7 +19,7 @@ subdir('services') subdir('src') executable('espeakup', - espeakup_version, - espeakup_sources, - dependencies : [thread_dep, espeak_dep, alsa_dep, math_dep], - install : true) + espeakup_version, + espeakup_sources, + dependencies : [thread_dep, espeak_dep, alsa_dep, math_dep], + install : true) diff --git a/meson_options.txt b/meson_options.txt index c7e35d9..c8560b6 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,4 +1,4 @@ -option('systemd', type : 'feature', value : 'auto', - description :'enable systemd support') option('man', type : 'feature', value : 'auto', description : 'build manpage with ronn') +option('systemd', type : 'feature', value : 'auto', + description :'enable systemd support') diff --git a/services/systemd/meson.build b/services/systemd/meson.build index 4a693ed..9ae652e 100644 --- a/services/systemd/meson.build +++ b/services/systemd/meson.build @@ -3,15 +3,14 @@ prefixdir = get_option('prefix') bindir = join_paths(prefixdir, get_option('bindir')) unit_conf = configuration_data() - unit_conf.set('bindir', bindir) service_file = configure_file( - input : 'espeakup.service.in', - output : 'espeakup.service', - configuration : unit_conf + input : 'espeakup.service.in', + output : 'espeakup.service', + configuration : unit_conf ) install_data(service_file, - install_dir : unitdir + install_dir : unitdir ) diff --git a/src/meson.build b/src/meson.build index f1c4610..6221208 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,6 +1,3 @@ -espeakup_version = vcs_tag(input : 'version.h.in', output : 'version.h') - - espeakup_sources = files([ 'cli.c', 'espeak.c', @@ -10,3 +7,4 @@ espeakup_sources = files([ 'softsynth.c', 'stringhandling.c' ]) +espeakup_version = vcs_tag(input : 'version.h.in', output : 'version.h') From b7282c1a90c8d1bf87388396113321d09c665809 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Tue, 29 Jun 2021 11:12:26 -0500 Subject: [PATCH 159/181] use systemd modprobe service for speakup_soft --- services/systemd/espeakup.service.in | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/services/systemd/espeakup.service.in b/services/systemd/espeakup.service.in index ec5f4da..da97c2a 100644 --- a/services/systemd/espeakup.service.in +++ b/services/systemd/espeakup.service.in @@ -1,14 +1,13 @@ [Unit] Description=Software speech output for Speakup Documentation=man:espeakup(8) -Wants=systemd-udev-settle.service -After=systemd-udev-settle.service sound.target +Wants=modprobe@speakup_soft.service +After=modprobe@speakup_soft.service sound.target [Service] Type=forking PIDFile=/run/espeakup.pid Environment="default_voice=" -ExecStartPre=+modprobe speakup_soft ExecStart=@bindir@/espeakup --default-voice=${default_voice} ExecReload=kill -HUP $MAINPID Restart=always From 8f18ad7f887c64f307b1a8ccc0df99a44a041a25 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Mon, 5 Jul 2021 19:32:37 -0500 Subject: [PATCH 160/181] add dupeString wrapper function This function calls strdup and exits on failure. --- src/stringhandling.c | 11 +++++++++++ src/stringhandling.h | 1 + 2 files changed, 12 insertions(+) diff --git a/src/stringhandling.c b/src/stringhandling.c index 86ed965..096b870 100644 --- a/src/stringhandling.c +++ b/src/stringhandling.c @@ -62,6 +62,17 @@ void *reallocMem(void *p, size_t n) return s; } +char *dupeString(char *s) +{ + char *c; + + if (!(c = strdup(s))) { + fprintf(stderr, "Out of memory!\n"); + exit(1); + } + return c; +} + char *initString(int *l) { *l = 0; diff --git a/src/stringhandling.h b/src/stringhandling.h index d138933..7f104ef 100644 --- a/src/stringhandling.h +++ b/src/stringhandling.h @@ -26,6 +26,7 @@ extern char *EMPTYSTRING; void *allocMem(size_t n); void *reallocMem(void *p, size_t n); +char *dupeString(char *s); char *initString(int *l); void stringAndString(char **s, int *l, const char *t); void stringAndBytes(char **s, int *l, const char *t, int cnt); From e858481c0a158514e383c9282641a436a07e6de2 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Mon, 5 Jul 2021 19:35:24 -0500 Subject: [PATCH 161/181] use dupeString in command line processing --- src/cli.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/cli.c b/src/cli.c index a4cf48f..bc25c79 100644 --- a/src/cli.c +++ b/src/cli.c @@ -23,6 +23,7 @@ #include #include "espeakup.h" +#include "stringhandling.h" #include "version.h" /* pid path */ @@ -72,18 +73,15 @@ static void show_version(void) void process_cli(int argc, char **argv) { int opt; - char *cp; do { opt = getopt_long(argc, argv, shortOptions, longOptions, NULL); switch (opt) { case 'p': - cp = strdup(optarg); - if (cp != NULL) - pidPath = cp; + pidPath = dupeString(optarg); break; case 'V': - defaultVoice = strdup(optarg); + defaultVoice = dupeString(optarg); break; case 'a': espeakup_mode = ESPEAKUP_MODE_ACSINT; From 316e4fc51d7e9db322feaf84e202e9243023671e Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sat, 21 Aug 2021 14:53:27 +0200 Subject: [PATCH 162/181] softsynth: on error, be clear we are talking about /dev/softsynth --- src/softsynth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/softsynth.c b/src/softsynth.c index 7d14708..9eb75a4 100644 --- a/src/softsynth.c +++ b/src/softsynth.c @@ -249,7 +249,7 @@ int open_softsynth(void) // Kernel without unicode support? Try without unicode. softFD = open("/dev/softsynth", O_RDWR | O_NONBLOCK); if (softFD < 0) { - perror("Unable to open the softsynth device"); + perror("Unable to open the /dev/softsynth device"); rc = -1; } return rc; From ca234f2122a9460a7290e0ea6a3dad3fdd8182df Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Fri, 11 Feb 2022 00:30:26 +0100 Subject: [PATCH 163/181] Request systemd to prioritize espeakup So speech doesn't get choppy on a loaded system. As suggested by Nick Gawronski. This fixes #46. --- services/systemd/espeakup.service.in | 1 + 1 file changed, 1 insertion(+) diff --git a/services/systemd/espeakup.service.in b/services/systemd/espeakup.service.in index da97c2a..ca5b2d7 100644 --- a/services/systemd/espeakup.service.in +++ b/services/systemd/espeakup.service.in @@ -11,6 +11,7 @@ Environment="default_voice=" ExecStart=@bindir@/espeakup --default-voice=${default_voice} ExecReload=kill -HUP $MAINPID Restart=always +Nice=-10 [Install] WantedBy=sound.target From c99bfb8e4519196b8338f0b06adc632e09482cf7 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Fri, 11 Feb 2022 00:31:05 +0100 Subject: [PATCH 164/181] Request systemd to protect espeakup from OOM Otherwise it might get killed on memory pressure. --- services/systemd/espeakup.service.in | 1 + 1 file changed, 1 insertion(+) diff --git a/services/systemd/espeakup.service.in b/services/systemd/espeakup.service.in index ca5b2d7..075a717 100644 --- a/services/systemd/espeakup.service.in +++ b/services/systemd/espeakup.service.in @@ -12,6 +12,7 @@ ExecStart=@bindir@/espeakup --default-voice=${default_voice} ExecReload=kill -HUP $MAINPID Restart=always Nice=-10 +OOMScoreAdjust=-900 [Install] WantedBy=sound.target From 78e561fae952a1230e0534f4e461a31a6d7a51e0 Mon Sep 17 00:00:00 2001 From: Brandon McGinty Date: Sat, 12 Feb 2022 15:29:23 -0600 Subject: [PATCH 165/181] use correct case for --pid-file option This permits --pid-file to be specified. The getopt_long option was looking for a lowercase p, and the pid-file option used an uppercase P. This meant that pid-file was never settable. --- src/cli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli.c b/src/cli.c index bc25c79..8453587 100644 --- a/src/cli.c +++ b/src/cli.c @@ -77,7 +77,7 @@ void process_cli(int argc, char **argv) do { opt = getopt_long(argc, argv, shortOptions, longOptions, NULL); switch (opt) { - case 'p': + case 'P': pidPath = dupeString(optarg); break; case 'V': From 108c28ae08bdffd4861f42cdf42374bb00c77bb7 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Tue, 1 Mar 2022 01:28:38 +0100 Subject: [PATCH 166/181] Throttle on EE_BUFFER_FULL errors When espeak returns EE_BUFFER_FULL we should just wait a bit before retrying. Also, we don't want to lose the current entry. We however want to wake up as soon as possible on stop request. --- src/espeak.c | 24 ++++++++++++++++++++---- src/espeakup.c | 1 + src/espeakup.h | 1 + src/softsynth.c | 1 + 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/espeak.c b/src/espeak.c index 135c6b5..b4b58ca 100644 --- a/src/espeak.c +++ b/src/espeak.c @@ -325,16 +325,16 @@ static void reinitialize_espeak(struct synth_t *s) return; } +static struct espeak_entry_t *current = NULL; static void queue_process_entry(struct synth_t *s) { - espeak_ERROR error; + espeak_ERROR error = EE_OK; char markbuff[50]; - static struct espeak_entry_t *current = NULL; if (current != queue_peek(synth_queue)) { if (current) free_espeak_entry(current); - current = (struct espeak_entry_t *) queue_remove(synth_queue); + current = queue_peek(synth_queue); } pthread_mutex_unlock(&queue_guard); @@ -386,9 +386,25 @@ static void queue_process_entry(struct synth_t *s) break; } + pthread_mutex_lock(&queue_guard); if (error == EE_OK) { + /* Processed, drop it */ + struct espeak_entry_t *unqueued = queue_remove(synth_queue); + assert(unqueued == current); free_espeak_entry(current); current = NULL; + } else { + if (error == EE_BUFFER_FULL) + { + /* Give speak a little break before retrying */ + struct timespec timeout; + clock_gettime(CLOCK_REALTIME, &timeout); + timeout.tv_sec++; + /* But wake up immediately if we have to stop */ + pthread_cond_timedwait(&wake_stop, &queue_guard, &timeout); + } + else + fprintf(stderr, "espeak error: %d\n", error); } } @@ -450,6 +466,7 @@ void *espeak_thread(void *arg) pthread_cond_wait(&runner_awake, &queue_guard); if (stop_requested) { + current = NULL; stop_speech(); synth_queue_clear(); stop_requested = 0; @@ -458,7 +475,6 @@ void *espeak_thread(void *arg) while (should_run && queue_peek(synth_queue) && !stop_requested) { queue_process_entry(s); - pthread_mutex_lock(&queue_guard); } } pthread_cond_signal(&stop_acknowledged); diff --git a/src/espeakup.c b/src/espeakup.c index 86b3a88..baeee11 100644 --- a/src/espeakup.c +++ b/src/espeakup.c @@ -40,6 +40,7 @@ volatile int should_run = 1; espeak_AUDIO_OUTPUT audio_mode; pthread_cond_t runner_awake = PTHREAD_COND_INITIALIZER; +pthread_cond_t wake_stop = PTHREAD_COND_INITIALIZER; pthread_cond_t stop_acknowledged = PTHREAD_COND_INITIALIZER; pthread_mutex_t queue_guard = PTHREAD_MUTEX_INITIALIZER; diff --git a/src/espeakup.h b/src/espeakup.h index 58d0f6e..62a5ca8 100644 --- a/src/espeakup.h +++ b/src/espeakup.h @@ -99,6 +99,7 @@ extern int self_pipe_fds[2]; #define PIPE_WRITE_FD (self_pipe_fds[1]) extern pthread_cond_t runner_awake; +extern pthread_cond_t wake_stop; extern pthread_cond_t stop_acknowledged; extern pthread_mutex_t queue_guard; diff --git a/src/softsynth.c b/src/softsynth.c index 9eb75a4..ca2e47e 100644 --- a/src/softsynth.c +++ b/src/softsynth.c @@ -228,6 +228,7 @@ static void request_espeak_stop(void) pthread_mutex_lock(&queue_guard); stop_requested = 1; pthread_cond_signal(&runner_awake); // Wake runner, if necessary. + pthread_cond_signal(&wake_stop); // Wake runner, if necessary. while (should_run && stop_requested) // wait for acknowledgement. pthread_cond_wait(&stop_acknowledged, &queue_guard); From d7c06a6f9f9c2d00801d14314eaf55bfdb328442 Mon Sep 17 00:00:00 2001 From: Alexander Epaneshnikov Date: Fri, 11 Mar 2022 16:51:28 +0300 Subject: [PATCH 167/181] meson: switch from deprecated functions (#49) --- meson.build | 2 +- services/systemd/meson.build | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index 0002729..38788d2 100644 --- a/meson.build +++ b/meson.build @@ -6,7 +6,7 @@ project('espeakup', 'c', ], license : 'GPL-3.0-or-later', version : '0.90', - meson_version : '>=0.47.0') + meson_version : '>=0.51.0') cc = meson.get_compiler('c') thread_dep = dependency('threads') diff --git a/services/systemd/meson.build b/services/systemd/meson.build index 9ae652e..eccbde7 100644 --- a/services/systemd/meson.build +++ b/services/systemd/meson.build @@ -1,4 +1,4 @@ -unitdir = systemd.get_pkgconfig_variable('systemdsystemunitdir') +unitdir = systemd.get_variable(pkgconfig: 'systemdsystemunitdir') prefixdir = get_option('prefix') bindir = join_paths(prefixdir, get_option('bindir')) From 98dc10374915c087c3a7368ccdb28bbb3df701b6 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Mon, 15 Aug 2022 23:48:26 +0200 Subject: [PATCH 168/181] queue_process_entry: Avoid leaving error uninitialized CMD_PAUSE was not actually setting error to EE_OK, and the default case, even if it is not supposed to happen, should set error to something sane. --- src/espeak.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/espeak.c b/src/espeak.c index b4b58ca..73876b4 100644 --- a/src/espeak.c +++ b/src/espeak.c @@ -377,12 +377,18 @@ static void queue_process_entry(struct synth_t *s) break; case CMD_PAUSE: if (!paused_espeak) { - espeak_Cancel(); - espeak_Terminate(); - paused_espeak = 1; + error = espeak_Cancel(); + if (error == EE_OK) + error = espeak_Terminate(); + if (error == EE_OK) + paused_espeak = 1; + } else { + error = EE_OK; } break; default: + /* Uh? */ + error = EE_OK; break; } From fa848f509e83bc8dff23e6fb1f2425e2f3ea7393 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Mon, 15 Aug 2022 23:41:52 +0200 Subject: [PATCH 169/181] set_punctuation: Fix punctuation levels values They do not actually follow the espeak values (and have no reason to, anyway). --- src/espeak.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/espeak.c b/src/espeak.c index 73876b4..90bdfc6 100644 --- a/src/espeak.c +++ b/src/espeak.c @@ -108,12 +108,31 @@ static espeak_ERROR set_punctuation(struct synth_t *s, int punct, enum adjust_t adj) { espeak_ERROR rc; + espeak_PUNCT_TYPE espeak_punct; if (adj == ADJ_DEC) punct = -punct; if (adj != ADJ_SET) punct += s->punct; - rc = espeak_SetParameter(espeakPUNCTUATION, punct, 0); + + switch (punct) { + case 0: + espeak_punct = espeakPUNCT_NONE; + break; + case 1: + espeak_punct = espeakPUNCT_SOME; + break; + case 2: + /* XXX: approximation */ + espeak_punct = espeakPUNCT_SOME; + break; + case 3: + default: + espeak_punct = espeakPUNCT_ALL; + break; + } + + rc = espeak_SetParameter(espeakPUNCTUATION, espeak_punct, 0); if (rc == EE_OK) s->punct = punct; return rc; From dc1f1b9efa2df9dc7e7ea7267b7a1cb0c1caf568 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Fri, 22 Aug 2025 14:12:32 +0300 Subject: [PATCH 170/181] Fix deprecated Meson setup command warning in README (#61) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: alex19EP <4889846+alex19EP@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9028d0b..e1395b0 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ espeakup yet, espeakup just uses meson, so you should be able to change to the source directory, then type: ```bash -meson . ./build +meson setup . ./build cd ./build ninja sudo ninja install From d1f7e2384ba6c29e76f570df45301c6b6df22d44 Mon Sep 17 00:00:00 2001 From: Alexander Epaneshnikov Date: Thu, 11 Jun 2026 11:05:10 +0300 Subject: [PATCH 171/181] espeak: do not call espeak_Cancel() while holding queue_guard When a flush is requested, the espeak thread called stop_speech() -> espeak_Cancel() with queue_guard held. espeak_Cancel() waits for espeak-ng's internal say thread to acknowledge the cancellation, and that thread can be blocked indefinitely inside a blocking ALSA call (snd_pcm_writei/snd_pcm_drain on a wedged device, as seen with EBUSY errors). In that case queue_guard was held forever, which in turn: - blocked the signal thread on pthread_mutex_lock(), so SIGINT/SIGTERM appeared to be ignored and only SIGKILL could end the process; - left the softsynth thread stuck in request_espeak_stop(), so /dev/softsynth was no longer drained, speakup's kernel buffer filled up, and console output (e.g. dmesg) stalled. Release queue_guard around the espeak_Cancel() call. This is safe because the only queue producer, the softsynth thread, is blocked waiting for stop_acknowledged for as long as stop_requested is set, so the queue cannot be mutated concurrently. Helps: https://github.com/linux-speakup/espeakup/issues/45 Helps: https://github.com/linux-speakup/espeakup/issues/62 Co-Authored-By: Claude --- src/espeak.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/espeak.c b/src/espeak.c index 90bdfc6..41a7e99 100644 --- a/src/espeak.c +++ b/src/espeak.c @@ -492,7 +492,16 @@ void *espeak_thread(void *arg) if (stop_requested) { current = NULL; + /* Call into espeak with queue_guard released: espeak_Cancel + * can take time, or even block indefinitely when the audio + * output is wedged, and holding the lock here would prevent + * the other threads from ever making progress again. The + * queue cannot change concurrently: the only producer (the + * softsynth thread) is blocked waiting for stop_acknowledged + * as long as stop_requested is set. */ + pthread_mutex_unlock(&queue_guard); stop_speech(); + pthread_mutex_lock(&queue_guard); synth_queue_clear(); stop_requested = 0; pthread_cond_signal(&stop_acknowledged); From 2b959e874e26729b7d508a7d4d88eb33f331c24c Mon Sep 17 00:00:00 2001 From: Alexander Epaneshnikov Date: Thu, 11 Jun 2026 11:05:56 +0300 Subject: [PATCH 172/181] signal: wake all condition-variable waiters on shutdown On SIGINT/SIGTERM, the signal thread only set should_run to 0 and relied on a wake-up chain to propagate the shutdown: the self-pipe wakes the softsynth thread out of select(), which on exit signals runner_awake to wake the espeak thread. That chain breaks whenever the softsynth thread is not sitting in select() but waiting on stop_acknowledged in request_espeak_stop(): nobody ever signals that condition variable on shutdown, so the thread never re-evaluates should_run and the process never exits. Broadcast all three condition variables after clearing should_run, so that every parked thread re-checks its predicate, whichever wait it is blocked in. Helps: https://github.com/linux-speakup/espeakup/issues/45 Helps: https://github.com/linux-speakup/espeakup/issues/62 Co-Authored-By: Claude --- src/signal.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/signal.c b/src/signal.c index f0b4d57..b6ddefc 100644 --- a/src/signal.c +++ b/src/signal.c @@ -58,6 +58,14 @@ void *signal_thread(void *arg) case SIGTERM: pthread_mutex_lock(&queue_guard); should_run = 0; + /* Wake up any thread waiting on a condition variable so + * that it notices the shutdown request: the softsynth + * thread may be waiting for a stop acknowledgement, and + * the espeak thread may be waiting for work or throttling + * before a retry. */ + pthread_cond_broadcast(&runner_awake); + pthread_cond_broadcast(&wake_stop); + pthread_cond_broadcast(&stop_acknowledged); pthread_mutex_unlock(&queue_guard); break; default: From e92edf96dc86ee4973bba468f35cfb173cd60a49 Mon Sep 17 00:00:00 2001 From: Alexander Epaneshnikov Date: Thu, 11 Jun 2026 11:06:35 +0300 Subject: [PATCH 173/181] softsynth: bound the wait for espeak to acknowledge a stop request request_espeak_stop() waited forever for the espeak thread to acknowledge the stop. If espeak-ng is wedged inside the audio output (e.g. an ALSA device blocked or stuck returning EBUSY, as reported in issue #62), the acknowledgement never comes, and the softsynth thread stops draining /dev/softsynth forever. Speakup's kernel buffer then fills up and console output stalls, which matches the "blocks dmesg output after a couple of pages" observation in issue #45. The process goes silent and only SIGKILL gets rid of it. Wait at most 10 seconds for the acknowledgement (a normal cancellation takes milliseconds; the timeout can only trigger when espeak is truly stuck). On timeout, exit with a clear message so that the init system respawns espeakup in a clean state: our systemd unit already has Restart=always. A one-second restart beats an unkillable silent daemon, and was explicitly requested by the reporter of issue #62. Helps: https://github.com/linux-speakup/espeakup/issues/45 Helps: https://github.com/linux-speakup/espeakup/issues/62 Co-Authored-By: Claude --- src/softsynth.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/softsynth.c b/src/softsynth.c index ca2e47e..d2fe585 100644 --- a/src/softsynth.c +++ b/src/softsynth.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include "espeakup.h" @@ -223,15 +224,37 @@ static void process_buffer_acsint(struct synth_t *s, char *buf, ssize_t length) } } +/* How long to wait for the espeak thread to acknowledge a stop request + * before concluding that espeak is wedged beyond in-process recovery. */ +static const int stopAckTimeout = 10; + static void request_espeak_stop(void) { + struct timespec timeout; + int err = 0; + pthread_mutex_lock(&queue_guard); stop_requested = 1; pthread_cond_signal(&runner_awake); // Wake runner, if necessary. pthread_cond_signal(&wake_stop); // Wake runner, if necessary. - while (should_run && stop_requested) + clock_gettime(CLOCK_REALTIME, &timeout); + timeout.tv_sec += stopAckTimeout; + while (should_run && stop_requested && err != ETIMEDOUT) // wait for acknowledgement. - pthread_cond_wait(&stop_acknowledged, &queue_guard); + err = pthread_cond_timedwait(&stop_acknowledged, &queue_guard, + &timeout); + if (should_run && stop_requested) { + /* The espeak thread is stuck in a call into espeak, most likely + * on a wedged audio device. There is no way to recover from + * within the process: exit so that the init system can respawn + * us in a clean state, rather than staying silent, ignoring + * SIGTERM, and stalling the whole console by not draining + * /dev/softsynth anymore. Use _exit because exit could hang in + * library destructors while the audio device is wedged. */ + fprintf(stderr, "espeakup: espeak did not acknowledge a stop " + "request within %d seconds, aborting\n", stopAckTimeout); + _exit(3); + } pthread_mutex_unlock(&queue_guard); } From 7405455baf4a20f0f8e31a057ecbb59f64f636e8 Mon Sep 17 00:00:00 2001 From: Alexander Epaneshnikov Date: Thu, 11 Jun 2026 11:07:43 +0300 Subject: [PATCH 174/181] espeak: back off before retrying after any espeak error When processing an entry failed, only EE_BUFFER_FULL throttled before the retry; any other persistent error (e.g. EE_INTERNAL_ERROR after espeak was terminated) made queue_process_entry retry the same entry in a tight loop with no sleep, burning a whole CPU while printing to a stderr that points to /dev/null in daemon mode. Factor the one-second throttle out into espeak_wait_retry() and apply it to every failed entry. The wake_stop condition variable still interrupts the wait immediately when a flush comes in. Co-Authored-By: Claude --- src/espeak.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/espeak.c b/src/espeak.c index 41a7e99..f6b4d1e 100644 --- a/src/espeak.c +++ b/src/espeak.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "espeakup.h" @@ -344,6 +345,19 @@ static void reinitialize_espeak(struct synth_t *s) return; } +/* Wait for up to a second before retrying an entry which could not be + * processed, so that we do not busy-loop on a persistent error. Called + * and returns with queue_guard held. Wakes up immediately if a stop is + * requested. */ +static void espeak_wait_retry(void) +{ + struct timespec timeout; + + clock_gettime(CLOCK_REALTIME, &timeout); + timeout.tv_sec++; + pthread_cond_timedwait(&wake_stop, &queue_guard, &timeout); +} + static struct espeak_entry_t *current = NULL; static void queue_process_entry(struct synth_t *s) { @@ -419,17 +433,13 @@ static void queue_process_entry(struct synth_t *s) free_espeak_entry(current); current = NULL; } else { - if (error == EE_BUFFER_FULL) - { - /* Give speak a little break before retrying */ - struct timespec timeout; - clock_gettime(CLOCK_REALTIME, &timeout); - timeout.tv_sec++; - /* But wake up immediately if we have to stop */ - pthread_cond_timedwait(&wake_stop, &queue_guard, &timeout); - } - else + if (error != EE_BUFFER_FULL) fprintf(stderr, "espeak error: %d\n", error); + /* The entry stays queued and will be retried. Give espeak a + * little break before that, whatever the error: previously only + * EE_BUFFER_FULL throttled, and any other persistent error made + * us retry the same entry in a tight loop, burning a whole CPU. */ + espeak_wait_retry(); } } From a504688f3d3bc1bcdefd89c015c33507d1b4d411 Mon Sep 17 00:00:00 2001 From: Alexander Epaneshnikov Date: Thu, 11 Jun 2026 11:08:16 +0300 Subject: [PATCH 175/181] espeak: do not call espeak functions after a failed reinitialization When resuming from CMD_PAUSE, queue_process_entry ignored the result of reinitialize_espeak: if espeak_Initialize failed, paused_espeak remained set, yet the entry was processed anyway, calling espeak_Synth & co on a terminated engine. Combined with the busy-retry loop, this produced an endless stream of failing calls against a dead engine. Make reinitialize_espeak report failure, and when espeak is unavailable, leave the entry queued and back off before trying to reinitialize again. Co-Authored-By: Claude --- src/espeak.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/espeak.c b/src/espeak.c index f6b4d1e..a77fcf3 100644 --- a/src/espeak.c +++ b/src/espeak.c @@ -321,7 +321,7 @@ static void synth_queue_clear() } } -static void reinitialize_espeak(struct synth_t *s) +static int reinitialize_espeak(struct synth_t *s) { int rate; @@ -329,7 +329,7 @@ static void reinitialize_espeak(struct synth_t *s) rate = espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 0, NULL, 0); if (rate < 0) { fprintf(stderr, "Unable to initialize espeak.\n"); - return; + return -1; } espeak_SetSynthCallback(callback); @@ -342,7 +342,7 @@ static void reinitialize_espeak(struct synth_t *s) espeak_SetParameter(espeakVOLUME, (s->volume + 1) * volumeMultiplier, 0); espeak_SetParameter(espeakCAPITALS, 0, 0); paused_espeak = 0; - return; + return 0; } /* Wait for up to a second before retrying an entry which could not be @@ -372,7 +372,15 @@ static void queue_process_entry(struct synth_t *s) pthread_mutex_unlock(&queue_guard); if (current->cmd != CMD_PAUSE && paused_espeak) { - reinitialize_espeak(s); + if (reinitialize_espeak(s) < 0) { + /* Espeak is unavailable, so the entry cannot be processed. + * Calling espeak functions on a terminated engine would + * just fail (or worse). Leave the entry queued and retry + * after a small pause. */ + pthread_mutex_lock(&queue_guard); + espeak_wait_retry(); + return; + } } switch (current->cmd) { From 71d0e1fa2a4f90ef2ed89ba807737374ecba1968 Mon Sep 17 00:00:00 2001 From: Alexander Epaneshnikov Date: Thu, 11 Jun 2026 11:09:29 +0300 Subject: [PATCH 176/181] espeak: detect a wedged engine, restart it, and eventually give up Issue #62 reports espeakup going permanently silent after libespeak-ng prints "error: Device or resource busy" (EBUSY from the ALSA device, via pcaudiolib). Once the audio output is wedged, espeak's internal command queue never drains, every espeak_Synth call fails with EE_BUFFER_FULL forever, and espeakup just kept retrying silently. EE_BUFFER_FULL is also perfectly normal while a long backlog is being played back, so persistent failure alone is not a reliable signal. To tell a backlogged engine from a wedged one, note progress whenever the synth callback fires (it is invoked for every chunk espeak synthesizes, and synthesis is paced by audio playback): if entries keep failing for ~10 seconds with no callback activity at all, declare the engine wedged. Recovery is layered: - restart the engine in-process (espeak_Cancel + espeak_Terminate + reinitialize), which recovers transient device problems; - if the engine has not been healthy for at least a minute between such restarts, after 3 restarts give up and exit, letting the init system (Restart=always in our systemd unit) respawn espeakup in a completely clean state; - if the restart itself blocks on the wedged device, the stop-acknowledgement timeout in the softsynth thread eventually terminates the process as a last resort. A quick espeak_Synth success right after a restart does not count as healthy on purpose: espeak's freshly emptied internal queue accepts entries even while the device is still wedged. Helps: https://github.com/linux-speakup/espeakup/issues/45 Helps: https://github.com/linux-speakup/espeakup/issues/62 Co-Authored-By: Claude --- src/espeak.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 80 insertions(+), 2 deletions(-) diff --git a/src/espeak.c b/src/espeak.c index a77fcf3..c701f74 100644 --- a/src/espeak.c +++ b/src/espeak.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "espeakup.h" @@ -48,9 +49,30 @@ const int volumeMultiplier = 22; volatile int stop_requested = 0; int paused_espeak = 1; +/* Wedged-engine detection. Espeak may legitimately refuse entries for a + * while (EE_BUFFER_FULL while a long backlog is being played back), so a + * failing entry is normally just retried. But when entries keep failing + * while the synth callback reports no progress at all, the audio output + * is most likely wedged (e.g. an ALSA device stuck returning EBUSY). + * After ESPEAK_STALL_RETRIES consecutive such retries (about one second + * each), restart the engine; after ESPEAK_MAX_RESTARTS restarts without + * the engine having been healthy for ESPEAK_HEALTHY_SECS in between, + * give up and exit, so that the init system can respawn us. */ +#define ESPEAK_STALL_RETRIES 10 +#define ESPEAK_MAX_RESTARTS 3 +#define ESPEAK_HEALTHY_SECS 60 + +/* Set by the synth callback whenever espeak makes synthesis progress; + * used to tell a merely backlogged engine from a wedged one. */ +static volatile int synth_progressed = 0; +static int stalled_retries = 0; +static int restart_attempts = 0; +static struct timespec last_restart; + static int callback(short *wav, int numsamples, espeak_EVENT *events) { int i; + synth_progressed = 1; for (i = 0; events[i].type != espeakEVENT_LIST_TERMINATED; i++) { if (events[i].type == espeakEVENT_MARK) { int mark = atoi(events[i].id.name); @@ -358,6 +380,50 @@ static void espeak_wait_retry(void) pthread_cond_timedwait(&wake_stop, &queue_guard, &timeout); } +/* Handle an entry which could not be processed. Called and returns + * with queue_guard held. + * Normally just back off before the retry, but watch out for a wedged + * engine: if entries keep failing while the synth callback shows no + * progress at all, restart the engine, and if restarting does not help + * either, exit so that the init system respawns us in a clean state. */ +static void espeak_handle_failure(struct synth_t *s) +{ + if (synth_progressed) { + /* Espeak is making progress, it is merely backlogged. */ + synth_progressed = 0; + stalled_retries = 0; + } else if (++stalled_retries >= ESPEAK_STALL_RETRIES) { + stalled_retries = 0; + if (++restart_attempts > ESPEAK_MAX_RESTARTS) { + fprintf(stderr, "espeakup: espeak keeps failing without " + "making progress and restarting it did not help, " + "aborting\n"); + /* Use _exit because exit could hang in library destructors + * while the audio device is wedged. */ + _exit(3); + } + fprintf(stderr, "espeakup: espeak has been failing without " + "making progress for %d seconds, restarting it\n", + ESPEAK_STALL_RETRIES); + /* Call into espeak with queue_guard released: these calls can + * take time, or block on a wedged audio device. If they do + * block forever, the stop-acknowledgement timeout in the + * softsynth thread is our last resort. */ + pthread_mutex_unlock(&queue_guard); + if (!paused_espeak) { + espeak_Cancel(); + espeak_Terminate(); + paused_espeak = 1; + } + reinitialize_espeak(s); + clock_gettime(CLOCK_MONOTONIC, &last_restart); + pthread_mutex_lock(&queue_guard); + return; + } + + espeak_wait_retry(); +} + static struct espeak_entry_t *current = NULL; static void queue_process_entry(struct synth_t *s) { @@ -378,7 +444,7 @@ static void queue_process_entry(struct synth_t *s) * just fail (or worse). Leave the entry queued and retry * after a small pause. */ pthread_mutex_lock(&queue_guard); - espeak_wait_retry(); + espeak_handle_failure(s); return; } } @@ -440,6 +506,18 @@ static void queue_process_entry(struct synth_t *s) assert(unqueued == current); free_espeak_entry(current); current = NULL; + stalled_retries = 0; + if (restart_attempts) { + /* Forget about past restarts once the engine has been + * healthy for a while. Entries can spuriously succeed + * right after a restart while the audio output is still + * wedged (espeak's internal queue is empty again), so a + * quick success must not reset the counter. */ + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + if (now.tv_sec - last_restart.tv_sec >= ESPEAK_HEALTHY_SECS) + restart_attempts = 0; + } } else { if (error != EE_BUFFER_FULL) fprintf(stderr, "espeak error: %d\n", error); @@ -447,7 +525,7 @@ static void queue_process_entry(struct synth_t *s) * little break before that, whatever the error: previously only * EE_BUFFER_FULL throttled, and any other persistent error made * us retry the same entry in a tight loop, burning a whole CPU. */ - espeak_wait_retry(); + espeak_handle_failure(s); } } From 683544964229388933d5f9a7722a2327312ad5d3 Mon Sep 17 00:00:00 2001 From: Alexander Epaneshnikov Date: Thu, 11 Jun 2026 11:34:40 +0300 Subject: [PATCH 177/181] fixup! softsynth: bound the wait for espeak to acknowledge a stop request --- src/espeakup.c | 15 ++++++++++++++- src/softsynth.c | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/espeakup.c b/src/espeakup.c index baeee11..1e39aaf 100644 --- a/src/espeakup.c +++ b/src/espeakup.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include "espeakup.h" @@ -41,7 +42,8 @@ espeak_AUDIO_OUTPUT audio_mode; pthread_cond_t runner_awake = PTHREAD_COND_INITIALIZER; pthread_cond_t wake_stop = PTHREAD_COND_INITIALIZER; -pthread_cond_t stop_acknowledged = PTHREAD_COND_INITIALIZER; +/* Initialized in main: uses the monotonic clock for timed waits. */ +pthread_cond_t stop_acknowledged; pthread_mutex_t queue_guard = PTHREAD_MUTEX_INITIALIZER; int espeakup_start_daemon(void) @@ -147,6 +149,17 @@ int main(int argc, char **argv) struct synth_t s = { .voice = "", }; + pthread_condattr_t monotonic_attr; + + /* Condition variables used with pthread_cond_timedwait must use the + * monotonic clock, so that wall-clock adjustments (NTP, an + * installer setting the system time) cannot make the timeouts fire + * too early or far too late. */ + pthread_condattr_init(&monotonic_attr); + pthread_condattr_setclock(&monotonic_attr, CLOCK_MONOTONIC); + pthread_cond_init(&stop_acknowledged, &monotonic_attr); + pthread_condattr_destroy(&monotonic_attr); + synth_queue = new_queue(); if (!synth_queue) { diff --git a/src/softsynth.c b/src/softsynth.c index d2fe585..e382b32 100644 --- a/src/softsynth.c +++ b/src/softsynth.c @@ -237,7 +237,7 @@ static void request_espeak_stop(void) stop_requested = 1; pthread_cond_signal(&runner_awake); // Wake runner, if necessary. pthread_cond_signal(&wake_stop); // Wake runner, if necessary. - clock_gettime(CLOCK_REALTIME, &timeout); + clock_gettime(CLOCK_MONOTONIC, &timeout); timeout.tv_sec += stopAckTimeout; while (should_run && stop_requested && err != ETIMEDOUT) // wait for acknowledgement. From 76a2af5008794fa87330c2649ca13c6705327077 Mon Sep 17 00:00:00 2001 From: Alexander Epaneshnikov Date: Thu, 11 Jun 2026 11:35:26 +0300 Subject: [PATCH 178/181] fixup! espeak: back off before retrying after any espeak error --- src/espeak.c | 2 +- src/espeakup.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/espeak.c b/src/espeak.c index c701f74..996d574 100644 --- a/src/espeak.c +++ b/src/espeak.c @@ -375,7 +375,7 @@ static void espeak_wait_retry(void) { struct timespec timeout; - clock_gettime(CLOCK_REALTIME, &timeout); + clock_gettime(CLOCK_MONOTONIC, &timeout); timeout.tv_sec++; pthread_cond_timedwait(&wake_stop, &queue_guard, &timeout); } diff --git a/src/espeakup.c b/src/espeakup.c index 1e39aaf..4e077f5 100644 --- a/src/espeakup.c +++ b/src/espeakup.c @@ -41,8 +41,8 @@ volatile int should_run = 1; espeak_AUDIO_OUTPUT audio_mode; pthread_cond_t runner_awake = PTHREAD_COND_INITIALIZER; -pthread_cond_t wake_stop = PTHREAD_COND_INITIALIZER; -/* Initialized in main: uses the monotonic clock for timed waits. */ +/* Initialized in main: use the monotonic clock for timed waits. */ +pthread_cond_t wake_stop; pthread_cond_t stop_acknowledged; pthread_mutex_t queue_guard = PTHREAD_MUTEX_INITIALIZER; @@ -157,6 +157,7 @@ int main(int argc, char **argv) * too early or far too late. */ pthread_condattr_init(&monotonic_attr); pthread_condattr_setclock(&monotonic_attr, CLOCK_MONOTONIC); + pthread_cond_init(&wake_stop, &monotonic_attr); pthread_cond_init(&stop_acknowledged, &monotonic_attr); pthread_condattr_destroy(&monotonic_attr); From cc1447b16aba1da2ab004c13922941b38d480b7f Mon Sep 17 00:00:00 2001 From: Alexander Epaneshnikov Date: Thu, 11 Jun 2026 11:35:52 +0300 Subject: [PATCH 179/181] fixup! espeak: detect a wedged engine, restart it, and eventually give up --- src/espeak.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/espeak.c b/src/espeak.c index 996d574..60cc996 100644 --- a/src/espeak.c +++ b/src/espeak.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -63,8 +64,9 @@ int paused_espeak = 1; #define ESPEAK_HEALTHY_SECS 60 /* Set by the synth callback whenever espeak makes synthesis progress; - * used to tell a merely backlogged engine from a wedged one. */ -static volatile int synth_progressed = 0; + * used to tell a merely backlogged engine from a wedged one. The + * callback runs in espeak's own thread, so the flag is atomic. */ +static atomic_int synth_progressed = 0; static int stalled_retries = 0; static int restart_attempts = 0; static struct timespec last_restart; @@ -72,7 +74,7 @@ static struct timespec last_restart; static int callback(short *wav, int numsamples, espeak_EVENT *events) { int i; - synth_progressed = 1; + atomic_store(&synth_progressed, 1); for (i = 0; events[i].type != espeakEVENT_LIST_TERMINATED; i++) { if (events[i].type == espeakEVENT_MARK) { int mark = atoi(events[i].id.name); @@ -388,9 +390,8 @@ static void espeak_wait_retry(void) * either, exit so that the init system respawns us in a clean state. */ static void espeak_handle_failure(struct synth_t *s) { - if (synth_progressed) { + if (atomic_exchange(&synth_progressed, 0)) { /* Espeak is making progress, it is merely backlogged. */ - synth_progressed = 0; stalled_retries = 0; } else if (++stalled_retries >= ESPEAK_STALL_RETRIES) { stalled_retries = 0; From c3c7c6a007f1c758ec6c9fe2b9ecd73bb7be6129 Mon Sep 17 00:00:00 2001 From: Achill Gilgenast Date: Mon, 29 Jun 2026 15:56:42 +0200 Subject: [PATCH 180/181] services: add fallback systemd unitdir if systemd is not available Allows building the service files without a systemd dependency by defining a default systemd user unit directory. Relevant in Alpine, where we can package the service files in a subpackage without having systemd in Alpine. Addresses feedback of https://github.com/linux-speakup/espeakup/pull/64, therefore superseeds it. --- services/meson.build | 4 ++-- services/systemd/meson.build | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/services/meson.build b/services/meson.build index 0be40f1..5eadcac 100644 --- a/services/meson.build +++ b/services/meson.build @@ -1,4 +1,4 @@ -systemd = dependency('systemd', required: get_option('systemd')) -if systemd.found() +systemd = dependency('systemd') +if (systemd.found() and get_option('systemd').allowed()) or get_option('systemd').enabled() subdir('systemd') endif diff --git a/services/systemd/meson.build b/services/systemd/meson.build index eccbde7..1a15303 100644 --- a/services/systemd/meson.build +++ b/services/systemd/meson.build @@ -1,4 +1,8 @@ -unitdir = systemd.get_variable(pkgconfig: 'systemdsystemunitdir') +if systemd.found() + unitdir = systemd.get_variable(pkgconfig: 'systemdsystemunitdir') +else + unitdir = join_paths(prefixdir, get_option('libdir'), 'systemd', 'system') +endif prefixdir = get_option('prefix') bindir = join_paths(prefixdir, get_option('bindir')) From f266faaff78b9f71a739ffead91c09ec5f8afc07 Mon Sep 17 00:00:00 2001 From: donovanmalisch23-alt <228235407+donovanmalisch23-alt@users.noreply.github.com> Date: Mon, 3 Aug 2026 11:04:45 +0000 Subject: [PATCH 181/181] espeak: escape XML-special characters in single-character mode When speakup echoes a single character, espeakup wraps it in SSML: %c If the character is one of XML's five special characters (< > & ' "), the raw byte is injected straight into the markup, producing ill-formed SSML. espeak-ng then misparses the element, which surfaces as a spurious high-pitched "ringing" whenever one of these characters is spoken. Escape each special character to its corresponding XML entity (< > & ' ") so the markup stays well-formed. Non-printable characters (< 0x20 or > 0x7e) are no longer wrapped in SSML either; they fall through to the existing raw-synthesis fallback so they cannot corrupt the surrounding element either. The space and ordinary-printable-character paths are unchanged. --- src/espeak.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/src/espeak.c b/src/espeak.c index 60cc996..c9ac908 100644 --- a/src/espeak.c +++ b/src/espeak.c @@ -302,15 +302,39 @@ static espeak_ERROR speak_text(struct synth_t *s) synth_mode |= espeakSSML; if (espeakup_mode == ESPEAKUP_MODE_SPEAKUP && (s->len == 1)) { - char *buf; + char *buf = NULL; int n; - if (s->buf[0] == ' ') + unsigned char c = s->buf[0]; + if (c == ' ') n = asprintf(&buf, " "); - else - n = asprintf(&buf, - "%c", - s->buf[0]); + else if (c < 0x20 || c > 0x7e) { + /* Not a printable character; do not embed it in SSML, as + * that would produce invalid markup. Fall through to the + * raw-synthesis path below. */ + n = -1; + } else { + /* Escape characters that are special in XML/SSML so the + * resulting markup stays well-formed; otherwise espeak-ng + * misparses the element, which is the source of + * the spurious high-pitched "ringing" on these characters. */ + const char *entity = NULL; + switch (c) { + case '<': entity = "<"; break; + case '>': entity = ">"; break; + case '&': entity = "&"; break; + case '\'': entity = "'"; break; + case '"': entity = """; break; + } + if (entity) + n = asprintf(&buf, + "%s", + entity); + else + n = asprintf(&buf, + "%c", + c); + } if (n == -1) { /* D'oh. Not much to do on allocation failure. * Perhaps espeak will happen to say the character */