mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
added volume control
This commit is contained in:
@@ -62,22 +62,14 @@ var AudioEncoder = (function () {
|
||||
return "help";
|
||||
};
|
||||
|
||||
AudioEncoder.prototype.encodeStream = function encodeStream(stream) {
|
||||
var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err, buffer) {} : arguments[1];
|
||||
|
||||
AudioEncoder.prototype.encodeStream = function encodeStream(stream, options) {
|
||||
var self = this;
|
||||
return new Promise(function (resolve, reject) {
|
||||
var enc = _child_process2["default"].spawn(self.getCommand(), ['-loglevel', '0', '-i', '-', '-f', 's16le', '-ar', '48000', '-ac', 2, 'pipe:1'], { stdio: ['pipe', 'pipe', 'ignore'] });
|
||||
var enc = _child_process2["default"].spawn(self.getCommand(), ['-loglevel', '0', '-i', '-', '-f', 's16le', '-ar', '48000', '-ac', 2, 'pipe:1', '-af', 'volume=' + (options.volume || 1)], { stdio: ['pipe', 'pipe', 'ignore'] });
|
||||
|
||||
stream.pipe(enc.stdin);
|
||||
|
||||
enc.stdout.once("readable", function () {
|
||||
callback(null, {
|
||||
proc: enc,
|
||||
stream: enc.stdout,
|
||||
instream: stream,
|
||||
channels: 2
|
||||
});
|
||||
resolve({
|
||||
proc: enc,
|
||||
stream: enc.stdout,
|
||||
@@ -87,30 +79,23 @@ var AudioEncoder = (function () {
|
||||
});
|
||||
|
||||
enc.stdout.on("end", function () {
|
||||
callback("end");
|
||||
reject("end");
|
||||
});
|
||||
|
||||
enc.stdout.on("close", function () {
|
||||
callback("close");
|
||||
reject("close");
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
AudioEncoder.prototype.encodeFile = function encodeFile(file) {
|
||||
var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err, buffer) {} : arguments[1];
|
||||
|
||||
AudioEncoder.prototype.encodeFile = function encodeFile(file, options) {
|
||||
var self = this;
|
||||
return new Promise(function (resolve, reject) {
|
||||
var enc = _child_process2["default"].spawn(self.getCommand(), ['-loglevel', '0', '-i', file, '-f', 's16le', '-ar', '48000', '-ac', 2, 'pipe:1'], { stdio: ['pipe', 'pipe', 'ignore'] });
|
||||
var enc = _child_process2["default"].spawn(self.getCommand(), ['-loglevel', '0', '-i', file, '-f', 's16le', '-ar', '48000', '-ac', 2, 'pipe:1', '-af', '"volume=' + (options.volume || 1) + '"'], { stdio: ['pipe', 'pipe', 'ignore'] });
|
||||
|
||||
console.log(['-loglevel', '0', '-i', file, '-f', 's16le', '-ar', '48000', '-af', '"volume=' + (options.volume || 1) + '"', '-ac', 2, 'pipe:1'].join(" "));
|
||||
|
||||
enc.stdout.once("readable", function () {
|
||||
callback(null, {
|
||||
proc: enc,
|
||||
stream: enc.stdout,
|
||||
channels: 2
|
||||
});
|
||||
resolve({
|
||||
proc: enc,
|
||||
stream: enc.stdout,
|
||||
@@ -120,13 +105,11 @@ var AudioEncoder = (function () {
|
||||
|
||||
enc.stdout.on("end", function () {
|
||||
console.log("end");
|
||||
callback("end");
|
||||
reject("end");
|
||||
});
|
||||
|
||||
enc.stdout.on("close", function () {
|
||||
console.log("close");
|
||||
callback("close");
|
||||
reject("close");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -233,11 +233,17 @@ var VoiceConnection = (function (_EventEmitter) {
|
||||
VoiceConnection.prototype.playFile = function playFile(stream) {
|
||||
var _this = this;
|
||||
|
||||
var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err, str) {} : arguments[1];
|
||||
var options = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1];
|
||||
var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, str) {} : arguments[2];
|
||||
|
||||
var self = this;
|
||||
if (typeof options === "function") {
|
||||
// options is the callback
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
return new Promise(function (resolve, reject) {
|
||||
_this.encoder.encodeFile(stream)["catch"](error).then(function (data) {
|
||||
_this.encoder.encodeFile(stream, options)["catch"](error).then(function (data) {
|
||||
self.streamProc = data.proc;
|
||||
var intent = self.playStream(data.stream, 2);
|
||||
resolve(intent);
|
||||
@@ -255,11 +261,17 @@ var VoiceConnection = (function (_EventEmitter) {
|
||||
VoiceConnection.prototype.playRawStream = function playRawStream(stream) {
|
||||
var _this2 = this;
|
||||
|
||||
var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err, str) {} : arguments[1];
|
||||
var options = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1];
|
||||
var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, str) {} : arguments[2];
|
||||
|
||||
var self = this;
|
||||
if (typeof options === "function") {
|
||||
// options is the callback
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
return new Promise(function (resolve, reject) {
|
||||
_this2.encoder.encodeStream(stream)["catch"](error).then(function (data) {
|
||||
_this2.encoder.encodeStream(stream, options)["catch"](error).then(function (data) {
|
||||
self.streamProc = data.proc;
|
||||
self.instream = data.instream;
|
||||
var intent = self.playStream(data.stream);
|
||||
|
||||
@@ -41,7 +41,7 @@ export default class AudioEncoder {
|
||||
return "help";
|
||||
}
|
||||
|
||||
encodeStream(stream, callback = function (err, buffer) { }) {
|
||||
encodeStream(stream, options) {
|
||||
var self = this;
|
||||
return new Promise((resolve, reject) => {
|
||||
var enc = cpoc.spawn(self.getCommand(), [
|
||||
@@ -50,18 +50,13 @@ export default class AudioEncoder {
|
||||
'-f', 's16le',
|
||||
'-ar', '48000',
|
||||
'-ac', 2,
|
||||
'pipe:1'
|
||||
'pipe:1',
|
||||
'-af', 'volume=' + (options.volume || 1)
|
||||
], {stdio: ['pipe', 'pipe', 'ignore']});
|
||||
|
||||
stream.pipe(enc.stdin);
|
||||
|
||||
enc.stdout.once("readable", function () {
|
||||
callback(null, {
|
||||
proc: enc,
|
||||
stream: enc.stdout,
|
||||
instream: stream,
|
||||
channels : 2
|
||||
});
|
||||
resolve({
|
||||
proc: enc,
|
||||
stream: enc.stdout,
|
||||
@@ -71,18 +66,16 @@ export default class AudioEncoder {
|
||||
});
|
||||
|
||||
enc.stdout.on("end", function () {
|
||||
callback("end");
|
||||
reject("end");
|
||||
});
|
||||
|
||||
enc.stdout.on("close", function () {
|
||||
callback("close");
|
||||
reject("close");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
encodeFile(file, callback = function (err, buffer) { }) {
|
||||
encodeFile(file, options) {
|
||||
var self = this;
|
||||
return new Promise((resolve, reject) => {
|
||||
var enc = cpoc.spawn(self.getCommand(), [
|
||||
@@ -91,15 +84,21 @@ export default class AudioEncoder {
|
||||
'-f', 's16le',
|
||||
'-ar', '48000',
|
||||
'-ac', 2,
|
||||
'pipe:1'
|
||||
], {stdio: ['pipe', 'pipe', 'ignore']});
|
||||
'pipe:1',
|
||||
'-af', '"volume=' + (options.volume || 1)+'"'
|
||||
], { stdio: ['pipe', 'pipe', 'ignore'] });
|
||||
|
||||
console.log([
|
||||
'-loglevel', '0',
|
||||
'-i', file,
|
||||
'-f', 's16le',
|
||||
'-ar', '48000',
|
||||
'-af', '"volume=' + (options.volume || 1) + '"',
|
||||
'-ac', 2,
|
||||
'pipe:1',
|
||||
].join(" "));
|
||||
|
||||
enc.stdout.once("readable", function () {
|
||||
callback(null, {
|
||||
proc: enc,
|
||||
stream: enc.stdout,
|
||||
channels : 2
|
||||
});
|
||||
resolve({
|
||||
proc: enc,
|
||||
stream: enc.stdout,
|
||||
@@ -109,13 +108,11 @@ export default class AudioEncoder {
|
||||
|
||||
enc.stdout.on("end", function () {
|
||||
console.log("end");
|
||||
callback("end");
|
||||
reject("end");
|
||||
});
|
||||
|
||||
enc.stdout.on("close", function () {
|
||||
console.log("close");
|
||||
callback("close");
|
||||
reject("close");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -205,11 +205,16 @@ export default class VoiceConnection extends EventEmitter {
|
||||
})
|
||||
}
|
||||
|
||||
playFile(stream, callback = function (err, str) { }) {
|
||||
playFile(stream, options=false, callback = function (err, str) { }) {
|
||||
var self = this;
|
||||
if (typeof options === "function") {
|
||||
// options is the callback
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
this.encoder
|
||||
.encodeFile(stream)
|
||||
.encodeFile(stream, options)
|
||||
.catch(error)
|
||||
.then(data => {
|
||||
self.streamProc = data.proc;
|
||||
@@ -225,11 +230,16 @@ export default class VoiceConnection extends EventEmitter {
|
||||
})
|
||||
}
|
||||
|
||||
playRawStream(stream, callback = function (err, str) { }) {
|
||||
playRawStream(stream, options=false, callback = function (err, str) { }) {
|
||||
var self = this;
|
||||
if (typeof options === "function") {
|
||||
// options is the callback
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
this.encoder
|
||||
.encodeStream(stream)
|
||||
.encodeStream(stream, options)
|
||||
.catch(error)
|
||||
.then(data => {
|
||||
self.streamProc = data.proc;
|
||||
|
||||
@@ -33,9 +33,9 @@ client.on("message", msg => {
|
||||
if (msg.content.startsWith("$play")) {
|
||||
var url = msg.content.split(" ")[1];
|
||||
|
||||
client.voiceConnection.playFile(url);
|
||||
|
||||
console.log(request.get(url).end());
|
||||
client.voiceConnection.playFile(url, {
|
||||
volume : 0.1
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -49,10 +49,6 @@ console.log("INIT");
|
||||
|
||||
client.on("debug", console.log);
|
||||
|
||||
client.on("unknown", p => {
|
||||
console.log(p);
|
||||
});
|
||||
|
||||
client.login(process.env["ds_email"], process.env["ds_password"]).catch(console.log);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user