[英]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.