Home › Forums › OpenEars › How to deallocate OpenEars singleton (2.0) ? › Reply To: How to deallocate OpenEars singleton (2.0) ?
Thanks for the quick reply Halle.
OK, so I think I understand the reasoning behind setActive. It’s just there to ensure sharedInstance has been fully initialized before we carry on with our code.
About the problem at hand, the reason I need to deallocate it is because of a conflict with other libraries my application is currently using (Unity 3D in my case).
I understand you cannot provide support for such kinds of use cases, so I isolated the problem to try to turn it into something that could be inside the scope of the support we can get.
If I was able to completely destroy the Singleton and reinitialize OpenEars from scratch, I’m sure I would be able to solve the issue I’m having.
Anyway, let me explain why I need to do this, as it may very well be a bug in OpenEars. I hope the following information will be helpful.
Here we go:
Whenever I plug in headphones during runtime, OpenEars will call StopListening by itself, and apparently try to restart the listening process after the Audio Route changes. However, after StopListening is called, it fails to restart the listening process and OEPocketsphinxController is put into some kind of invalid locked state. That lock is never released, and it doesn’t allow me to call StopListening to shut it off, or StartListening either. It’s basically just dead.
Unplugging the headphones has no effect, OpenEars no longer responds to it.
Here’s are the logs I get as soon as I plug in the headphones:
2015-08-30 00:43:43.263 mathcommand[12363:3873953] Audio route has changed for the following reason:
2015-08-30 00:43:43.263 mathcommand[12363:3873953] A new device is available
2015-08-30 00:43:43.263 mathcommand[12363:3873953] The audio input is available
2015-08-30 00:43:43.265 mathcommand[12363:3873953] This is a case for performing a route change. Before the route change, the current route was HeadphonesMicrophoneWired. Performing route change.
2015-08-30 00:43:43.266 mathcommand[12363:3873953] Audio route change. The new audio route is HeadphonesMicrophoneWired
2015-08-30 00:43:43.267 mathcommand[12363:3873953] Stopping listening.
2015-08-30 00:43:43.267 mathcommand[12363:3874187] A request has been made to start a listening session using startListeningWithLanguageModelAtPath:dictionaryAtPath:acousticModelAtPath:languageModelIsJSGF:, however, there is already a listening session in progress which has not been stopped. Please stop this listening session first with [[OEPocketsphinxController sharedInstance] stopListening]; and wait to receive the OEEventsObserver callback pocketsphinxDidStopListening before starting a new session. You can still change models in the existing session by using OEPocketsphinxController's method changeLanguageModelToFile:withDictionary:
2015-08-30 00:43:44.658 mathcommand[12363:3873953] 00:43:44.657 ERROR: [0x3a5069dc] AVAudioSession.mm:646: -[AVAudioSession setActive:withOptions:error:]: Deactivating an audio session that has running I/O. All I/O should be stopped or paused prior to deactivating the audio session.
2015-08-30 00:43:44.659 mathcommand[12363:3873953] Error: couldn't set session inactive.: '!act'
2015-08-30 00:43:44.669 mathcommand[12363:3873953] Error: there was a problem tearing down the audio session: Error Domain=NSOSStatusErrorDomain Code=560030580 "The operation couldn’t be completed. (OSStatus error 560030580.)".
2015-08-30 00:43:44.670 mathcommand[12363:3873953] Unable to stop listening because because an utterance is still in progress; trying again.
2015-08-30 00:43:44.721 mathcommand[12363:3873953] Attempting to stop an unstopped utterance so listening can stop.
2015-08-30 00:43:44.752 mathcommand[12363:3873953] No longer listening.
2015-08-30 00:43:44.754 mathcommand[12363:3873953] Pocketsphinx has stopped listening.
2015-08-30 00:43:44.754 mathcommand[12363:3874198] A request has been made to start a listening session using startListeningWithLanguageModelAtPath:dictionaryAtPath:acousticModelAtPath:languageModelIsJSGF:, however, there is already a listening session in progress which has not been stopped. Please stop this listening session first with [[OEPocketsphinxController sharedInstance] stopListening]; and wait to receive the OEEventsObserver callback pocketsphinxDidStopListening before starting a new session. You can still change models in the existing session by using OEPocketsphinxController's method changeLanguageModelToFile:withDictionary:
2015-08-30 00:43:44.761 mathcommand[12363:3873953] Audio route has changed for the following reason:
2015-08-30 00:43:44.762 mathcommand[12363:3873953] There was a category change. The new category is AVAudioSessionCategoryPlayAndRecord
2015-08-30 00:43:44.765 mathcommand[12363:3873953] This is not a case in which OpenEars notifies of a route change. At the close of this function, the new audio route is ---Headphones---. The previous route before changing to this route was <AVAudioSessionRouteDescription: 0x19305160,
inputs = (
"<AVAudioSessionPortDescription: 0x19309610, type = MicrophoneWired; name = Headset Microphone; UID = Wired Microphone; selectedDataSource = (null)>"
);
outputs = (
"<AVAudioSessionPortDescription: 0x193772f0, type = Headphones; name = Headphones; UID = Wired Headphones; selectedDataSource = (null)>"
)>.
After this, whenever I try to call StartListening, I get this:
2015-08-30 00:43:47.849 mathcommand[12363:3874198] A request has been made to start a listening session using startListeningWithLanguageModelAtPath:dictionaryAtPath:acousticModelAtPath:languageModelIsJSGF:, however, there is already a listening session in progress which has not been stopped. Please stop this listening session first with [[OEPocketsphinxController sharedInstance] stopListening]; and wait to receive the OEEventsObserver callback pocketsphinxDidStopListening before starting a new session. You can still change models in the existing session by using OEPocketsphinxController's method changeLanguageModelToFile:withDictionary:
And if I try to call StopListening, I get this:
2015-08-30 01:17:17.484 mathcommand[12378:3879295] [[OEPocketsphinxController sharedInstance] stopListening] was called while listening was not in progress. This is not necessarily an exception, just a notification that that a request to stop a listening session was ignored because there was no active listening session to stop.
As you can see, OEPocketsphinxController is clearly in a locked state. Neither StopListening nor StartListening will work anymore.
I can’t find a way to unlock it. So that’s the reason I want to destroy the Singleton.
I hope these logs can be useful.