【发布时间】:2014-06-06 18:58:23
【问题描述】:
我正在开发一个带有麦克风的无线电系统,系统管理员将对麦克风讲话,音频将实时传输给用户......我是使用 node.js 的新手,我不确定如何使从麦克风到用户的音频流...有人可以帮助我吗?
我有以下问题,我将麦克风中的音频记录在一个 blob 中,我需要知道如何直播这个 blob ...
我没有要显示的代码,只提供录音...
<script>
function getByID(id) {
return document.getElementById(id);
}
var recordAudio = getByID('record-audio'),
stopRecordingAudio = getByID('stop-recording-audio');
var audio = getByID('audio');
var audioConstraints = {
audio: true,
video: false
};
</script>
<script>
var audioStream;
var recorder;
recordAudio.onclick = function() {
if (!audioStream)
navigator.getUserMedia(audioConstraints, function(stream) {
if (window.IsChrome) stream = new window.MediaStream(stream.getAudioTracks());
audioStream = stream;
audio.src = URL.createObjectURL(audioStream);
audio.muted = true;
audio.play();
// "audio" is a default type
recorder = window.RecordRTC(stream, {
type: 'audio'
});
recorder.startRecording();
}, function() {
});
else {
audio.src = URL.createObjectURL(audioStream);
audio.muted = true;
audio.play();
if (recorder) recorder.startRecording();
}
window.isAudio = true;
this.disabled = true;
stopRecordingAudio.disabled = false;
};
stopRecordingAudio.onclick = function() {
this.disabled = true;
recordAudio.disabled = false;
audio.src = '';
if (recorder)
recorder.stopRecording(function(url) {
audio.src = url;
audio.muted = false;
audio.play();
document.getElementById('audio-url-preview').innerHTML = '<a href="' + url + '" target="_blank">Recorded Audio URL</a>';
});
};
</script>
【问题讨论】:
-
但是WebRTC并不容易,我没有弄清楚如何
标签: javascript html node.js