简体   繁体   English

如何在浏览器中使用手机麦克风录制?

[英]How to record using phone microphone on browsers?

I am trying to record a voice from browsers but it only works on chrome browser in my mac but the same doesn't work in any other browser. 我正在尝试从浏览器录制声音,但它只能在Mac上的chrome浏览器上使用,但不能在其他任何浏览器上使用。 My goal is to record the voice from a phone from a browser. 我的目标是从浏览器记录电话中的语音。

I have been trying this below example but it doesn't works on mobile browsers. 我一直在尝试下面的示例,但不适用于移动浏览器。 It opens up the microphone but doesn't stop recording and never plays it back. 它会打开麦克风,但不会停止录音,也不会播放。

I think the problem is somewhere around recorder.stop() which doesn't get called. 我认为问题出在recorder.stop()周围,但没有被调用。

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>

</script>
</head>

<body>
 <audio controls autoplay></audio>
<script type="text/javascript" src="recorder.js"> </script>

<input onclick="startRecording()" type="button" value="start recording" />
<input onclick="stopRecording()" type="button" value="stop recording and play" />

<script>
  var onFail = function(e) {
    console.log('Rejected!', e);
  };

  var onSuccess = function(s) {
    var context = new webkitAudioContext();
    var mediaStreamSource = context.createMediaStreamSource(s);
    recorder = new Recorder(mediaStreamSource);
    recorder.record();

    // audio loopback
    // mediaStreamSource.connect(context.destination);
  }

  window.URL = window.URL || window.webkitURL;
  navigator.getUserMedia  = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;

  var recorder;
  var audio = document.querySelector('audio');

  function startRecording() {
    if (navigator.getUserMedia) {
      navigator.getUserMedia({audio: true}, onSuccess, onFail);
    } else {
      console.log('navigator.getUserMedia not present');
    }
  }

  function stopRecording() {
    //alert("hello");
    recorder.stop();
    recorder.exportWAV(function(blob) {
      //audio.src = window.URL.createObjectURL(s);

      var url = URL.createObjectURL(blob);
                    audio.src = url;
                    audio.controls = true;
                    var hf = document.createElement('a');
                    hf.href = url;
                    hf.download = new Date().toISOString() + '.wav';
                    //upload(blob);   
                    audio.src = url;
    });

  }

  function upload(blobOrFile) {
    var xhr = new XMLHttpRequest();
    xhr.open('POST', '/upload.aspx', true);
    xhr.onload = function (e) {
        var result = e.target.result;
  };

    xhr.send(blobOrFile);
}
 </script>
 </body>
</html>

Only Chrome supports as of now the AudioContext interface. 到目前为止,只有Chrome支持AudioContext接口。 Firefox also has an implementation but only in the Nightly build. Firefox也有一个实现,但仅在Nightly构建中。

I'm not sure if it is supported by the mobile version of these browsers. 我不确定这些浏览器的移动版本是否支持它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用meteor js在android应用程序中录制来自麦克风的声音 - How to record sound from microphone in android app using meteor js 如何通过不使用内置麦克风在移动设备上的应用程序中录制音频 - How to record audio within a application on a mobile device, by not using the built in microphone 使用带有HTML5的用户麦克风录制音频 - Record Audio Using the Users Microphone with HTML5 如何使用 RecordRTC 录制屏幕+音频+麦克风 - How to record screen+audio+microphone with RecordRTC 如何在 JavaScript 中录制麦克风音频并提交给 DialogFlow? - How to record microphone audio in JavaScript and submit to DialogFlow? 任何人都可以建议如何使用html5和javascript在网站上录制麦克风的音频 - Can anyone suggest how to record audio from microphone on a website using html5 and javascript 无法在Rails环境中使用Recorder.js记录麦克风输入 - Can't record microphone input by using recorderjs in rails environment 使用 Web 音频 API 录制来自麦克风的低音量输入 - Record Low Volume Input from Microphone using Web Audio API 如何使用手机间隙在html5中录制音频 - how to record a audio in html5 using phone gap 如何更改onclick以便在手机浏览器上运行? - How to change onclick so it works on phone browsers?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM