flutter_tts icon indicating copy to clipboard operation
flutter_tts copied to clipboard

Method 'setIosAudioCategory' does not seem to work

Open mvrsn opened this issue 2 years ago • 7 comments

🐛 Bug Report

I was trying to test the new audio mode option by calling the setIosAudioCategory method but were having some issues with getting duckOthers to work

I then tried a bunch of different settings combinations, but none of them seemed to affect the outcome

I put some breakpoints in the SwiftFlutterTtsPlugin file, and it seems the method channel method setIosAudioCategory gets called, but for me the execution dies before self.setAudioCategory(...) is called with an error like Error Domain=NSOSStatusErrorDomain Code=2003329396 "(null)"

Slightly off topic: might be useful to add the descriptions from https://developer.apple.com/documentation/avfaudio/avaudiosession/mode to the IosTextToSpeechAudioMode enum, took me a little while to figure out how this enum related to TTS for ios with the namings being so different

Configuration

Version: 3.3.3

Platform:

  • [x] :iphone: iOS
  • [ ] :robot: Android

mvrsn avatar Dec 27 '21 18:12 mvrsn

thanks for the tip regarding documentation, I definitely need to do a better job with that. What outcome are you trying to accomplish?

did you try the following:

await flutterTts.setIosAudioCategory(IosTextToSpeechAudioCategory.ambient,
     [
          IosTextToSpeechAudioCategoryOptions.allowBluetooth,
          IosTextToSpeechAudioCategoryOptions.allowBluetoothA2DP,
          IosTextToSpeechAudioCategoryOptions.mixWithOthers
     ],
     IosTextToSpeechAudioMode.voicePrompt
);

dlutton avatar Dec 27 '21 20:12 dlutton

@dlutton yea but I have a feeling that it just works with the defaults, the background audio is no longer stopped

However, when I change to duckOthers there is no change in behavior, and according to the breakpoints the method never gets called successfully

mvrsn avatar Dec 27 '21 20:12 mvrsn

okay thanks I'll look into it @mvrsn

dlutton avatar Dec 27 '21 21:12 dlutton

It seems like there is something going wrong on line 278

let mode: AVAudioSession.Mode? = AudioModes(rawValue: audioMode ?? "")?.toAVAudioSessionMode() ?? AVAudioSession.Mode.default

When I run through the code with breakpoints the mode variable doesn't seem to initialize properly and then the Error Domain=NSOSStatusErrorDomain Code=2003329396 "(null)" error happens, possibly because of the ! in try audioSession.setCategory(category, mode: mode!, options: options)

I could try to look into it myself if you could give me some guidance on how to work with this project, shouldn't there be some project file in the repository, or how do you run the code in Xcode? Sorry if this is a dumb question but I'm very new to iOS development

mvrsn avatar Mar 11 '22 18:03 mvrsn

I see the same Error Domain=NSOSStatusErrorDomain Code=2003329396 "(null)" error in my logs.

Flutter 3.0.3 flutter_tts 3.4.0

wildsurfer avatar Jun 26 '22 13:06 wildsurfer

thank you @mvrsn and @wildsurfer, I'll commit some time into looking into this issue.

dlutton avatar Jun 26 '22 20:06 dlutton

Potential workaround:

I've found I only get this issue when trying to set the IosTextToSpeechAudioCategoryOptions.allowBluetooth and/or IosTextToSpeechAudioCategoryOptions.allowBluetoothA2DP categories, both of which are alluded to in the README's examples.

Removing the bluetooth categories from my call to setCategories allows for the remaining categories to be set — e.g., the mixing and ducking categories — without exception, and they seem to work as expected. Further, without including the bluetooth categories, audio still seems to work over bluetooth headphones, from my tested device, so I don't know what those categories are actually meant to do.

georgi0u avatar Aug 12 '22 14:08 georgi0u

Wow, took me a while to get back here and see this, and indeed you are correct @georgi0u, this solved my problem

@dlutton Maybe it would suffice to mention this in the docs or in the code for closing this issue to avoid having people getting stuck with this in the future?

mvrsn avatar Jan 02 '23 16:01 mvrsn

@mvrsn @georgi0u I'll update the docs and code with this information. thank you!

dlutton avatar Jan 02 '23 18:01 dlutton