src/festival_interface.c
author Markus Bröker <mbroeker@largo.dyndns.tv>
Tue, 02 Feb 2010 13:41:48 +0100
changeset 3 a80adbcf4882
parent 0 06dd3b8d90ad
permissions -rw-r--r--
Default txt2pho file committer: Markus Bröker <mbroeker@largo.homelinux.org>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     1
/**
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     2
 *  $Id: festival_interface.c 53 2008-01-10 00:19:41Z mbroeker $
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     3
 * $URL: http://localhost/svn/c/VirtualReader/trunk/src/festival_interface.c $
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     4
 */
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     5
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     6
#ifdef FESTIVAL
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     7
#include <festival_interface.h>
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     8
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     9
ttshandles interface_init (tts_options t_options)
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    10
{
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    11
    ttshandles handle;
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    12
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    13
    return handle;
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    14
}
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    15
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    16
long *interface_get_timing (ttshandles tts, char *text)
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    17
{
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    18
    int i;
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    19
    long *t = NULL;
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    20
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    21
    for (i = 0; i < strlen (text); i++) {
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    22
        t = realloc (t, (i + 2) * sizeof (long));
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    23
        t[i] = i * 20 + 10;
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    24
    }
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    25
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    26
    t[i] = 0;
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    27
    return t;
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    28
};
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    29
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    30
int interface_write_to_wav (char *fname, char *text, ttshandles t_handles, tts_options t_options)
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    31
{
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    32
    char *s = NULL;
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    33
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    34
    if ((s = malloc (strlen (text) + 80)) == NULL)
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    35
        return -1;
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    36
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    37
    sprintf (s, "printf \"%s\" | bin/festival_write_wav - %s", text, fname);
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    38
#ifdef DEBUG
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    39
    printf ("Writing %s\n", fname);
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    40
#endif
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    41
    system (s);
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    42
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    43
    if (s != NULL)
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    44
        free (s);
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    45
    return 0;
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    46
}
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    47
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    48
tts_options interface_get_cl_opts (int num, char **arguments)
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    49
{
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    50
    tts_options options = { 0, 0, 0, 0 };
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    51
    int c;
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    52
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    53
    while ((c = getopt (num, arguments, "p:v:i:")) > 0) {
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    54
        switch (c) {
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    55
        case 'p':
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    56
            options.Path = optarg;
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    57
            break;
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    58
        case 'v':
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    59
            options.Voice = optarg;
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    60
            break;
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    61
        case 'i':
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    62
            options.TextFile = optarg;
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    63
            break;
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    64
        }
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    65
    }
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    66
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    67
    if (options.TextFile == NULL) {
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    68
        fprintf (stderr, "It's substantial to give a text file by -i <text file>!\n");
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    69
        exit (0);
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    70
    }
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    71
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    72
    return options;
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    73
}
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    74
06dd3b8d90ad Virtual Reader
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    75
#endif