Return audio on finishing playing sound by Speech

import * as Speech from "expo-speech";
Speech.speak("a word");

I implemented Expo Speech in my app. This works well.
But I want to return audio on finishing playing sound.

  • Listening to music or podcast which is played by another app.
  • Play sound by Speech in Expo app
  • Resume music or podcast

Is this possible?

For example, the Google map app can do this. Navigation interrupts music or podcast, but get back to music or podcast.

Hey yosukep, I found a possible solution about this issue.

You can wrap your Speech function in the Audio Api.

https://docs.expo.io/versions/latest/sdk/audio/

    // config setup
    Audio.setAudioModeAsync({
        playsInSilentModeIOS: true,
        allowsRecordingIOS: false,
        staysActiveInBackground: false,
        interruptionModeIOS: Audio.INTERRUPTION_MODE_IOS_DUCK_OTHERS, // INTERRUPTION_MODE_IOS_DO_NOT_MIX does not return to audio
        shouldDuckAndroid: false,
        interruptionModeAndroid: Audio.INTERRUPTION_MODE_ANDROID_DUCK_OTHERS,
        playThroughEarpieceAndroid: true,
    });

    const soundObject = new Audio.Sound();

    try {
        await soundObject.loadAsync(require(SILENCE_AUDIO_FILE));
        await soundObject.playAsync();

        // be sure your SILENCE_AUDIO_FILE is long enough
        Speech.speak(TEXT);
    } catch (error) {
        // handle error
    }

Use a silence audio file from https://github.com/anars/blank-audio or your own one.
I`m not sure if is possible to stop the music completely.