#include <ArSoundsQueue.h>
Inheritance diagram for ArSoundsQueue:
The actual playback of sound and speech is done through callbacks (which you can supply in the constructor or afterwards). Some callbacks you can use are provided by classes like ArSoundPlayer (for sound file playback) and ArFestival (from the ArSpeechSynth_Festival library) and ArCepstral (from the ArSpeechSynth_Cepstral librrary) for speech synthesis.
Add sound files to the queue with play(), and text to speak with speak(). Use runAsync() to run the processing thread in the background, or run() to run synchronously in the current thread.
Public Types | |
typedef ArFunctor | InterruptItemFunctor |
enum | ItemType { SPEECH, SOUND_FILE, SOUND_DATA, OTHER } |
typedef ArRetFunctor< bool > | PlaybackConditionFunctor |
typedef ArRetFunctor2< bool, const char *, const char * > | PlayItemFunctor |
Public Member Functions | |
void | addInitCallback (ArRetFunctor< bool > *cb) |
void | addItem (ItemType type, const char *data, std::list< PlayItemFunctor * > callbacks, int priority=0, const char *params=0) |
void | addItem (ArSoundsQueue::Item item) |
void | addQueueEmptyCallback (ArFunctor *f) |
void | addQueueNonemptyCallback (ArFunctor *f) |
void | addSoundFinishedCallback (ArFunctor *f) |
void | addSoundStartedCallback (ArFunctor *f) |
ArSoundsQueue (ArSpeechSynth *speechSynthesizer, ArRetFunctor< bool > *playInitCB=0, PlayItemFunctor *playFileCB=0, InterruptItemFunctor *interruptFileCB=0) | |
ArSoundsQueue (ArRetFunctor< bool > *speakInitCB, PlayItemFunctor *speakCB=0, InterruptItemFunctor *interruptSpeechCB=0, ArRetFunctor< bool > *playInitCB=0, PlayItemFunctor *playFileCB=0, InterruptItemFunctor *interruptFileCB=0) | |
void | clearQueue () |
ArSoundsQueue::Item | createDefaultFileItem (const char *filename=0) |
ArSoundsQueue::Item | createDefaultSpeechItem (const char *speech=0) |
std::set< int > | findPendingItems (const char *item) |
size_t | getCurrentQueueSize () |
Get the current size of the speech/sound playback queue. | |
ArFunctor * | getPauseCallback () |
ArFunctor * | getResumeCallback () |
void | interrupt () |
If sound is currently being played or speech is being spoken, interrupt it. (but continue processing the queue). SoundFinished callbacks will not be called. | |
bool | isInitialized () |
bool | isPaused () |
bool | isPlaying () |
Returns true if an item is currently being played. | |
bool | isSpeaking () |
bool | isSpeakingOrPlaying (void) |
std::string | nextItem (ItemType type, int priority) |
std::string | nextItem (int priority) |
std::string | nextItem (ItemType type) |
void | pause () |
void | play (const char *filename) |
void | playf (const char *filename_fmt,...) |
void | removePendingItems (ItemType type) |
void | removePendingItems (int priority, ItemType type) |
void | removePendingItems (int priority) |
void | removePendingItems (const char *data) |
void | removePendingItems (const char *item, ItemType type) |
void | remQueueEmptyCallback (ArFunctor *f) |
void | remQueueNonemptyCallback (ArFunctor *f) |
void | remSoundFinishedCallback (ArFunctor *f) |
void | remSoundStartedCallback (ArFunctor *f) |
void | resume () |
Resume processing the sounds queue. | |
void | run (void) |
Begin processing the sounds queue synchronously (in this thread; does not return). | |
void | runAsync (void) |
Begin processing the sounds queue in a background thread. | |
virtual void * | runThread (void *arg) |
main function for thread | |
void | setDefaultPlayConditionCB (PlaybackConditionFunctor *f) |
void | setInterruptFileCallback (InterruptItemFunctor *cb) |
void | setInterruptSpeechCallback (InterruptItemFunctor *cb) |
void | setInterruptWavFileCallback (InterruptItemFunctor *cb) |
void | setPlayFileCallback (PlayItemFunctor *cb) |
void | setPlayWavFileCallback (PlayItemFunctor *cb) |
void | setSpeakCallback (PlayItemFunctor *cb) |
Convenience methods for special speech synthesis and WAV file queue items:. | |
void | setSpeakInitCallback (ArRetFunctor< bool > *cb) |
void | speak (const char *str) |
void | speakf (const char *fmt,...) |
void | speakWithPriority (int priority, const char *fmt,...) |
void | speakWithVoice (const char *voice, const char *fmt,...) |
void | stop () |
Protected Member Functions | |
void | invokeCallbacks (const std::list< ArRetFunctor< bool > * > &lst) |
Invoke each functor in a list, but stop if any of them return false. | |
void | invokeCallbacks (const std::list< ArFunctor * > &lst) |
Invoke each functor in a list. | |
void | lock () |
Item | popQueueItem () |
Item | popQueueItem_NoLock () |
void | pushQueueItem (Item item) |
void | pushQueueItem_NoLock (Item item) |
bool | tryLock () |
void | unlock () |
Protected Attributes | |
InterruptItemFunctor * | myDefaultInterruptFileCB |
InterruptItemFunctor * | myDefaultInterruptSpeechCB |
PlaybackConditionFunctor * | myDefaultPlayConditionCB |
Used when creating default configured speech and sound file items. | |
PlayItemFunctor * | myDefaultPlayFileCB |
PlayItemFunctor * | myDefaultSpeakCB |
Used by speak() and play() convenience methods:. | |
std::list< ArFunctor * > | myEndPlaybackCBList |
std::list< ArRetFunctor< bool > * > | myInitCallbacks |
Functors to invoke when we start running in our thread. | |
bool | myInitialized |
Item | myLastItem |
The current or most recent item played. | |
ArCondition | myPausedCondition |
Condition variable used by the thread to pause. | |
int | myPauseRequestCount |
Semaphore for doing pausing and resuming of the queue. | |
bool | myPlayingSomething |
std::list< Item > | myQueue |
std::list< ArFunctor * > | myQueueEmptyCallbacks |
ArMutex | myQueueMutex |
std::list< ArFunctor * > | myQueueNonemptyCallbacks |
std::list< ArFunctor * > | myStartPlaybackCBList |
Functors to invoke during queue processing. | |
Classes | |
class | Item |
|
Callback types for determining whether to commence playing an item, or skipping it. |
|
Callback for playing a queue item. First argument is the "data", second is item type-specific "parameters". Return true to continue processing more callbacks in a list, false to cancel processing. |
|
Opaque identifier for the type of an item in the sound queue. Not used during processing, but may be used to search for items in the queue. |
|
|
|
Set default speech and WAV file callbacks for use by the convenience methods speak() and play(). Omit the last three arguments to use callbacks into ArSoundPlayer. |
|
Add a callback to be called when the sound queue begins to run in its thread. (For example, the speech synthesizers must be initialized in the same thread as they are used.) |
|
Create a new queue item with the given data and add to the queue. |
|
Add (a copy of) the given item to the queue.
|
|
Add a callback functor to be invoked when the sound queue becomes empty and the last sound has finished playing, that is, when a block of sounds/speech utterances ends. This will not be called when the sound queue first begins running.
|
|
Add a callback functor to be invoked when a the sound queue becomes non-empty, that is, when a block of sounds/speech utterances begins.
|
|
Add a callback functor to be invoked when plackback of one sound or speech utterance begins. |
|
Add a callback functor to be invoked when playback of one sound or speech utterance starts. |
|
Empty the queue. If a sound is currently playing, it will not be interrupted. QueueEmpty callbacks will be called. SoundFinished callbacks will not be called.
|
|
Return an item set up for sound file playback with previously set default play callbacks.
|
|
Return an item set up for speech with previously set default speech callbacks.
|
|
Find items waiting in the queue. This is mainly useful in finding speech text.
|
|
Create and return a new a functor for pause(), which other modules can use to pause this sounds queue. |
|
Create and return a new functor for resume(), which other modules can use to resume this sounds queue. |
|
Return true if all initialization callbacks have completed, false otherwise. |
|
|
|
|
|
|
|
Temporarily stop processing the sounds queue. (Any currently playing sound or speech utterance will finish. The sound device may remain open.)
|
|
Add a sound file to the queue for default sound file playback.
|
|
Add a sound file to the queue for default sound file playback.
|
|
Pop item from queue and return it |
|
push item onto queue
|
|
Remove pending items with the given type. |
|
Remove pending items with priority less the given priority and with the given type. |
|
Remove pending items with a priority less than that given. |
|
Remove pending items with the given data. |
|
Remove pending items with the given data and type.
|
|
Remove a functor added by addQueueEmptyCallback() |
|
Remove a functor added by addQueueNonemptyCallback(). |
|
Remove a callback functor to be invoked when plackback of one sound or speech utterance finishes. |
|
Remove a callback functor to be invoked when playback one sound or speech utterance starts. |
|
Set a playback condition functor used for default speech and sound file items |
|
Set the "default" callback to interrupt current wav file playback, for use by the play() convenience method.
|
|
Set the "default" callback to interrupt a current speech utterance, used by speak()
|
|
|
|
As a convenience, you may set a "default" WAV file playback callback, and then simply use the play() method to add the file to the queue with this callback.
|
|
|
|
Convenience methods for special speech synthesis and WAV file queue items:. As a convenience, you may set a "default" speech synthesis callback, and then simply use the speak() method to add a speech item to the queue with those callbacks.
|
|
|
|
Add text string item to the queue for speech synthesis. The text will be sent to the "speak" callback, if set, otherwise the SynthesiseToSound and PlaySynthesizedSound callbacks are used, if set. |
|
Add a formatted text string (like printf) to the queue configured for default speech synthesis. When reached in the queue while running, the text will be sent to the "speak" callback, if set, otherwise, the "SythesizeToSound" and "PlaySynthesizedSound" callbacks will be used (if they are set.)
|
|
Speak with alternate priority. |
|
Speak with alternate voice. |
|
End the processing thread. This function is deprecated. Use stopRunning() instead.
|