diff --git a/espeakup.c b/espeakup.c index 5422c37..2f6dd25 100644 --- a/espeakup.c +++ b/espeakup.c @@ -105,6 +105,16 @@ int main(int argc, char **argv) return 1; } + /* open the softsynth. */ + if (! open_softsynth()) { + perror("Unable to open the softsynth device"); + return 3; + } + + /* register signal handler */ + signal(SIGINT, espeakup_sighandler); + signal(SIGTERM, espeakup_sighandler); + if (!debug) { /* become a daemon */ daemon(0, 1); @@ -116,15 +126,6 @@ int main(int argc, char **argv) } } - /* Spawn our queue-processing thread. */ - int err = pthread_create(&queue_thread_id, NULL, &queue_runner, &s); - if (err != 0) { - return 4; - } - - /* open the softsynth. */ - open_softsynth(); - /* initialize espeak */ espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 0, NULL, 0); @@ -140,9 +141,11 @@ int main(int argc, char **argv) set_volume(&s, defaultVolume, ADJ_SET); espeak_SetParameter(espeakCAPITALS, 0, 0); - /* register signal handler */ - signal(SIGINT, espeakup_sighandler); - signal(SIGTERM, espeakup_sighandler); + /* Spawn our queue-processing thread. */ + int err = pthread_create(&queue_thread_id, NULL, &queue_runner, &s); + if (err != 0) { + return 4; + } /* run the main loop */ main_loop(&s); diff --git a/espeakup.h b/espeakup.h index 067a42b..75292c8 100644 --- a/espeakup.h +++ b/espeakup.h @@ -74,7 +74,7 @@ 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 open_softsynth(void); +extern int open_softsynth(void); extern void close_softsynth(void); extern void main_loop(struct synth_t *s); extern void * queue_runner(void *arg); diff --git a/softsynth.c b/softsynth.c index 15801f4..b482ec9 100644 --- a/softsynth.c +++ b/softsynth.c @@ -125,13 +125,16 @@ static void process_buffer(struct synth_t *s, char *buf, ssize_t length) } } -void open_softsynth(void) +int open_softsynth(void) { + int rc; + softFD = open("/dev/softsynth", O_RDWR | O_NONBLOCK); - if (softFD < 0) { - perror("Unable to open the softsynth device"); - exit(3); - } + if (softFD < 0) + rc = 0; + else + rc = 1; + return rc; } void close_softsynth(void)