diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/vox.c | 90 |
1 files changed, 90 insertions, 0 deletions
@@ -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); |