diff options
author | XANTRONIX Development | 2022-02-27 00:39:55 -0500 |
---|---|---|
committer | XANTRONIX Development | 2022-02-27 00:39:55 -0500 |
commit | 455efe0d2d06e37569631089843e38cadee5cc4a (patch) | |
tree | 683f4a96eeac69d06db0c6ffb0191a7b985a9edc | |
parent | 8c5121eb5f8fd415fb1d0ca61fd7aff9ab084565 (diff) | |
download | xas-455efe0d2d06e37569631089843e38cadee5cc4a.tar.gz xas-455efe0d2d06e37569631089843e38cadee5cc4a.tar.bz2 xas-455efe0d2d06e37569631089843e38cadee5cc4a.zip |
meow, we can now like, set stuff :333
-rw-r--r-- | include/xas/vox.h | 13 | ||||
-rw-r--r-- | src/vox.c | 90 |
2 files changed, 101 insertions, 2 deletions
diff --git a/include/xas/vox.h b/include/xas/vox.h index c3bae65..7aa43e4 100644 --- a/include/xas/vox.h +++ b/include/xas/vox.h @@ -7,7 +7,8 @@ #include <xas/audio.h> -#define XAS_VOX_SETTINGS_PATHLEN 64 +#define XAS_VOX_SETTINGS_TMP_PATH "/tmp/xas-vox.XXXXXX" +#define XAS_VOX_SETTINGS_TMP_PATHLEN 64 enum xas_vox_state { XAS_VOX_IDLE, @@ -28,7 +29,9 @@ typedef struct _xas_vox { stdin, stdout; - char tmpfile[XAS_VOX_SETTINGS_PATHLEN]; + char tmpfile[XAS_VOX_SETTINGS_TMP_PATHLEN]; + int tmpfd; + FILE *tmpfh; FILE *in; } xas_vox; @@ -45,6 +48,12 @@ xas_vox *xas_vox_new(xas_audio_format format, void xas_vox_destroy(xas_vox *vox); +int xas_vox_set_voice(xas_vox *vox, const char *voice); + +int xas_vox_set_parameter(xas_vox *vox, + const char *name, + const char *value); + int xas_vox_stop(xas_vox *vox); int xas_vox_active(xas_vox *vox); @@ -208,6 +208,45 @@ error_read: return -1; } +static int tmpfile_open(xas_vox *vox) { + if (vox->tmpfile[0] && vox->tmpfd > 0) { + return 0; + } + + memset(vox->tmpfile, '\0', sizeof(vox->tmpfile)); + + memcpy(vox->tmpfile, + XAS_VOX_SETTINGS_TMP_PATH, + strlen(XAS_VOX_SETTINGS_TMP_PATH)); + + if ((vox->tmpfd = mkstemp(vox->tmpfile)) < 0) { + goto error_mkstemp; + } + + if ((vox->tmpfh = fdopen(vox->tmpfd, "w")) == NULL) { + goto error_fdopen; + } + + return 0; + +error_fdopen: + close(vox->tmpfd); + unlink(vox->tmpfile); + +error_mkstemp: + return -1; +} + +static void tmpfile_close(xas_vox *vox) { + fclose(vox->tmpfh); + (void)close(vox->tmpfd); + unlink(vox->tmpfile); + + memset(vox->tmpfile, '\0', sizeof(vox->tmpfile)); + vox->tmpfd = -1; + vox->tmpfh = NULL; +} + xas_vox *xas_vox_new_args(xas_audio_format format, size_t buffer_size, const char *text2wave_path, @@ -236,6 +275,7 @@ xas_vox *xas_vox_new_args(xas_audio_format format, vox->args = args; memset(vox->tmpfile, '\0', sizeof(vox->tmpfile)); + vox->tmpfd = -1; return vox; @@ -243,10 +283,60 @@ error_malloc_vox: return NULL; } +xas_vox *xas_vox_new(xas_audio_format format, + size_t buffer_size, + const char *text2wave_path) { + return xas_vox_new_args(format, + buffer_size, + text2wave_path, + 0, + NULL); +} + void xas_vox_destroy(xas_vox *vox) { + if (vox->tmpfile[0] && vox->tmpfd > 0) { + tmpfile_close(vox); + } + free(vox); } +int xas_vox_set_voice(xas_vox *vox, const char *voice) { + if (tmpfile_open(vox) < 0) { + goto error_tmpfile_open; + } + + if (fprintf(vox->tmpfh, "(%s)\n", voice) < 0) { + goto error_fprintf; + } + + return 0; + +error_fprintf: +error_tmpfile_open: + return -1; +} + +int xas_vox_set_parameter(xas_vox *vox, + const char *name, + const char *value) { + if (tmpfile_open(vox) < 0) { + goto error_tmpfile_open; + } + + if (fprintf(vox->tmpfh, "(Parameter.set '%s %s)\n", + name, + value) < 0) { + goto error_fprintf; + } + + return 0; + +error_fprintf: +error_tmpfile_open: + return -1; +} + int xas_vox_stop(xas_vox *vox) { if (vox->state == XAS_VOX_ACTIVE) { return vox_stop(vox); |