From a048f5848e6d57098d4524cb8b97853ef8329854 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Tue, 1 Feb 2022 15:39:16 -0500 Subject: hmm...getting more refined here --- include/xas/vox.h | 34 +++++++++++++++++------- src/vox.c | 79 ++++++++++++++++++++++++++----------------------------- 2 files changed, 62 insertions(+), 51 deletions(-) diff --git a/include/xas/vox.h b/include/xas/vox.h index 6b73ae9..179d5d1 100644 --- a/include/xas/vox.h +++ b/include/xas/vox.h @@ -1,18 +1,20 @@ #ifndef _XAS_VOX_H #define _XAS_VOX_H +#include #include #include -#define XAS_VOX_VOICE_IDLE 0 -#define XAS_VOX_VOICE_ACTIVE (1 << 0) +#define XAS_VOX_IDLE 0 +#define XAS_VOX_ACTIVE (1 << 0) -typedef struct _xas_vox_voice { +typedef struct _xas_vox { const char *text2wave_path; size_t sample_size, - sample_rate; + sample_rate, + buffer_size; void *ctx; @@ -20,12 +22,24 @@ typedef struct _xas_vox_voice { int pid, stdout; -} xas_vox_voice; +} xas_vox; -xas_audio_stream *xas_vox_new(const char *text2wave_path, - size_t sample_size, - size_t sample_rate, - size_t buffer_size, - void *ctx); +xas_vox *xas_vox_new(const char *text2wave_path, + size_t sample_size, + size_t sample_rate, + size_t buffer_size, + void *ctx); + +void xas_vox_destroy(xas_vox *vox); + +int xas_vox_stop(xas_vox *vox); + +int xas_vox_vsayf(xas_vox *vox, const char *message, va_list args); + +int xas_vox_sayf(xas_vox *vox, const char *message, ...); + +int xas_vox_say(xas_vox *vox, const char *message); + +xas_audio_stream *xas_vox_stream_new(xas_vox *vox); #endif /* _XAS_VOX_H */ diff --git a/src/vox.c b/src/vox.c index 502d79b..047200a 100644 --- a/src/vox.c +++ b/src/vox.c @@ -4,24 +4,24 @@ #include -static void voice_cleanup(xas_vox_voice *voice, xas_audio_stream *stream) { +static void vox_cleanup(xas_vox *vox, xas_audio_stream *stream) { int status; - if (voice->flags & XAS_VOX_VOICE_ACTIVE) { - if (voice->pid >= 0) { - (void)waitpid(voice->pid, &status, 0); + if (vox->flags & XAS_VOX_ACTIVE) { + if (vox->pid >= 0) { + (void)waitpid(vox->pid, &status, 0); } - if (voice->stdout >= 0) { - (void)close(voice->stdout); + if (vox->stdout >= 0) { + (void)close(vox->stdout); } } } -static ssize_t voice_fill(xas_vox_voice *voice, - int16_t *samples, - size_t count, - xas_audio_stream *stream) { +static ssize_t vox_fill(xas_vox *vox, + int16_t *samples, + size_t count, + xas_audio_stream *stream) { size_t i; for (i=0; itext2wave_path = text2wave_path; - voice->sample_size = sample_size; - voice->sample_rate = sample_rate; - voice->ctx = ctx; - voice->flags = XAS_VOX_VOICE_IDLE; + vox->text2wave_path = text2wave_path; + vox->sample_size = sample_size; + vox->sample_rate = sample_rate; + vox->buffer_size = buffer_size; + vox->ctx = ctx; + vox->flags = XAS_VOX_IDLE; - voice->pid = -1; - voice->stdout = -1; + vox->pid = -1; + vox->stdout = -1; - if ((stream = xas_audio_stream_new_source((xas_audio_fill)voice_fill, - (xas_audio_cleanup)voice_cleanup, - voice, - sample_size, - sample_rate, - XAS_AUDIO_STREAM_MONO, - buffer_size)) == NULL) { - goto error_audio_stream_new_source; - } - - return stream; - -error_audio_stream_new_source: - free(voice); + return vox; -error_malloc_voice: +error_malloc_vox: return NULL; } + +xas_audio_stream *xas_vox_stream_new(xas_vox *vox) { + return xas_audio_stream_new_source((xas_audio_fill)vox_fill, + (xas_audio_cleanup)vox_cleanup, + vox, + vox->sample_size, + vox->sample_rate, + XAS_AUDIO_STREAM_MONO, + vox->buffer_size); +} -- cgit v1.2.3