23 #include "synth_thread.h"
25 #include <interfaces/SpeechSynthInterface.h>
26 #include <utils/time/wait.h>
27 #include <asoundlib.h>
30 using namespace fawkes;
33 extern cst_voice *register_cmu_us_kal(
const char *voxdir);
34 extern void unregister_cmu_us_kal(cst_voice *voice);
46 :
Thread(
"FliteSynthThread",
Thread::OPMODE_WAITFORWAKEUP),
56 __voice = register_cmu_us_kal(NULL);
61 say(
"Speech synth loaded");
68 unregister_cmu_us_kal(__voice);
110 cst_wave *wave = flite_text_to_wave(text, __voice);
111 cst_wave_save_riff(wave,
"/tmp/test.wav");
116 __speechsynth_if->
write();
122 __speechsynth_if->
write();
127 FliteSynthThread::get_duration(cst_wave *wave)
129 return (
float)cst_wave_num_samples(wave) / (float)cst_wave_sample_rate(wave);
137 FliteSynthThread::play_wave(cst_wave *wave)
140 float duration = get_duration(wave);
142 if ((err = snd_pcm_open(&pcm,
"default", SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
143 throw Exception(
"Failed to open PCM: %s", snd_strerror(err));
145 snd_pcm_nonblock(pcm, 0);
146 if ((err = snd_pcm_set_params(pcm,
147 SND_PCM_FORMAT_S16_LE,
148 SND_PCM_ACCESS_RW_INTERLEAVED,
149 cst_wave_num_channels(wave),
150 cst_wave_sample_rate(wave),
152 (
unsigned int)roundf(duration * 1000000.))) < 0) {
153 throw Exception(
"Playback to set params: %s", snd_strerror(err));
156 snd_pcm_sframes_t frames;
157 frames = snd_pcm_writei(pcm, cst_wave_samples(wave), cst_wave_num_samples(wave));
160 frames = snd_pcm_recover(pcm, frames, 0);
164 }
else if ( frames < (
long)cst_wave_num_samples(wave)) {
166 (
long)cst_wave_num_samples(wave), frames);
169 TimeWait::wait_systime((
unsigned int)roundf(duration * 1000000.f));