rxlabz / speech_recognition

A Flutter plugin to use speech recognition on iOS & Android (Swift/Java)
https://pub.dartlang.org/packages/speech_recognition
Other
336 stars 197 forks source link

Microphone stays on after stop() and close(). #48

Open mazo20 opened 5 years ago

mazo20 commented 5 years ago

I am building an app where I use both speech recognition and text-to-speech. However, I have encountered an error where the microphone used for speech recognition is being kept on even after I stop the recognition with stop() or close() or if it completes on its own. If the mic is kept on I cannot play any sounds and hence the text-to-speech doesn't work after I use speech recognition.

nmfisher commented 5 years ago

This is because the plugin sets the audioSession category to "record":

https://github.com/rxlabz/speech_recognition/blob/d527d13d16c2a9cd001bf14a4372ec74c69f72b2/ios/Classes/SwiftSpeechRecognitionPlugin.swift#L111

and this doesn't allow audio playback, which is why you hear nothing.

Two options to fix this: 1) After speech recognition is invoked, manually set the category to playback in your text-to-speech code. 2) Fork the speech_recognition plugin to set the category to playAndRecord

https://github.com/nmfisher/speech_recognition/commit/48d4cccadd5a9381bc7df49f7ab63c792419f40f

monggos commented 5 years ago

yes, i also manually updated this file.. /ios/.symlinks/plugins//speech_recognition/ios/Classes/SwiftSpeechRecognitionPlugin.swift

i hope i will not forget that i updated the file and upgrade the version.. hehehe..

Screen Shot 2019-10-11 at 4 58 09 PM