Permalink
Cannot retrieve contributors at this time
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?
DCC-Server/toMp3.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
28 lines (21 sloc)
621 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |