This program demonstrates the sound output queue ArSoundsQueueShows how to operate the sounds queue and add WAV files to play.
You may specify up to 10 file names on the command line. This example only demonstrates using the sounds queue for WAV file playback. For demonstration of using the sounds queue for speech synthesis, see the examples provided with either the ArSpeechSynth_Cepstral or ArSpeechSynth_Festival libraries.
Usage: soundQueue <wav file names>
#include "Aria.h"
#include "ariaTypedefs.h"
#include "ariaUtil.h"
#include "ArSoundsQueue.h"
#include "ArSoundPlayer.h"
#include <iostream>
#include <vector>
using namespace std;
void queueNowEmpty() {
printf("The sound queue is now empty.\n");
}
void queueNowNonempty() {
printf("The sound queue is now non-empty.\n");
}
bool no() {
return false;
}
int main(int argc, char** argv) {
if(argc < 2)
{
cerr << "Usage: " << argv[0] << " <up to ten WAV sound file names...>\n";
}
std::vector<const char*> filenames;
for(int i = 1; i < min(argc, 11); i++)
{
filenames.push_back(argv[i]);
}
{
cout << "Queue is " <<
<< "Enter a command followed by the enter key:\n"
<< "\tp\trequest pause state (cumulative)\n"
<< "\tr\trequest resume state (cumulative)\n"
<< "\ti\tinterrupt current sound\n"
<< "\tc\tclear the queue\n"
<< "\tC\tclear priority < 4 from the queue.\n"
<< "\tn\tAdd " << filenames[0] << " to the queue, but with a condition callback to prevent it playing.\n"
<< "\tv\tAdjust volume -50%\n"
<< "\tV\tAdjust volume +50%\n"
<< "\to\tAdjust volume -100%\n"
<< "\tO\tAdjust volume +100%\n"
<< "\tl\tAdjust volume -200%\n"
<< "\tL\tAdjust volume +200%\n"
<< "\t-\tSet volume adjustment to normal level\n"
;
for(size_t i = 0; i < filenames.size(); i++)
cout << "\t" << i << "\tadd " << filenames[i] << " to the queue\n";
cout << "\tq\tquit\n\n";
int c = getchar();
if(c == '\n')
continue;
switch(c)
{
case 'p': soundQueue.
pause();
break;
case 'r': soundQueue.
resume();
break;
case 'n':
{
cout << "Adding \"" << filenames[0] << "\" but with a condition callback that will prevent it from playing...\n";
item.
playbackConditionCallbacks.push_back(&dontPlayItem);
break;
}
default:
if(filenames.size() > 0 && c >= '0' && c <= '9')
{
size_t i = c - '0';
if(i < filenames.size())
{
cout << "Adding \"" << filenames[i] << "\" to the queue...\n";
soundQueue.
play(filenames[i]);
}
}
}
}
cout << "ended.\n";
return 0;
}
static ArRetFunctor2< bool, const char *, const char * > * getPlayWavFileCallback()
Return the static functor for playWavFile.
Definition: ArSoundPlayer.cpp:39
void clearQueue()
Empty the queue.
Definition: ArSoundsQueue.cpp:628
A sound item in the queue, with callbacks for dealing with the item and the data to pass to those cal...
Definition: ArSoundsQueue.h:85
size_t getCurrentQueueSize()
Get the current size of the speech/sound playback queue.
Definition: ArSoundsQueue.h:243
void resume()
Resume processing the sounds queue.
Definition: ArSoundsQueue.cpp:591
void stop()
End the processing thread.
Definition: ArSoundsQueue.cpp:606
void play(const char *filename)
Add a sound file to the queue for default sound file playback.
Definition: ArSoundsQueue.cpp:349
void interrupt()
If sound is currently being played or speech is being spoken, interrupt it. (but continue processing ...
Definition: ArSoundsQueue.cpp:616
void runAsync(void)
Begin processing the sounds queue in a background thread.
Definition: ArSoundsQueue.h:196
void setPlayWavFileCallback(PlayItemFunctor *cb)
Definition: ArSoundsQueue.h:407
static ArFunctor * getStopPlayingCallback()
Return the static functor for stopPlaying().
Definition: ArSoundPlayer.cpp:45
static void setVolumePercent(double pct)
Set volume as a "percent" of normal, where 100% is normal or natural volume, 50% is increased by 50%,...
Definition: ArSoundPlayer.cpp:301
This class manages a queue of items to play as WAV files or as text to speak using a speech synthesiz...
Definition: ArSoundsQueue.h:62
static void exit(int exitCode=0)
Shutdown all Aria processes/threads, call exit callbacks, and exit the program.
Definition: Aria.cpp:367
bool isPlaying()
Returns true if an item is currently being played.
Definition: ArSoundsQueue.h:182
static void init(SigHandleMethod method=SIGHANDLE_THREAD, bool initSockets=true, bool sigHandleExitNotShutdown=true)
Initialize Aria global data struture and perform OS-specific initialization, including adding OS sign...
Definition: Aria.cpp:128
void addItem(ArSoundsQueue::Item item)
Add (a copy of) the given item to the queue.
Definition: ArSoundsQueue.cpp:288
void setInterruptWavFileCallback(InterruptItemFunctor *cb)
Definition: ArSoundsQueue.h:420
bool isPaused()
Definition: ArSoundsQueue.cpp:611
void addQueueEmptyCallback(ArFunctor *f)
Add a callback functor to be invoked when the sound queue becomes empty and the last sound has finish...
Definition: ArSoundsQueue.h:327
static void sleep(unsigned int ms)
Sleep for the given number of milliseconds.
Definition: ariaUtil.cpp:151
void addQueueNonemptyCallback(ArFunctor *f)
Add a callback functor to be invoked when a the sound queue becomes non-empty, that is,...
Definition: ArSoundsQueue.h:311
ArSoundsQueue::Item createDefaultFileItem(const char *filename=0)
Return an item set up for sound file playback with previously set default play callbacks.
Definition: ArSoundsQueue.cpp:453
Functor for a global function with no parameters.
Definition: ArFunctor.h:648
static bool getRunning(void)
Sees if Aria is still running (mostly for the thread in main)
Definition: Aria.cpp:753
void removePendingItems(const char *item, ItemType type)
Remove pending items with the given data and type.
Definition: ArSoundsQueue.cpp:651
void pause()
Temporarily stop processing the sounds queue.
Definition: ArSoundsQueue.cpp:584