The user_data parameter is just a pointer that is passed into the
espeak_synth call that is passed back to the callback. In native mode,
we are not using it since there is not a callback. However, in alsa
mode, it will be used to indicate when a cancel was processed.
The signal handler stopped working after I moved the initialization
calls to the main function. Creating the signal handler thread first
fixed this issue.
pthread_cond_wait() can have spurious wakeups, so we need to be sure
that the condition is actually true when we return from this function.
Thanks to Chris Brannon for the patch.
The only time queue_process_entry should lock the queue gard is when it
is removing the item from the queue. This happens only when the item
was successfully processed.
1. Don't lock or unlock queue_guard during queue_clear.
It is locked when queue_clear is called, and it should remain so.
2. Protect runner_must_stop with queue_guard in
the request_espeak_stop function.
The following condition should always hold: queue_guard is locked while
testing or modifying runner_must_stop.
3. Rename stop_guard to acknowledge_guard. This is a more
descriptive name. This mutex simply protects the acknowledgement of
the stop request from being lost.
4. Remove the pthread_mutex_lock from the top of queue_process_entry,
because queue_guard is already locked when the function is called.
Most of the idea for this change came from William:
Renamed queue_runner to espeak_thread. Moved espeak initialization
and termination to espeak_thread. The while loops that process
the queue now use the variable should_run.
The goal is to create threads for the reader, que runner/espeak
processing and signal handling.
As of this commit, this code is still being worked on, so it is broken.
This adds retry processing back to the queue functions. queue_remove
should only be called after the head entry on the queue is processed
successfully.
espeak uses a sample rate of 22050 HZ, but let's not rely on that knowledge.
espeak_Initialize returns the sample rate on success,
so rely on that value when selecting a rate.
This commit updates the makefile and the documentation to explain how to
build alsa support. It has not been fully tested, so it is not built by
default. Also, I was able to remove the conditional compile directives
from the source.
The stop_speech function needs to test the return code from
espeak_Cancel() to be sure the operation was successful before
signaling the callback to stop the audio.