diff options
-rw-r--r-- | include/xas/vox.h | 5 | ||||
-rw-r--r-- | src/vox.c | 67 |
2 files changed, 58 insertions, 14 deletions
diff --git a/include/xas/vox.h b/include/xas/vox.h index fd442a8..917eda1 100644 --- a/include/xas/vox.h +++ b/include/xas/vox.h @@ -11,13 +11,16 @@ #define XAS_VOX_ACTIVE (1 << 0) typedef struct _xas_vox { - const char *text2wave_path; xas_audio_format format; size_t buffer_size; int flags; + const char *text2wave_path; + int argn; + char **args; + int pid, stdin, @@ -46,6 +46,35 @@ error_waitpid: return -1; } +static char **args_concat(int argn1, char **args1, + int argn2, char **args2, + int *total) { + char **ret; + + int count = argn1 + argn2, + i, o; + + if ((ret = malloc((count + 1) * sizeof(char *))) == NULL) { + goto error_malloc; + } + + for (i=0, o=0; i<argn1; i++, o++) { + ret[o] = args1[i]; + } + + for (i=0; i<argn2; i++, o++) { + ret[o] = args2[i]; + } + + *total = count; + ret[o] = NULL; + + return ret; + +error_malloc: + return NULL; +} + static int vox_start(xas_vox *vox) { int pipe_stdin[2], pipe_stdout[2]; @@ -54,18 +83,6 @@ static int vox_start(xas_vox *vox) { char sample_rate[40]; - char *args[] = { - (char *)vox->text2wave_path, - "-F", - sample_rate, - "-", - "-o", - "-", - NULL - }; - - snprintf(sample_rate, sizeof(sample_rate)-1, "%zu", vox->format.sample_rate); - if (vox->flags & XAS_VOX_ACTIVE) { (void)vox_stop(vox); } @@ -83,8 +100,27 @@ static int vox_start(xas_vox *vox) { } if (pid == 0) { + char *args[] = { + (char *)vox->text2wave_path, + "-F", + sample_rate, + "-", + "-o", + "-", + NULL + }; + + int argc; + char **argv; + int fd; + snprintf(sample_rate, sizeof(sample_rate)-1, "%zu", vox->format.sample_rate); + + if ((argv = args_concat(6, args, vox->argn, vox->args, &argc)) == NULL) { + goto error_child; + } + if ((fd = open("/dev/null", O_WRONLY)) < 0) { goto error_child; } @@ -104,7 +140,7 @@ static int vox_start(xas_vox *vox) { goto error_child; } - if (execv(vox->text2wave_path, args) < 0) { + if (execv(vox->text2wave_path, argv) < 0) { goto error_child; } @@ -194,6 +230,11 @@ xas_vox *xas_vox_new(const char *text2wave_path, vox->stdout = -1; vox->in = NULL; + vox->argn = 0; + vox->args = NULL; + + memset(vox->tmpfile, '\0', sizeof(vox->tmpfile)); + return vox; error_malloc_vox: |