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

Get recorded audio when paused #834

Open
cjambrosi opened this issue Apr 10, 2023 · 2 comments
Open

Get recorded audio when paused #834

cjambrosi opened this issue Apr 10, 2023 · 2 comments

Comments

@cjambrosi
Copy link

cjambrosi commented Apr 10, 2023

Is it possible to pause and resume like WhatsApp Web?
For example, when I click on the pause button, get the audio recorded so far?

If not, can someone give me an idea how to do it?

@damiaanh
Copy link

damiaanh commented Oct 5, 2023

Yes this is possible using timeSlice to make data available on a certain interval. see this link for more info on this API.

  1. Create a recorder the following options:
recorderType: MediaStreamRecorder, // need to set this recorderType to pass the timeSlice option.
timeSlice: 1000, // or another value that you want to make the recording available on.

i.e.:

 var myRecorder = new RecordRTC(stream, {
            type: "audio",
            recorderType: MediaStreamRecorder,
            mimeType: "audio/webm;codecs=opus",
            timeSlice: 1000,
        });
  1. Since a blob is now created for every second, we have to create one big blob when you pause the recorder:
myRecorder.pauseRecording();
var internal = myRecorder.getInternalRecorder();
if (internal && internal.getArrayOfBlobs) {
        var blob = new Blob(internal.getArrayOfBlobs(), {
            type: "audio",
        });
    }
  1. if needed, create an object url for the blob:
  const myUrl = URL.createObjectURL(blob));

Based on this great example on handling onDataAvailable with recordRTC.

@cjambrosi
Copy link
Author

Excellent! Thank you very much @damiaanh. I'll try here

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

No branches or pull requests

2 participants