如何录制音频mp3 javascript

时间:2018-10-15 14:36:30

标签: javascript audio-recording

我正在开发一个网站,该网站需要将用户的语音记录为mp3文件。 我有这段代码,它将音频另存为webm文件,问题是如果下载文件,我将无法重新启动音频,并且无法收听特定的分钟。 这是我的代码:

  navigator.mediaDevices.getUserMedia({ audio: true }).then(function(microphone) {
  // preview camera during recording
  document.getElementById('your-video-id').style.display="none";
  document.getElementById('your-video-id').muted = true;
  setSrcObject(microphone, document.getElementById('your-video-id'));
  // recording configuration/hints/parameters
  var recordingHints = {
      type: 'audio'
  };
  // initiating the recorder
  var recorder = RecordRTC(microphone, recordingHints);
  // starting recording here
  recorder.startRecording();
  // auto stop recording after 5 seconds
  setTimeout(function() {
      // stop recording
      recorder.stopRecording(function() {

          // get recorded blob
          var blob = recorder.getBlob();
          // generating a random file name
          var fileName = getFileName('mp3');
          // we need to upload "File" --- not "Blob"
          var fileObject = new File([blob], fileName, {
              type: 'audio/mp3'
          });
          var storageRef = firebase.storage().ref(fileObject.name);
          storageRef.put(blob);
      });
  }, milliSeconds);
});

0 个答案:

没有答案