casual-simulation / casualos

Casual Open Simulation for the Web
https://ab1.bot
MIT License
49 stars 9 forks source link

Fixed MediaAudioRecorder when set to stream mode. #282

Closed Blitzy closed 1 year ago

Blitzy commented 1 year ago

This PR fixes a bug with os.beginAudioRecording when set to stream: true and a mimeType of anything other than audio/x-raw.

Previously MediaAudioRecorder was providing empty Blob data to @onAudioChunk when running the MediaAudioRecorder with stream: true and an audio encoding format (ie mimeType: 'audio/webm'). The fix is to provide the buffer rate to the recorder's start() function which accepts a timeslice argument. When timeslice is provided, the recorder's dataavailable event gets triggered properly and @onAudioChunk gets the Blob chunks as originally intended.

Another alteration included in this PR is to await the finalBlobPromise before invoking dataAvailable.complete(). This gives the recorder time to stop and call its final dataavailable event with the remaining Blob data before finalizing and cleaning up.