我已经有一个使用麦克风将数据流式传输到<audio>
标签的工作页面。
但是,我希望收集发送到我的<audio>
标签的数据。您认为如何收集流式传输的数据并将其持续流式传输到 Node.js 服务器?(我将使用 Binaryjs 进行二进制数据流传输。)
这是我幸运的代码。:)
<audio src="" id="audio" controls="controls">Sad twinkletoes does not have audio.</audio><br>
<br>
<span id="aw"></span>
<script>
try {
navigator.getMedia = ( navigator.getUserMedia || navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||navigator.msGetUserMedia);
navigator.getMedia ({
audio: true
},
function(stream) {
var audio = document.getElementById('audio');
var streamer = window.URL.createObjectURL(stream);
audio.src = streamer;
var loopertime = 3;
var looper = setInterval(function() {
if(loopertime == 0) {
clearInterval(looper);
audio.play();
// stream starts here!
var spanner = document.getElementById('aw');
spanner.innerHTML = '<code>Streaming...</code>';
// this is where I want the data to be streamed...
} else {
audio.play();
setTimeout(function() {
audio.pause();
},10);
loopertime--; // played and paused 3 times... getaround for audio only not working
}
},15);
},
function(err) {
// No permissions
}
);
}
catch(e) {
alert('Your browser does not support HTML5 Audio Media.');
console.log(e);
}
</script>