summaryrefslogtreecommitdiff
path: root/aoview
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2009-07-11 00:56:13 -0700
committerKeith Packard <keithp@keithp.com>2009-07-11 00:56:13 -0700
commitfef7334bddb9fccfbd6deab7d5d466ab3e76323a (patch)
treea418845f11ae8004f463cfde8202f43ef6692cc3 /aoview
parent80cadf44f5f1accd6ddfca25c2af8d4d424f26d9 (diff)
Hook aoview directly to alsa
This skips the flite internal audio stuff which opened and closed the audio device for each phrase. This caused the first part of some phrases to be missed when using an external audio device. Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'aoview')
-rw-r--r--aoview/Makefile.am4
-rw-r--r--aoview/aoview_flite.c49
-rw-r--r--aoview/aoview_voice.c2
3 files changed, 51 insertions, 4 deletions
diff --git a/aoview/Makefile.am b/aoview/Makefile.am
index c354aa0f..00851b67 100644
--- a/aoview/Makefile.am
+++ b/aoview/Makefile.am
@@ -1,9 +1,9 @@
VERSION=$(shell git describe)
-AM_CFLAGS=$(GNOME_CFLAGS) -I$(top_srcdir)/src -DAOVIEW_VERSION=\"$(VERSION)\" @FLITE_INCS@
+AM_CFLAGS=$(GNOME_CFLAGS) $(ALSA_CFLAGS) -I$(top_srcdir)/src -DAOVIEW_VERSION=\"$(VERSION)\" @FLITE_INCS@
bin_PROGRAMS=aoview
-aoview_LDADD=$(GNOME_LIBS) $(FLITE_LIBS)
+aoview_LDADD=$(GNOME_LIBS) $(FLITE_LIBS) $(ALSA_LIBS)
aoview_SOURCES = \
aoview_main.c \
diff --git a/aoview/aoview_flite.c b/aoview/aoview_flite.c
index bca19043..2673824d 100644
--- a/aoview/aoview_flite.c
+++ b/aoview/aoview_flite.c
@@ -18,6 +18,7 @@
#include <stdio.h>
#include <flite/flite.h>
#include "aoview.h"
+#include <alsa/asoundlib.h>
cst_voice *register_cmu_us_kal();
static cst_voice *voice;
@@ -25,14 +26,58 @@ static cst_voice *voice;
static FILE *pipe_write;
static GThread *aoview_flite_thread;
+static snd_pcm_t *alsa_handle;
+
gpointer
aoview_flite_task(gpointer data)
{
FILE *input = data;
char line[1024];
+ cst_wave *wave;
+ int rate;
+ int channels;
+ int err;
- while (fgets(line, sizeof (line) - 1, input) != NULL)
- flite_text_to_speech(line, voice, "play");
+ err = snd_pcm_open(&alsa_handle, "default",
+ SND_PCM_STREAM_PLAYBACK, 0);
+ if (err >= 0)
+ {
+ if (err < 0) {
+ snd_pcm_close(alsa_handle);
+ alsa_handle = 0;
+ }
+ }
+ rate = 0;
+ channels = 0;
+ while (fgets(line, sizeof (line) - 1, input) != NULL) {
+ if (!alsa_handle)
+ continue;
+ wave = flite_text_to_wave(line, voice);
+ if (wave->sample_rate != rate ||
+ wave->num_channels != channels)
+ {
+ rate = wave->sample_rate;
+ channels = wave->num_channels;
+ snd_pcm_set_params(alsa_handle,
+ SND_PCM_FORMAT_S16,
+ SND_PCM_ACCESS_RW_INTERLEAVED,
+ channels,
+ rate,
+ 1,
+ 100000);
+ }
+ snd_pcm_prepare(alsa_handle);
+ err = snd_pcm_writei(alsa_handle,
+ wave->samples,
+ wave->num_samples);
+ if (err < 0)
+ fprintf(stderr, "alsa write error %s\n",
+ strerror(-err));
+ snd_pcm_drain(alsa_handle);
+ delete_wave(wave);
+ }
+ snd_pcm_close(alsa_handle);
+ alsa_handle = 0;
return NULL;
}
diff --git a/aoview/aoview_voice.c b/aoview/aoview_voice.c
index f7c099b1..24422df6 100644
--- a/aoview/aoview_voice.c
+++ b/aoview/aoview_voice.c
@@ -24,6 +24,8 @@ FILE *aoview_flite;
void aoview_voice_open(void)
{
+ int err;
+
if (!aoview_flite)
aoview_flite = aoview_flite_start();
}