Home › Forums › OpenEars › Flite in background › Reply To: Flite in background
Thanks for the quick response.
Not sure if I am doing it right, I was able to make Flite speak in the background after making two changes in AudioSessionManager.m.
1. self.soundMixing = TRUE;
2. audioCategoryClassification = kAudioSessionCategory_MediaPlayback;
The weird part is that the Flite can only speak one phrase after entering the background mode. It was working fine if the app is running in the foreground.
Below are my findings after many hours of debugging:
1. the AVAudioPlayer delegates did not get called after the [self.audioPlayer play] in the background mode.
2. since the audioPlay did not get destroyed and neither speaking, the lazy accessory of AVAudioPlayer bypassed the initWithData when another phrase was sent to FliteController.
3. When the app is running in the foreground, the AVAudioPlayer delegates were triggered on the main thread.
4. However, since my app was running in another background queue (NSOperationQueue), the Application Delegate was the only application thread running on the main thread. I don’t see any log message coming out of main thread any more.
5. I found a work around by checking to see audioPlay is playing in the lazy accessor code to destroy the audioPlayer and execute the play command again. I kind of suspect this may cause problem some where else.
I am not clear what happen to Flite Controller, as a delegate, running in the back ground mode.
Let me know what you think.
Will do more investigation later.
Thanks,
==============================
logs – (907 is the main thread):
===============================
4784:1803 I’m running flite
4784:1803 Checking and resetting all audio session settings.
4784:1803 audioCategory is correct, we will leave it as it is.
4784:1803 bluetoothInput is correct, we will leave it as it is.
4784:1803 categoryDefaultToSpeaker is correct, we will leave it as it is.
4784:1803 OverrideCategoryMixWithOthers is correct, we will leave it as it is.
4784:1803 preferredBufferSize is correct, we will leave it as it is.
4784:1803 preferredSampleRateCheck is correct, we will leave it as it is.
4784:1803 I’m done running flite and it took 0.306104 seconds
4784:1803 Flite posting suspend notification
4784:907 Flite sending suspend recognition notification.
4784:1803 Flite audio player was nil when referenced so attempting to allocate a new audio player.
4784:1803 Loading speech data for Flite concluded successfully.
4784:907 AVAudioPlayer did finish playing with success flag of 1
4784:907 Flite sending resume recognition notification.
4784:907
Running in the background!
4784:390b I’m running flite
4784:390b Checking and resetting all audio session settings.
4784:390b audioCategory is correct, we will leave it as it is.
4784:390b bluetoothInput is correct, we will leave it as it is.
4784:390b categoryDefaultToSpeaker is correct, we will leave it as it is.
4784:390b OverrideCategoryMixWithOthers is correct, we will leave it as it is.
4784:390b preferredBufferSize is correct, we will leave it as it is.
4784:390b preferredSampleRateCheck is correct, we will leave it as it is.
4784:390b I’m done running flite and it took 0.216623 seconds
4784:390b Flite posting suspend notification
4784:390b Flite audio player was nil when referenced so attempting to allocate a new audio player.
4784:390b Loading speech data for Flite concluded successfully.
(no voice)
4784:390f I’m running flite
4784:390f Checking and resetting all audio session settings.
4784:390f audioCategory is correct, we will leave it as it is.
4784:390f bluetoothInput is correct, we will leave it as it is.
4784:390f categoryDefaultToSpeaker is correct, we will leave it as it is.
4784:390f OverrideCategoryMixWithOthers is correct, we will leave it as it is.
4784:390f preferredBufferSize is correct, we will leave it as it is.
4784:390f preferredSampleRateCheck is correct, we will leave it as it is.
4784:390f I’m done running flite and it took 0.208594 seconds
4784:390f Flite posting suspend notification
4784:390f Loading speech data for Flite concluded successfully.
(no voice)