~alcinnz/rhapsode

4298dd3cb00bc6a641bb32cad897e31b1b3564c5 — Adrian Cochrane 3 years ago 42f1157
Draft SpeechD integration.
1 files changed, 35 insertions(+), 1 deletions(-)

M src/main.c
M src/main.c => src/main.c +35 -1
@@ 9,6 9,12 @@
#include <espeak-ng/espeak_ng.h>
#include <sndfile.h>

// #define WITH_SPEECHD // FIXME Doesn't support audio cues, navigation, or even read the full page.
#ifdef WITH_SPEECHD
#include <speechd_types.h>
#include <libspeechd.h>
#endif

/* Exported Haskell functions/types */
struct session;
struct session *c_newSession();


@@ 226,10 232,17 @@ int main(int argc, char **argv) {
    FILE *fd_links = NULL;
    int use_espeak = 0;
    tcgetattr(0, &stored_settings);
    #ifdef WITH_SPEECHD
    SPDConnection *spd_conn = NULL;
    #endif

    int c;
    opterr = 0;
    #ifdef WITH_SPEECHD
    while ((c = getopt(argc, argv, "xs::l::kw::dh")) != -1) {
    #else
    while ((c = getopt(argc, argv, "xs::l::kw::h")) != -1) {
    #endif
        switch (c) {
        case 'x':
            mimes = "text/xml application/xml application/xhtml+xml text/html text/plain";


@@ 254,6 267,13 @@ int main(int argc, char **argv) {
            use_espeak = 1;
            path_wav = optarg;
            break;
        #ifdef WITH_SPEECHD
        case 'd':
            spd_conn = spd_open("rhapsode", "main", NULL, SPD_MODE_SINGLE);
            if (spd_conn == NULL) fprintf(stderr, "Failed to open SpeechD connection, ignoring\n");
            spd_set_data_mode(spd_conn, SPD_DATA_SSML);
            break;
        #endif
        case '?':
            fprintf(stderr, "Invalid flag %c\n\n", optopt);
        case 'h':


@@ 270,7 290,12 @@ int main(int argc, char **argv) {
        }
    }
    if (fd_ssml == stdout && fd_links == stdout) fd_links = stderr;
    if (fd_ssml == NULL && fd_links == NULL && !use_espeak) use_espeak = 1;
    #ifdef WITH_SPEECHD
    if (fd_ssml == NULL && fd_links == NULL && spd_conn == NULL && !use_espeak)
    #else
    if (fd_ssml == NULL && fd_links == NULL && !use_espeak)
    #endif
        use_espeak = 1;

    struct session *session = c_newSession();
    struct page *referer = c_initialReferer();


@@ 279,6 304,9 @@ int main(int argc, char **argv) {
    char *ssml;
    for (int i = optind; i < argc; i++) {
        if (use_espeak && speak_err == 0) speak(argv[i], NULL);
        #ifdef WITH_SPEECHD
        else if (spd_conn != NULL) spd_say(spd_conn, SPD_MESSAGE, argv[i]);
        #endif
        else printf("%s\n", argv[i]);

        struct page *page = c_fetchURL(session, mimes, referer, argv[i]);


@@ 288,10 316,16 @@ int main(int argc, char **argv) {
        if (fd_ssml != NULL) fprintf(fd_ssml, "%s\n", ssml);
        if (fd_links != NULL) write_links(fd_links, links);
        if (use_espeak & speak_err == 0) speak(ssml, "main");
        #ifdef WITH_SPEECHD
        if (spd_conn != NULL) spd_say(spd_conn, SPD_MESSAGE, ssml);
        #endif

        c_freePage(page);
    }
    if (use_espeak & speak_err == 0) speak_err = speak_finalize(ssml);
    #ifdef WITH_SPEECHD
    if (spd_conn != NULL) spd_close(spd_conn);
    #endif

    c_freePage(referer);
    c_freeSession(session);