Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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

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