imgingerbear
imgingerbear

Reputation: 183

How to get audio buffers from the flutter webrtc plugin?

I am using the flutter-webrtc-plugin and would like to record both local and remote audio streams. Is there any way for me to get audio buffers from the media streams? I have tried using the AudioFileRenderer in the unified-plan branch. In the startRecording function of MediaRecorderImpl.java, I supplied the file storage path e.g. "storage/emulated/0/Android/data", a file is successfully created everytime I ended my call but the recording file is broken so it can't be played. There are no errors coming from the terminal. I'm using flutter v1.22.6 and forked the flutter-webrtc from 0.5.8. I added the AudioFileRenderer file to the flutter-webrtc 0.5.8, my code is as below:

public void startRecording(File file) throws Exception {
    recordFile = file;
    if (isRunning)
        return;
    isRunning = true;
    //noinspection ResultOfMethodCallIgnored
    file.getParentFile().mkdirs();
    if (videoTrack != null) {
      System.out.println("try123 1");
        videoFileRenderer = new VideoFileRenderer(
            file.getAbsolutePath(),
            EglUtils.getRootEglBaseContext(),
            audioInterceptor != null
        );
        videoTrack.addSink(videoFileRenderer);
        if (audioInterceptor != null)
            audioInterceptor.attachCallback(id, videoFileRenderer);
    } else {
        Log.e(TAG, "Video track is null");
        if (audioInterceptor != null) {
            //TODO(rostopira): audio only recording
            // throw new Exception("Audio-only recording not implemented yet");
     
            Log.d(TAG, "Try to use onWebrtcSamplesReady");
            audioFileRenderer = new AudioFileRenderer(file);
            audioInterceptor.attachCallback(id, audioFileRenderer);
        }
    }
}

Any help is appreciated! Thanks!

Upvotes: 2

Views: 1187

Answers (1)

Pitu Werno
Pitu Werno

Reputation: 123

I am also looking for the same solution, none has been found so far.

So, I am using webview for the the RTC part (communication & recording), while keeping the Firebase messaging and EventSource/SSE (I'm not using socket) in Flutter.

This is not directly answer your question, just providing alternative solution, it's better than having no solution at all, probably in the future when flutter RTC updated and supporting voice only recording, we can update the apps we develop.

Upvotes: 0

Related Questions