Skip to content
Permalink
df5288289f
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
28 lines (21 sloc) 621 Bytes
const fs = require('fs');
const lame = require('lame');
// Pipe the live voice input into an mp3 file
async function toMp3(nickname, audioStream) {
nickname.replace(/[^a-z0-9]/gi, '_').toLowerCase();
const mp3path = `./tmp/${nickname}_${Date.now()}.mp3`;
var encoder = new lame.Encoder({
// input
channels: 2,
bitDepth: 16,
sampleRate: 48000,
// output
bitRate: 128,
outSampleRate: 16000,
mode: lame.MONO
});
audioStream.pipe(encoder);
encoder.pipe(fs.createWriteStream(mp3path));
return mp3path;
}
exports.toMp3 = toMp3;