如何流式传输 Blob

5

我正在开发一个带麦克风的无线电系统,系统管理员会通过麦克风讲话,音频将实时传输给用户... 我是一个新手使用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>

1
但是WebRTC并不容易,我还没有弄清楚如何做。 - Alan PS
1个回答

2
我不是专家,但我记得在html5rocks上有几篇关于捕获音频的文章。

http://updates.html5rocks.com/2012/01/Web-Audio-FAQ http://www.html5rocks.com/en/tutorials/getusermedia/intro/#toc-webaudio-api

你应该尝试在npm库中搜索。我认为它可能有一些流式的节点模块。(从核心node.js API开始开发真的很难,我也无法理解。)
还要看看这个:
Node.js synchronized audio streaming between server and clients? 这里有用于发送二进制数据的节点模块(我认为它支持流式blob):http://binaryjs.com/ 希望这些能帮到你!

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接