通过Express流过麦克风的音频流无法在VLC媒体播放器(或其他任何设备)中播放

时间:2018-09-09 14:56:35

标签: node.js express streaming audio-streaming ogg

我正在尝试通过nodejs express将我的麦克风音频流传输到本地URL。

访问url时,它将连接并触发调试代码,但它不会开始播放音频,并且将继续无限加载。

var mic = require("mic");
var express = require("express");
var app = express();

var micInstance = mic({
    rate: "16000",
    channels: "1",
    //debug: true,
    fileType: "ogg"
});
let micInputStream = micInstance.getAudioStream();

micInputStream.on("error", function(err) {
    cosole.log("Error: " + err);
});

micInputStream.on("startComplete", function() {
    console.log("Started recording");
});
micInstance.start();

app.get("/stream.oga", function (req, res) {
    res.set("content-type", "audio/ogg");
    res.set("transfer-encoding", "chunked");

    micInputStream.on("data", function(data) {
        console.log("Writing chunk: " + data.length);
        res.write(data);
    });
    console.log("##DEBUG Started piping");

    //micInputStream.pipe(res);
});

app.listen(3000, () => {
    console.log("Listening on port 3000");
});

0 个答案:

没有答案