flutter_tts icon indicating copy to clipboard operation
flutter_tts copied to clipboard

Background play and sound mix not working ( setSharedInstance() not working )

Open hola726 opened this issue 2 years ago • 1 comments

🐛 Bug Report

Expected behavior

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

above method doesn't work

import UIKit
import AVFAudio
import Flutter

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    let audioSession = AVAudioSession.sharedInstance()
      do {
          try audioSession.setCategory(AVAudioSession.Category.playback,mode: AVAudioSession.Mode.voicePrompt, options:[AVAudioSession.CategoryOptions.mixWithOthers,AVAudioSession.CategoryOptions.duckOthers] )
          } catch {
              print("Setting category to AVAudioSessionCategoryPlayback failed.")
          }
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

I solved the background playback and other sounds and mixes by adding an audio session directly to ios native.

Configuration

Version: 3.5.3

Platform:

  • [x] :iphone: iOS ( iOS 16 )
  • [ ] :robot: Android

hola726 avatar Sep 16 '22 05:09 hola726

thanks mate~

KerwinCheung avatar Mar 17 '23 08:03 KerwinCheung