speechd-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 6/7] replace spd_audio_play with module_tts_output callback


From: Andrei Kholodnyi
Subject: [PATCH 6/7] replace spd_audio_play with module_tts_output callback
Date: Sun, 28 Nov 2010 19:51:27 +0100

we return now produced by TTS engine speech output to the main
by calling callback and let it decide what to do
at the moment it calls spd_audio_play
---
 src/modules/espeak.c       |    2 +-
 src/modules/festival.c     |   28 ++++++++++++++--------------
 src/modules/flite.c        |   18 +++++++-----------
 src/modules/ibmtts.c       |   28 ++++++++++++++++++----------
 src/modules/ivona.c        |    2 +-
 src/modules/module_utils.c |   11 +++++++++++
 src/modules/module_utils.h |    1 +
 src/modules/pico.c         |    8 ++++++--
 8 files changed, 59 insertions(+), 39 deletions(-)

diff --git a/src/modules/espeak.c b/src/modules/espeak.c
index 6c62fb8..781d5af 100644
--- a/src/modules/espeak.c
+++ b/src/modules/espeak.c
@@ -990,7 +990,7 @@ espeak_send_to_audio(TPlaybackQueueEntry 
*playback_queue_entry)
        track.samples = playback_queue_entry->data.audio.audio_chunk;
 
        DBG("Espeak: Sending %i samples to audio.", track.num_samples);
-       ret = spd_audio_play(module_audio_id, track, SPD_AUDIO_LE);
+       ret = module_tts_output(track, SPD_AUDIO_LE);
        if (ret < 0) {
                DBG("ERROR: Can't play track for unknown reason.");
                return FALSE;
diff --git a/src/modules/festival.c b/src/modules/festival.c
index 7651200..fce2050 100644
--- a/src/modules/festival.c
+++ b/src/modules/festival.c
@@ -554,27 +554,27 @@ int
 festival_send_to_audio(FT_Wave *fwave)
 {
     AudioTrack track;
+#if defined(BYTE_ORDER) && (BYTE_ORDER == BIG_ENDIAN)
+    AudioFormat format = SPD_AUDIO_BE;
+#else
+    AudioFormat format = SPD_AUDIO_LE;
+#endif
     int ret = 0;
-    
+
+    if (fwave->samples == NULL)
+       return 0;
+
     track.num_samples = fwave->num_samples;
     track.num_channels = 1;
     track.sample_rate = fwave->sample_rate;
     track.bits = 16;
     track.samples = fwave->samples;
     
-    if (track.samples != NULL){
-       DBG("Sending to audio");
-               switch (module_audio_id->format){
-                       case SPD_AUDIO_LE:
-                               ret = spd_audio_play(module_audio_id, track, 
SPD_AUDIO_LE);
-                               break;
-                       case SPD_AUDIO_BE:
-                               ret = spd_audio_play(module_audio_id, track, 
SPD_AUDIO_BE);
-                               break;
-               }
-       if (ret < 0) DBG("ERROR: Can't play track for unknown reason.");
-       DBG("Sent to audio.");
-    }
+    DBG("Sending to audio");
+
+    ret = module_tts_output(track, format);
+    if (ret < 0) DBG("ERROR: Can't play track for unknown reason.");
+    DBG("Sent to audio.");
 
     return 0;
 }
diff --git a/src/modules/flite.c b/src/modules/flite.c
index 23fdd25..236f366 100644
--- a/src/modules/flite.c
+++ b/src/modules/flite.c
@@ -254,6 +254,11 @@ void*
 _flite_speak(void* nothing)
 {      
     AudioTrack track;
+#if defined(BYTE_ORDER) && (BYTE_ORDER == BIG_ENDIAN)
+    AudioFormat format = SPD_AUDIO_BE;
+#else
+    AudioFormat format = SPD_AUDIO_LE;
+#endif
     cst_wave *wav;
     unsigned int pos;
     char *buf;
@@ -333,17 +338,8 @@ _flite_speak(void* nothing)
                        break;
                    }
                    DBG("Playing part of the message");
-                   switch (module_audio_id->format){
-                       case SPD_AUDIO_LE:
-                           ret = spd_audio_play(module_audio_id, track, 
SPD_AUDIO_LE);
-                           break;
-                       case SPD_AUDIO_BE:
-                           ret = spd_audio_play(module_audio_id, track, 
SPD_AUDIO_BE);
-                           break;
-                        default:
-                            FATAL("unknown audio format");
-                   }
-                   if (ret < 0) DBG("ERROR: spd_audio failed to play the 
track");
+                   ret = module_tts_output(track, format);
+                   if (ret < 0) DBG("ERROR: failed to play the track");
                    if (flite_stop){
                        DBG("Stop in child, terminating (s)");
                        flite_speaking = 0;
diff --git a/src/modules/ibmtts.c b/src/modules/ibmtts.c
index 6678589..1885bf4 100644
--- a/src/modules/ibmtts.c
+++ b/src/modules/ibmtts.c
@@ -31,7 +31,7 @@
             This thread receives audio and index mark callbacks from
             IBM TTS and queues them into a playback queue. See _ibmtts_synth().
         A playback thread that acts on entries in the playback queue,
-            either sending them to the audio output module (spd_audio_play()),
+            either sending them to the audio output module 
(module_tts_output()),
             or emitting Speech Dispatcher events.  See _ibmtts_play().
         A thread which is used to stop or pause the synthesis and
             playback threads.  See _ibmtts_stop_or_pause().
@@ -1376,22 +1376,30 @@ static TIbmttsBool
 ibmtts_send_to_audio(TPlaybackQueueEntry *playback_queue_entry)
 {
     AudioTrack track;
+#if defined(BYTE_ORDER) && (BYTE_ORDER == BIG_ENDIAN)
+    AudioFormat format = SPD_AUDIO_BE;
+#else
+    AudioFormat format = SPD_AUDIO_LE;
+#endif
+    int ret;
+
+    if (track.samples == NULL)
+        return IBMTTS_TRUE;
+
     track.num_samples = playback_queue_entry->data.audio.num_samples;
     track.num_channels = 1;
     track.sample_rate = eci_sample_rate;
     track.bits = 16;
     track.samples = playback_queue_entry->data.audio.audio_chunk;
 
-    if (track.samples != NULL){
-        DBG("Ibmtts: Sending %i samples to audio.", track.num_samples);
-        int ret = spd_audio_play(module_audio_id, track, SPD_AUDIO_LE);
-        if (ret < 0) {
-            DBG("ERROR: Can't play track for unknown reason.");
-            return IBMTTS_FALSE;
-        }
-        DBG("Ibmtts: Sent to audio.");
-    }
 
+    DBG("Ibmtts: Sending %i samples to audio.", track.num_samples);
+    ret = module_tts_output(track, format);
+    if (ret < 0) {
+        DBG("ERROR: Can't play track for unknown reason.");
+        return IBMTTS_FALSE;
+    }
+    DBG("Ibmtts: Sent to audio.");
     return IBMTTS_TRUE;
 }
 
diff --git a/src/modules/ivona.c b/src/modules/ivona.c
index 44aee43..39a4256 100644
--- a/src/modules/ivona.c
+++ b/src/modules/ivona.c
@@ -527,7 +527,7 @@ _ivona_speak(void* nothing)
                track.bits = 16;
                track.samples = ((short *)audio)+offset;
                DBG("Got %d samples", track.num_samples);
-               spd_audio_play(module_audio_id, track, SPD_AUDIO_LE);
+                module_tts_output(track, SPD_AUDIO_LE);
                g_free(audio);
                audio=NULL;
            }
diff --git a/src/modules/module_utils.c b/src/modules/module_utils.c
index c6522c5..a6eb002 100644
--- a/src/modules/module_utils.c
+++ b/src/modules/module_utils.c
@@ -1079,3 +1079,14 @@ module_audio_init(char **status_info)
     return -1;
 
 }
+
+int
+module_tts_output(AudioTrack track, AudioFormat format)
+{
+
+    if (spd_audio_play(module_audio_id, track, format) < 0) {
+        DBG("Can't play track for unknown reason.");
+       return -1;
+    }
+    return 0;
+}
diff --git a/src/modules/module_utils.h b/src/modules/module_utils.h
index c790a4a..4409627 100644
--- a/src/modules/module_utils.h
+++ b/src/modules/module_utils.h
@@ -127,6 +127,7 @@ SPDVoice** module_list_voices(void);
 int     module_speak        (char *data, size_t bytes, SPDMessageType msgtype);
 int     module_stop         (void);
 SPDVoice**     module_get_voices   (void);
+int     module_tts_output   (AudioTrack track, AudioFormat format);
 size_t  module_pause        (void);
 char*     module_is_speaking  (void);
 int    module_close        (void);
diff --git a/src/modules/pico.c b/src/modules/pico.c
index 983e001..5cb9b5a 100644
--- a/src/modules/pico.c
+++ b/src/modules/pico.c
@@ -167,6 +167,11 @@ static int pico_process_tts(void)
        short outbuf[MAX_OUTBUF_SIZE];
        pico_Retstring outMessage;
        AudioTrack track;
+#if defined(BYTE_ORDER) && (BYTE_ORDER == BIG_ENDIAN)
+       AudioFormat format = SPD_AUDIO_BE;
+#else
+       AudioFormat format = SPD_AUDIO_LE;
+#endif
        pico_Char *buf = picoInp;
 
        text_remaining = strlen((const char *) buf) + 1;
@@ -210,8 +215,7 @@ static int pico_process_tts(void)
                                DBG(MODULE_NAME
                                        ": Sending %i samples to audio.", 
track.num_samples);
 
-                               if (spd_audio_play(module_audio_id, track,
-                                                      module_audio_id->format) 
< 0) {
+                               if (module_tts_output(track, format) < 0) {
                                        DBG(MODULE_NAME
                                                "Can't play track for unknown 
reason.");
                                        return -1;
-- 
1.6.0.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]