Skip to content

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