fix(audio): optimize audio configuration for iOS and Android platforms

This commit is contained in:
cogwheel0
2025-11-27 18:41:41 +05:30
parent 852a65f870
commit d092bb2e44
7 changed files with 276 additions and 267 deletions

View File

@@ -70,20 +70,12 @@ class TextToSpeechService {
}
});
if (!kIsWeb && Platform.isIOS) {
final context = AudioContext(
iOS: AudioContextIOS(
category: AVAudioSessionCategory.playAndRecord,
options: const {
AVAudioSessionOptions.defaultToSpeaker,
AVAudioSessionOptions.mixWithOthers,
AVAudioSessionOptions.allowBluetooth,
AVAudioSessionOptions.allowBluetoothA2DP,
},
if (!kIsWeb && Platform.isAndroid) {
_player.setAudioContext(
AudioContext(
android: const AudioContextAndroid(),
),
android: const AudioContextAndroid(),
);
_player.setAudioContext(context);
}
}
@@ -103,13 +95,8 @@ class TextToSpeechService {
if (!kIsWeb && Platform.isIOS) {
await _tts.setSharedInstance(true);
await _tts
.setIosAudioCategory(IosTextToSpeechAudioCategory.playAndRecord, [
IosTextToSpeechAudioCategoryOptions.mixWithOthers,
IosTextToSpeechAudioCategoryOptions.defaultToSpeaker,
IosTextToSpeechAudioCategoryOptions.allowBluetooth,
IosTextToSpeechAudioCategoryOptions.allowBluetoothA2DP,
]);
// Rely on the native VoiceBackgroundAudioManager for iOS
// audio session configuration to avoid routing conflicts.
}
if (_engine != TtsEngine.server) {