Shows 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>
00001 00017 #include "Aria.h" 00018 #include "ariaTypedefs.h" 00019 #include "ariaUtil.h" 00020 #include "ArSoundsQueue.h" 00021 #include "ArSoundPlayer.h" 00022 #include <iostream> 00023 #include <vector> 00024 00025 using namespace std; 00026 00027 void queueNowEmpty() { 00028 printf("The sound queue is now empty.\n"); 00029 } 00030 00031 void queueNowNonempty() { 00032 printf("The sound queue is now non-empty.\n"); 00033 } 00034 00035 bool no() { 00036 // just a false tautology 00037 return false; 00038 } 00039 00040 int main(int argc, char** argv) { 00041 Aria::init(); 00042 //ArLog::init(ArLog::StdErr, ArLog::Verbose); 00043 00044 // Create the sound queue. 00045 ArSoundsQueue soundQueue; 00046 00047 // Set WAV file callbacks 00048 soundQueue.setPlayWavFileCallback(ArSoundPlayer::getPlayWavFileCallback()); 00049 soundQueue.setInterruptWavFileCallback(ArSoundPlayer::getStopPlayingCallback()); 00050 00051 // Notifications when the queue goes empty or non-empty. 00052 soundQueue.addQueueEmptyCallback(new ArGlobalFunctor(&queueNowEmpty)); 00053 soundQueue.addQueueNonemptyCallback(new ArGlobalFunctor(&queueNowNonempty)); 00054 00055 // Run the sound queue in a new thread 00056 soundQueue.runAsync(); 00057 00058 // Get WAV file names from command line 00059 if(argc < 2) 00060 { 00061 cerr << "Usage: " << argv[0] << " <up to ten WAV sound file names...>\n"; 00062 exit(-1); 00063 } 00064 std::vector<const char*> filenames; 00065 for(int i = 1; i < min(argc, 11); i++) 00066 { 00067 filenames.push_back(argv[i]); 00068 } 00069 00070 // This functor can be used to cancel all sound playback until removed 00071 ArGlobalRetFunctor<bool> dontPlayItem(&no); 00072 00073 while(Aria::getRunning()) 00074 { 00075 cout << "Queue is " << 00076 string(soundQueue.isPaused()?"paused":(soundQueue.isPlaying()?"playing":"ready")) 00077 << ", with " << soundQueue.getCurrentQueueSize() << " pending sounds." << endl 00078 << "Enter a command followed by the enter key:\n" 00079 << "\tp\trequest pause state (cumulative)\n" 00080 << "\tr\trequest resume state (cumulative)\n" 00081 << "\ti\tinterrupt current sound\n" 00082 << "\tc\tclear the queue\n" 00083 << "\tC\tclear priority < 4 from the queue.\n" 00084 << "\tn\tAdd " << filenames[0] << " to the queue, but with a condition callback to prevent it playing.\n" 00085 ; 00086 for(size_t i = 0; i < filenames.size(); i++) 00087 cout << "\t" << i << "\tadd " << filenames[i] << " to the queue\n"; 00088 cout << "\tq\tquit\n\n"; 00089 00090 int c = getchar(); 00091 if(c == '\n') 00092 continue; 00093 switch(c) 00094 { 00095 case 'p': soundQueue.pause(); break; 00096 case 'r': soundQueue.resume(); break; 00097 case 'i': soundQueue.interrupt(); break; 00098 case 'q': soundQueue.stop(); ArUtil::sleep(100); exit(0); 00099 case 'c': soundQueue.clearQueue(); break; 00100 case 'C': soundQueue.removePendingItems(4); break; 00101 case 'n': 00102 { 00103 cout << "Adding \"" << filenames[0] << "\" but with a condition callback that will prevent it from playing...\n"; 00104 ArSoundsQueue::Item item = soundQueue.createDefaultFileItem(filenames[0]); 00105 item.playbackConditionCallbacks.push_back(&dontPlayItem); 00106 soundQueue.addItem(item); 00107 break; 00108 } 00109 default: 00110 if(filenames.size() > 0 && c >= '0' && c <= '9') 00111 { 00112 size_t i = c - '0'; 00113 if(i < filenames.size()) 00114 { 00115 cout << "Adding \"" << filenames[i] << "\" to the queue...\n"; 00116 soundQueue.play(filenames[i]); 00117 } 00118 } 00119 } 00120 } 00121 cout << "Aria ended.\n"; 00122 Aria::shutdown(); 00123 return 0; 00124 } 00125 00126
1.4.7