mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 17:43:30 +01:00
playing stream
This commit is contained in:
@@ -23,16 +23,55 @@ class AudioEncoder{
|
||||
|
||||
}
|
||||
|
||||
encodeFile(file, callback=function(err, buffer){}){
|
||||
encodeStream(stream, callback=function(err, buffer){}){
|
||||
var self = this;
|
||||
return new Promise((resolve, reject) => {
|
||||
var enc = cpoc.spawn("ffmpeg" , [
|
||||
"-i", file,
|
||||
"-f", "s16le",
|
||||
"-ar", "48000",
|
||||
"-ac", "1", // this can be 2 but there's no point, discord makes it mono on playback, wasted bandwidth.
|
||||
"-af", "volume=1",
|
||||
"pipe:1"
|
||||
"pipe:1",
|
||||
"-i", "-"
|
||||
]);
|
||||
|
||||
stream.pipe(enc.stdin);
|
||||
|
||||
enc.stdout.once("readable", function() {
|
||||
callback(null, {
|
||||
proc : enc,
|
||||
stream : enc.stdout,
|
||||
instream : stream
|
||||
});
|
||||
resolve({
|
||||
proc : enc,
|
||||
stream : enc.stdout,
|
||||
instream : stream
|
||||
});
|
||||
});
|
||||
|
||||
enc.stdout.on("end", function() {
|
||||
callback("end");
|
||||
reject("end");
|
||||
});
|
||||
|
||||
enc.stdout.on("close", function() {
|
||||
callback("close");
|
||||
reject("close");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
encodeFile(file, callback=function(err, buffer){}){
|
||||
var self = this;
|
||||
return new Promise((resolve, reject) => {
|
||||
var enc = cpoc.spawn("ffmpeg" , [
|
||||
"-f", "s16le",
|
||||
"-ar", "48000",
|
||||
"-ac", "1", // this can be 2 but there's no point, discord makes it mono on playback, wasted bandwidth.
|
||||
"-af", "volume=1",
|
||||
"pipe:1",
|
||||
"-i", file
|
||||
]);
|
||||
|
||||
enc.stdout.once("readable", function() {
|
||||
@@ -45,7 +84,7 @@ class AudioEncoder{
|
||||
stream : enc.stdout
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
enc.stdout.on("end", function() {
|
||||
callback("end");
|
||||
reject("end");
|
||||
|
||||
Reference in New Issue
Block a user