23 #include "synth_thread.h" 25 #include <interfaces/SpeechSynthInterface.h> 26 #include <utils/time/wait.h> 27 #include <asoundlib.h> 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);
63 say(
"Speech synth loaded");
70 unregister_cmu_us_kal(__voice);
112 cst_wave *wave = flite_text_to_wave(text, __voice);
113 cst_wave_save_riff(wave,
"/tmp/test.wav");
118 __speechsynth_if->
write();
124 __speechsynth_if->
write();
129 FliteSynthThread::get_duration(cst_wave *wave)
131 return (
float)cst_wave_num_samples(wave) / (float)cst_wave_sample_rate(wave);
139 FliteSynthThread::play_wave(cst_wave *wave)
142 float duration = get_duration(wave);
144 if ((err = snd_pcm_open(&pcm, __cfg_soundcard.c_str(), SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
145 throw Exception(
"Failed to open PCM: %s", snd_strerror(err));
147 snd_pcm_nonblock(pcm, 0);
148 if ((err = snd_pcm_set_params(pcm,
149 SND_PCM_FORMAT_S16_LE,
150 SND_PCM_ACCESS_RW_INTERLEAVED,
151 cst_wave_num_channels(wave),
152 cst_wave_sample_rate(wave),
154 (
unsigned int)roundf(duration * 1000000.))) < 0) {
155 throw Exception(
"Playback to set params: %s", snd_strerror(err));
158 snd_pcm_sframes_t frames;
159 frames = snd_pcm_writei(pcm, cst_wave_samples(wave), cst_wave_num_samples(wave));
162 frames = snd_pcm_recover(pcm, frames, 0);
166 }
else if ( frames < (
long)cst_wave_num_samples(wave)) {
168 (
long)cst_wave_num_samples(wave), frames);
171 TimeWait::wait_systime((
unsigned int)roundf(duration * 1000000.f));
void set_duration(const float new_duration)
Set duration value.
Base class for all messages passed through interfaces in Fawkes BlackBoard.
unsigned int id() const
Get message ID.
void set_final(const bool new_final)
Set final value.
bool msgq_empty()
Check if queue is empty.
virtual bool bb_interface_message_received(fawkes::Interface *interface, fawkes::Message *message)
BlackBoard message received notification.
Fawkes library namespace.
virtual void init()
Initialize the thread.
FliteSynthThread()
Constructor.
SayMessage Fawkes BlackBoard Interface Message.
virtual void unregister_listener(BlackBoardInterfaceListener *listener)
Unregister BB interface listener.
Thread class encapsulation of pthreads.
void write()
Write from local copy into BlackBoard memory.
Base class for all Fawkes BlackBoard interfaces.
Logger * logger
This is the Logger member used to access the logger.
void set_msgid(const uint32_t new_msgid)
Set msgid value.
virtual void register_listener(BlackBoardInterfaceListener *listener, ListenerRegisterFlag flag=BBIL_FLAG_ALL)
Register BB event listener.
void msgq_pop()
Erase first message from queue.
void wakeup()
Wake up thread.
Base class for exceptions in Fawkes.
void set_text(const char *new_text)
Set text value.
Message * msgq_first()
Get the first message from the message queue.
virtual void finalize()
Finalize the thread.
const char * name() const
Get name of thread.
bool msgq_first_is()
Check if first message has desired type.
virtual void log_warn(const char *component, const char *format,...)=0
Log warning message.
void say(const char *text)
Say something.
char * text() const
Get text value.
virtual void loop()
Code to execute in the thread.
Configuration * config
This is the Configuration member used to access the configuration.
void bbil_add_message_interface(Interface *interface)
Add an interface to the message received watch list.
virtual Interface * open_for_writing(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for writing.
virtual std::string get_string(const char *path)=0
Get value from configuration which is of type string.
BlackBoard interface listener.
SpeechSynthInterface Fawkes BlackBoard Interface.
BlackBoard * blackboard
This is the BlackBoard instance you can use to interact with the BlackBoard.
virtual void close(Interface *interface)=0
Close interface.