katspaugh / wavesurfer.js

Audio waveform player
https://wavesurfer.xyz
BSD 3-Clause "New" or "Revised" License
8.61k stars 1.62k forks source link

I would like to request you to add a description of the startMic and startRecording functions of RecordPlugin to the official document #3666

Closed milk717 closed 5 days ago

milk717 commented 4 months ago

Bug description

If RecordPlugin calls the startRecording function first and then the startMic function, the stream that was created by the startRecording call is overwritten by the startMic function call, making the first stream that was created indefinitely. Therefore, it would be good if you could state in the official document that you need to call startMic before startRecording. I didn't know these things, so I spent a lot of time trying to solve the issue of audio not shutting down. If you try the code below, press the micro first button and press the stop audio button, the audio will end normally. However, if you shut down the audio after pressing the recording first button, the audio will not end. I think adding these warnings to the document will reduce unnecessary time for many people due to this issue.

Environment

export default function Home() { const recorderRef = useRef<RecordPlugin | null>(null); useEffect(() => { const waveSurferInstance = WaveSurfer.create({ container: '#waveform', }); const recorderInstance = waveSurferInstance.registerPlugin( RecordPlugin.create({ scrollingWaveform: true, renderRecordedAudio: false, mimeType: MediaRecorder.isTypeSupported('audio/webm') ? 'audio/webm;codecs=pcm' : 'audio/mp4', }) );

    recorderRef.current = recorderInstance;
}, []);

const handleMicFirstButtonClick = async() => {
    await recorderRef.current?.startMic()
    recorderRef.current?.startRecording();
}

const handleRecordingFirstButtonClick = () => {
    recorderRef.current?.startRecording();
    recorderRef.current?.startMic()
}

const handleStopBoth = () => {
    recorderRef.current?.stopMic();
}

return (
    <main className="flex" id="waveform">
        <button className="p-4 border" onClick={handleMicFirstButtonClick}>mic first</button>
        <button className="p-4 border" onClick={handleRecordingFirstButtonClick}>recording first</button>
        <button className="p-4 border" onClick={handleStopBoth}>stop audio</button>
    </main>
);

}



## Expected result

## Obtained result

## Screenshots

https://github.com/katspaugh/wavesurfer.js/assets/57657868/31b1e02b-0e2c-4036-893e-d6f0e48eec5c
entonbiba commented 1 month ago

@milk717 add this as a feature request discussion item instead, https://github.com/katspaugh/wavesurfer.js/discussions