Aria
2.8.0
|
This class manages a queue of items to play as WAV files or as text to speak using a speech synthesizer. More...
#include <ArSoundsQueue.h>
Inherits ArASyncTask.
Classes | |
class | Item |
A sound item in the queue, with callbacks for dealing with the item and the data to pass to those callbacks. More... | |
Public Types | |
typedef ArFunctor | InterruptItemFunctor |
enum | ItemType { SPEECH, SOUND_FILE, SOUND_DATA, OTHER } |
Opaque identifier for the type of an item in the sound queue. More... | |
typedef ArRetFunctor< bool > | PlaybackConditionFunctor |
Callback types for determining whether to commence playing an item, or skipping it. | |
typedef ArRetFunctor2< bool, const char *, const char * > | PlayItemFunctor |
Callback for playing a queue item. More... | |
Public Types inherited from ArThread | |
typedef std::map< ThreadType, ArThread * > | MapType |
enum | Status { STATUS_FAILED =1, STATUS_NORESOURCE, STATUS_NO_SUCH_THREAD, STATUS_INVALID, STATUS_JOIN_SELF, STATUS_ALREADY_DETATCHED } |
typedef pthread_t | ThreadType |
Public Member Functions | |
void | addInitCallback (ArRetFunctor< bool > *cb) |
Add a callback to be called when the sound queue begins to run in its thread. More... | |
void | addItem (ArSoundsQueue::Item item) |
Add (a copy of) the given item to the queue. More... | |
void | addItem (ItemType type, const char *data, std::list< PlayItemFunctor *> callbacks, int priority=0, const char *params=0) |
Create a new queue item with the given data and add to the queue. More... | |
void | addQueueEmptyCallback (ArFunctor *f) |
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. More... | |
void | addQueueNonemptyCallback (ArFunctor *f) |
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. | |
void | addSoundFinishedCallback (ArFunctor *f) |
Add a callback functor to be invoked when plackback of one sound or speech utterance finishes. | |
void | addSoundItemFinishedCallback (ArFunctor1< ArSoundsQueue::Item > *f) |
Add a callback functor to be invoked when plackback of one sound or speech utterance finishes. | |
void | addSoundItemStartedCallback (ArFunctor1< ArSoundsQueue::Item > *f) |
Add a callback functor to be invoked when playback of one sound or speech utterance starts. More... | |
void | addSoundStartedCallback (ArFunctor *f) |
Add a callback functor to be invoked when playback of one sound or speech utterance starts. More... | |
ArSoundsQueue () | |
INTERNAL_CLASSES. | |
ArSoundsQueue (ArRetFunctor< bool > *speakInitCB, PlayItemFunctor *speakCB=0, InterruptItemFunctor *interruptSpeechCB=0, ArRetFunctor< bool > *playInitCB=0, PlayItemFunctor *playFileCB=0, InterruptItemFunctor *interruptFileCB=0) | |
ArSoundsQueue (ArSpeechSynth *speechSynthesizer, ArRetFunctor< bool > *playInitCB=0, PlayItemFunctor *playFileCB=0, InterruptItemFunctor *interruptFileCB=0) | |
Set default speech and WAV file callbacks for use by the convenience methods speak() and play(). More... | |
void | clearQueue () |
Empty the queue. More... | |
std::set< int > | findPendingItems (const char *item) |
Find items waiting in the queue. More... | |
size_t | getCurrentQueueSize () |
Get the current size of the speech/sound playback queue. | |
ArFunctor * | getPauseCallback () |
Create and return a new a functor for pause(), which other modules can use to pause this sounds queue. More... | |
ArFunctor * | getResumeCallback () |
Create and return a new functor for resume(), which other modules can use to resume this sounds queue. More... | |
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 () |
Return true if all initialization callbacks have completed, false otherwise. | |
bool | isPaused () |
bool | isPlaying () |
Returns true if an item is currently being played. | |
bool | isSpeaking () |
bool | isSpeakingOrPlaying (void) |
std::string | nextItem (ItemType type) |
std::string | nextItem (int priority) |
std::string | nextItem (ItemType type, int priority) |
void | pause () |
Temporarily stop processing the sounds queue. More... | |
void | removeItems (int priority) |
Remove pending and current items with a priority less than that given. More... | |
void | removeItems (Item item) |
Removes pending and current items with the same data and type as the given item. | |
void | removePendingItems (const char *item, ItemType type) |
Remove pending items with the given data and type. More... | |
void | removePendingItems (const char *data) |
Remove pending items with the given data. More... | |
void | removePendingItems (int priority) |
Remove pending items with a priority less than that given. More... | |
void | removePendingItems (int priority, ItemType type) |
Remove pending items with priority less the given priority and with the given type. More... | |
void | removePendingItems (ItemType type) |
Remove pending items with the given type. More... | |
void | remQueueEmptyCallback (ArFunctor *f) |
Remove a functor added by addQueueEmptyCallback() | |
void | remQueueNonemptyCallback (ArFunctor *f) |
Remove a functor added by addQueueNonemptyCallback(). More... | |
void | remSoundFinishedCallback (ArFunctor *f) |
Remove a callback functor to be invoked when plackback of one sound or speech utterance finishes. More... | |
void | remSoundItemFinishedCallback (ArFunctor1< ArSoundsQueue::Item > *f) |
Remove a callback functor to be invoked when plackback of one sound or speech utterance finishes. More... | |
void | remSoundItemStartedCallback (ArFunctor1< ArSoundsQueue::Item > *f) |
Remove a callback functor to be invoked when playback one sound or speech utterance starts. More... | |
void | remSoundStartedCallback (ArFunctor *f) |
Remove a callback functor to be invoked when playback one sound or speech utterance starts. More... | |
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) |
Set a playback condition functor used for default speech and sound file items. More... | |
void | setSpeakInitCallback (ArRetFunctor< bool > *cb) |
void | stop () |
End the processing thread. More... | |
void | setSpeakCallback (PlayItemFunctor *cb) |
Convenience methods for special speech synthesis and WAV file queue items: More... | |
void | setInterruptSpeechCallback (InterruptItemFunctor *cb) |
Set the "default" callback to interrupt a current speech utterance, used by speak() More... | |
void | setPlayFileCallback (PlayItemFunctor *cb) |
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. More... | |
void | setPlayWavFileCallback (PlayItemFunctor *cb) |
void | setInterruptFileCallback (InterruptItemFunctor *cb) |
Set the "default" callback to interrupt current wav file playback, for use by the play() convenience method. More... | |
void | setInterruptWavFileCallback (InterruptItemFunctor *cb) |
void | speak (const char *str) |
Add text string item to the queue for speech synthesis. More... | |
void | play (const char *filename) |
Add a sound file to the queue for default sound file playback. More... | |
void | speakf (const char *fmt,...) |
Add a formatted text string (like printf) to the queue configured for default speech synthesis. More... | |
void | speakWithVoice (const char *voice, const char *fmt,...) |
Speak with alternate voice. More... | |
void | speakWithPriority (int priority, const char *fmt,...) |
Speak with alternate priority. More... | |
void | playf (const char *filename_fmt,...) |
Add a sound file to the queue for default sound file playback. More... | |
ArSoundsQueue::Item | createDefaultSpeechItem (const char *speech=0) |
Return an item set up for speech with previously set default speech callbacks. More... | |
ArSoundsQueue::Item | createDefaultFileItem (const char *filename=0) |
Return an item set up for sound file playback with previously set default play callbacks. More... | |
Public Member Functions inherited from ArASyncTask | |
ArASyncTask () | |
Constructor. | |
virtual int | create (bool joinable=true, bool lowerPriority=true) |
Create the task and start it going. | |
virtual const char * | getThreadActivity (void) |
Gets a string that describes what the thread is doing, or NULL if it doesn't know. More... | |
virtual void * | runInThisThread (void *arg=0) |
Internal function used with system threading system to run the new thread. More... | |
virtual void | stopRunning (void) |
Stop the thread. | |
virtual | ~ArASyncTask () |
Destructor. | |
Public Member Functions inherited from ArThread | |
ArThread (bool blockAllSignals=true) | |
Constructor. | |
ArThread (ThreadType thread, bool joinable, bool blockAllSignals=true) | |
Constructor - starts the thread. | |
ArThread (ArFunctor *func, bool joinable=true, bool blockAllSignals=true) | |
Constructor - starts the thread. | |
virtual void | cancel (void) |
Cancel the thread. | |
virtual int | detach (void) |
Detatch the thread so it cant be joined. | |
bool | getBlockAllSignals (void) |
Do we block all process signals at startup? | |
virtual ArFunctor * | getFunc (void) const |
Get the functor that the thread runs. | |
virtual bool | getJoinable (void) const |
Get the joinable status of the thread. | |
virtual ThreadType | getOSThread (void) const |
Get the underlying os thread type. | |
pid_t | getPID (void) |
virtual bool | getRunning (void) const |
Get the running status of the thread. | |
virtual bool | getRunningWithLock (void) |
Get the running status of the thread, locking around the variable. | |
virtual const ThreadType * | getThread (void) const |
Get the underlying thread type. | |
virtual const char * | getThreadName (void) |
Gets the name of the thread. | |
pid_t | getTID (void) |
virtual bool | isThreadFinished () const |
Returns whether the thread has been completed and can be deleted. More... | |
virtual bool | isThreadStarted () const |
Returns whether the thread has been started. More... | |
virtual int | join (void **ret=NULL) |
Join on the thread. | |
int | lock (void) |
Lock the thread instance. More... | |
virtual void | logThreadInfo (void) |
Logs the information about this thread. | |
virtual void | setRunning (bool running) |
Set the running value on the thread. | |
virtual void | setThreadName (const char *name) |
Sets the name of the thread. | |
virtual void | threadFinished (void) |
Marks the thread as finished and logs useful debugging information. More... | |
virtual void | threadStarted (void) |
Marks the thread as started and logs useful debugging information. More... | |
int | tryLock (void) |
Try to lock the thread instance without blocking. More... | |
int | unlock (void) |
Unlock the thread instance. More... | |
virtual | ~ArThread () |
Destructor. | |
Protected Member Functions | |
void | invokeCallbacks (const std::list< ArFunctor *> &lst) |
Invoke each functor in a list. | |
void | invokeCallbacks (const std::list< ArRetFunctor< bool > *> &lst) |
Invoke each functor in a list, but stop if any of them return false. | |
void | lock () |
bool | tryLock () |
void | unlock () |
void | pushQueueItem (Item item) |
push item onto queue More... | |
void | pushQueueItem_NoLock (Item item) |
Item | popQueueItem () |
Pop item from queue and return it. | |
Item | popQueueItem_NoLock () |
Protected Member Functions inherited from ArThread | |
virtual int | doJoin (void **ret=NULL) |
Protected Attributes | |
PlaybackConditionFunctor * | myDefaultPlayConditionCB |
Used when creating default configured speech and sound file items. | |
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 |
ArMutex | myQueueMutex |
PlayItemFunctor * | myDefaultSpeakCB |
Used by speak() and play() convenience methods: | |
InterruptItemFunctor * | myDefaultInterruptSpeechCB |
PlayItemFunctor * | myDefaultPlayFileCB |
InterruptItemFunctor * | myDefaultInterruptFileCB |
std::list< ArFunctor * > | myStartPlaybackCBList |
Functors to invoke during queue processing. | |
std::list< ArFunctor * > | myEndPlaybackCBList |
std::list< ArFunctor1< ArSoundsQueue::Item > * > | myStartItemPlaybackCBList |
std::list< ArFunctor1< ArSoundsQueue::Item > * > | myEndItemPlaybackCBList |
std::list< ArFunctor * > | myQueueNonemptyCallbacks |
std::list< ArFunctor * > | myQueueEmptyCallbacks |
Protected Attributes inherited from ArThread | |
bool | myBlockAllSignals |
bool | myFinished |
ArFunctor * | myFunc |
bool | myJoinable |
ArMutex | myMutex |
std::string | myName |
pid_t | myPID |
bool | myRunning |
State variable to denote when the thread should continue or exit. | |
bool | myStarted |
ArStrMap | myStrMap |
ThreadType | myThread |
pid_t | myTID |
Additional Inherited Members | |
Static Public Member Functions inherited from ArThread | |
static void | cancelAll (void) |
Cancel all threads. | |
static ArLog::LogLevel | getLogLevel (void) |
Gets the logging level for thread information. | |
static ThreadType | getThisOSThread (void) |
Get the underlying os thread type of this thread. | |
static const ThreadType * | getThisThread (void) |
Get the underlying thread type of this thread. | |
static const char * | getThisThreadName (void) |
Gets the name of the this thread. | |
static void | init (void) |
Initialize the internal book keeping structures. More... | |
static void | joinAll (void) |
Join on all threads. | |
static ThreadType | osSelf (void) |
Returns the os self of the current thread. More... | |
static ArThread * | self (void) |
Returns the instance of your own thread (the current one) More... | |
static void | setLogLevel (ArLog::LogLevel level) |
Sets the logging level for thread information. | |
static void | shutdown () |
Shuts down and deletes the last remaining thread; call after joinAll. | |
static void | stopAll () |
Stop all threads. | |
static void | yieldProcessor (void) |
Yield the processor to another thread. | |
Static Protected Member Functions inherited from ArThread | |
static void | addThreadToMap (ThreadType pt, ArThread *at) |
static ArThread * | findThreadInMap (ThreadType t) |
static void | removeThreadFromMap (ThreadType t) |
Static Protected Attributes inherited from ArThread | |
static ArLog::LogLevel | ourLogLevel = ArLog::Verbose |
static MapType | ourThreads |
static ArMutex | ourThreadsMutex |
static std::string | ourUnknownThreadName = "unknown" |
This class manages a queue of items to play as WAV files or as text to speak using a speech synthesizer.
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.
typedef ArRetFunctor2<bool, const char*, const char*> ArSoundsQueue::PlayItemFunctor |
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.
ArSoundsQueue::ArSoundsQueue | ( | ArRetFunctor< bool > * | speakInitCB, |
PlayItemFunctor * | speakCB = 0 , |
||
InterruptItemFunctor * | interruptSpeechCB = 0 , |
||
ArRetFunctor< bool > * | playInitCB = 0 , |
||
PlayItemFunctor * | playFileCB = 0 , |
||
InterruptItemFunctor * | interruptFileCB = 0 |
||
) |
ArSoundsQueue::ArSoundsQueue | ( | ArSpeechSynth * | speechSynthesizer, |
ArRetFunctor< bool > * | playInitCB = 0 , |
||
PlayItemFunctor * | playFileCB = 0 , |
||
InterruptItemFunctor * | interruptFileCB = 0 |
||
) |
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.
|
inline |
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.)
void ArSoundsQueue::addItem | ( | ArSoundsQueue::Item | item | ) |
Add (a copy of) the given item to the queue.
void ArSoundsQueue::addItem | ( | ItemType | type, |
const char * | data, | ||
std::list< PlayItemFunctor *> | callbacks, | ||
int | priority = 0 , |
||
const char * | params = 0 |
||
) |
Create a new queue item with the given data and add to the queue.
|
inline |
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.
|
inline |
Add a callback functor to be invoked when playback of one sound or speech utterance starts.
|
inline |
Add a callback functor to be invoked when playback of one sound or speech utterance starts.
void ArSoundsQueue::clearQueue | ( | ) |
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.
ArSoundsQueue::Item ArSoundsQueue::createDefaultFileItem | ( | const char * | filename = 0 | ) |
Return an item set up for sound file playback with previously set default play callbacks.
filename | Filename to set (optional) |
ArSoundsQueue::Item ArSoundsQueue::createDefaultSpeechItem | ( | const char * | speech = 0 | ) |
Return an item set up for speech with previously set default speech callbacks.
speech | Text to speak (optional) |
set< int > ArSoundsQueue::findPendingItems | ( | const char * | item | ) |
Find items waiting in the queue.
This is mainly useful in finding speech text.
item | Item to search for. |
|
inline |
Create and return a new a functor for pause(), which other modules can use to pause this sounds queue.
|
inline |
Create and return a new functor for resume(), which other modules can use to resume this sounds queue.
bool ArSoundsQueue::isPaused | ( | ) |
|
inline |
|
inline |
void ArSoundsQueue::pause | ( | void | ) |
Temporarily stop processing the sounds queue.
(Any currently playing sound or speech utterance will finish. The sound device may remain open.)
void ArSoundsQueue::play | ( | const char * | filename | ) |
Add a sound file to the queue for default sound file playback.
void ArSoundsQueue::playf | ( | const char * | filename_fmt, |
... | |||
) |
Add a sound file to the queue for default sound file playback.
filename_fmt | Format string for determining the filename of the WAV file, same as printf(). |
... | If given, arguments to format into the format string. |
|
protected |
push item onto queue
void ArSoundsQueue::removeItems | ( | int | priority | ) |
Remove pending and current items with a priority less than that given.
void ArSoundsQueue::removePendingItems | ( | const char * | item, |
ItemType | type | ||
) |
Remove pending items with the given data and type.
void ArSoundsQueue::removePendingItems | ( | const char * | data | ) |
Remove pending items with the given data.
void ArSoundsQueue::removePendingItems | ( | int | priority | ) |
Remove pending items with a priority less than that given.
void ArSoundsQueue::removePendingItems | ( | int | priority, |
ItemType | type | ||
) |
Remove pending items with priority less the given priority and with the given type.
void ArSoundsQueue::removePendingItems | ( | ItemType | type | ) |
Remove pending items with the given type.
|
inline |
Remove a functor added by addQueueNonemptyCallback().
|
inline |
Remove a callback functor to be invoked when plackback of one sound or speech utterance finishes.
|
inline |
Remove a callback functor to be invoked when plackback of one sound or speech utterance finishes.
|
inline |
Remove a callback functor to be invoked when playback one sound or speech utterance starts.
|
inline |
Remove a callback functor to be invoked when playback one sound or speech utterance starts.
|
inline |
Set a playback condition functor used for default speech and sound file items.
Set to NULL to clear.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
void ArSoundsQueue::speak | ( | const char * | str | ) |
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.
void ArSoundsQueue::speakf | ( | const char * | fmt, |
... | |||
) |
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.)
fmt | Format string. |
... | Arguments to format into the format string. |
void ArSoundsQueue::speakWithPriority | ( | int | priority, |
const char * | fmt, | ||
... | |||
) |
Speak with alternate priority.
void ArSoundsQueue::speakWithVoice | ( | const char * | voice, |
const char * | fmt, | ||
... | |||
) |
Speak with alternate voice.
void ArSoundsQueue::stop | ( | void | ) |
End the processing thread.
This function is deprecated. Use stopRunning() instead.