Search code examples
react-nativeexpoaudio-streamingexpo-av

React Native Expo Audio | Send the audio in real time while recording it


I am trying to create a bird recognition application, so when I activate the recognition function, from the UI, I wish to be able to send it to the server in real-time for it to recognize the bird by its songs. Now I can only send it after I stop the recording.

I haven't been able to find any information online regarding this, or any work-around for it, yet.

Here is the recording function:


  async function startRecording() {
    try {
      const perm = await Audio.requestPermissionsAsync();
      if (perm.status === "granted") {
        await Audio.setAudioModeAsync({
          allowsRecordingIOS: true,
          playsInSilentModeIOS: true
        });
        const recordingInstance = new Audio.Recording();
        await recordingInstance.prepareToRecordAsync(Audio.RECORDING_OPTIONS_PRESET_HIGH_QUALITY);
        setRecording(recordingInstance);

      recordingInstance.setOnRecordingStatusUpdate((status) => {
        console.log("Base64 recording data:", status);
        console.log("uri: ", recordingInstance.getURI());
      });
        await recordingInstance.startAsync();

      }
    } catch (err) {
      console.error('Failed to start recording', err);
    }
  }

Has anyone done this before using expo? Any other suggestions are welcomed! Thanks!


Solution

  • You can try websockets, it is used for real time server connection, without the need to call apis. You may find what you are looking for in this link https://socket.io