From 455efe0d2d06e37569631089843e38cadee5cc4a Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Sun, 27 Feb 2022 00:39:55 -0500 Subject: meow, we can now like, set stuff :333 --- src/vox.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) (limited to 'src') diff --git a/src/vox.c b/src/vox.c index bf2968b..bcfab5d 100644 --- a/src/vox.c +++ b/src/vox.c @@ -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); -- cgit v1.2.3