原生js在浏览器中录制声音录音并文件下载代码

代码语言:html

所属分类:多媒体

代码描述:原生js在浏览器中录制声音录音并文件下载代码

代码标签: js 麦克风 录音 下载

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">





</head>

<body>
<h2>请不要在iframe中运行</h2>
    <div id="audio">
        <p>
            <button id=startRecord onclick="startRecording()">Start</button>
            <button id=stopRecord onclick="stopRecording()">Stop</button>
        </p>
        <p>
            <audio id=recordedAudio></audio>
        </p>
        <p>
            <a id=audioDownload></a>
        </p>
    </div>


    <script>
        navigator.mediaDevices.getUserMedia({
          audio: true }).
        
        then(stream => {
          rec = new MediaRecorder(stream);
          rec.ondataavailable = e => {
            audio.push(e.data);
            if (rec.state == "inactive") {
              let blob = new Blob(audio, {
                type: 'audio/wav; codecs=0' });
        
              recordedAudio.src = URL.createObjectURL(blob);
              recordedAudio.controls = true;
              audioDownload.href = recordedAudio.src.........完整代码请登录后点击上方下载按钮下载查看

网友评论0