我正在尝试通过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");
});