Fixed order

This commit is contained in:
hydrabolt
2015-11-08 16:31:33 +00:00
parent 412a1b0f27
commit 36e40d1b35
2 changed files with 52 additions and 2 deletions

View File

@@ -19,6 +19,7 @@ var AudioEncoder = (function () {
if (opus) {
this.opus = new opus.OpusEncoder(48000, 1);
}
this.choice = false;
}
AudioEncoder.prototype.opusBuffer = function opusBuffer(buffer) {
@@ -26,12 +27,42 @@ var AudioEncoder = (function () {
return this.opus.encode(buffer, 1920);
};
AudioEncoder.prototype.getCommand = function getCommand(force) {
if (this.choice && force) return choice;
var choices = ["avconv", "ffmpeg"];
for (var _iterator = choices, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var choice = _ref;
var p = cpoc.spawnSync(choice);
if (!p.error) {
this.choice = choice;
return choice;
}
}
return "help";
};
AudioEncoder.prototype.encodeStream = function encodeStream(stream) {
var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err, buffer) {} : arguments[1];
var self = this;
return new Promise(function (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.
var enc = cpoc.spawn(self.getCommand(), ["-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", "-"]);
stream.pipe(enc.stdin);

View File

@@ -15,6 +15,7 @@ class AudioEncoder{
if(opus){
this.opus = new opus.OpusEncoder(48000, 1);
}
this.choice = false;
}
opusBuffer(buffer){
@@ -23,10 +24,28 @@ class AudioEncoder{
}
getCommand(force){
if(this.choice && force)
return choice;
var choices = ["avconv", "ffmpeg"];
for(var choice of choices){
var p = cpoc.spawnSync(choice);
if(!p.error){
this.choice = choice;
return choice;
}
}
return "help";
}
encodeStream(stream, callback=function(err, buffer){}){
var self = this;
return new Promise((resolve, reject) => {
var enc = cpoc.spawn("ffmpeg" , [
var enc = cpoc.spawn(self.getCommand() , [
"-f", "s16le",
"-ar", "48000",
"-ac", "1", // this can be 2 but there's no point, discord makes it mono on playback, wasted bandwidth.