Skip to content

Comments

Fix audio session conflict with other voice instances on iOS#276

Open
Taegon21 wants to merge 1 commit intoak1394:masterfrom
Taegon21:fix/audio-session-conflict
Open

Fix audio session conflict with other voice instances on iOS#276
Taegon21 wants to merge 1 commit intoak1394:masterfrom
Taegon21:fix/audio-session-conflict

Conversation

@Taegon21
Copy link

@Taegon21 Taegon21 commented Jan 18, 2025

Problem

When using this TTS library alongside other voice-related libraries (like @react-native-voice/voice), TTS sometimes stops working on IOS. This occurs because the audio session is reset (e.g., other libraries reset the audio session), which interferes with TTS functionality.

Solution

Ensures that TTS functionality remains stable when starting TTS by resolving conflicts with other voice instances.

  1. Automatically reconfigures the audio session at the start of each utterance.
  2. Prevents audio session conflicts with other voice recognition libraries.

Changes

(void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didStartSpeechUtterance:(AVSpeechUtterance *)utterance
{
+    [[AVAudioSession sharedInstance]
+     setCategory:AVAudioSessionCategoryPlayback
+     mode:AVAudioSessionModeVoicePrompt
+     options:AVAudioSessionCategoryOptionInterruptSpokenAudioAndMixWithOthers
+     error:nil];
    
    if(_ducking) {
        [[AVAudioSession sharedInstance] setActive:YES error:nil];
    }

    [self sendEventWithName:@"tts-start" body:@{@"utteranceId":[NSNumber numberWithUnsignedLong:utterance.hash]}];
}

Resolves #275

el-lsan added a commit to el-lsan/react-native-tts that referenced this pull request Dec 27, 2025
- Configure AVAudioSession in didStartSpeechUtterance to prevent conflicts
- Set category to Playback with VoicePrompt mode
- Use InterruptSpokenAudioAndMixWithOthers option for better audio handling

Fixes from PR ak1394#276 by Taegon21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TTS fails to work due to audio session conflicts on iOS

1 participant