voice fixes

This commit is contained in:
Amish Shah
2015-12-05 20:57:08 +00:00
parent de19475ae0
commit d122184b6b
6 changed files with 87 additions and 50 deletions

1
.gitignore vendored
View File

@@ -36,5 +36,4 @@ build/Release
node_modules node_modules
test/auth.json test/auth.json
examples/auth.json examples/auth.json
test/msgbot.js
docs/_build docs/_build

View File

@@ -67,8 +67,7 @@ var AudioEncoder = (function () {
var self = this; var self = this;
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
var enc = _child_process2["default"].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. var enc = _child_process2["default"].spawn(self.getCommand(), ['-i', "-", '-f', 's16le', '-ar', '48000', '-ac', 1, 'pipe:1']);
"-af", "volume=1", "pipe:1", "-i", "-"]);
stream.pipe(enc.stdin); stream.pipe(enc.stdin);
@@ -102,8 +101,7 @@ var AudioEncoder = (function () {
var self = this; var self = this;
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
var enc = _child_process2["default"].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. var enc = _child_process2["default"].spawn(self.getCommand(), ['-i', file, '-f', 's16le', '-ar', '48000', '-ac', 1, 'pipe:1']);
"-af", "volume=1", "pipe:1", "-i", file]);
enc.stdout.once("readable", function () { enc.stdout.once("readable", function () {
callback(null, { callback(null, {
@@ -117,11 +115,13 @@ var AudioEncoder = (function () {
}); });
enc.stdout.on("end", function () { enc.stdout.on("end", function () {
console.log("end");
callback("end"); callback("end");
reject("end"); reject("end");
}); });
enc.stdout.on("close", function () { enc.stdout.on("close", function () {
console.log("close");
callback("close"); callback("close");
reject("close"); reject("close");
}); });

View File

@@ -122,11 +122,10 @@ var VoiceConnection = (function (_EventEmitter) {
self.playingIntent = retStream; self.playingIntent = retStream;
function send() { function send() {
if (!self.playingIntent || !self.playing) { if (!self.playingIntent || !self.playing) {
self.setSpeaking(false); self.setSpeaking(false);
retStream.emit("end"); retStream.emit("end");
self; console.log("ending 1");
return; return;
} }
try { try {
@@ -137,6 +136,7 @@ var VoiceConnection = (function (_EventEmitter) {
if (onWarning) { if (onWarning) {
retStream.emit("end"); retStream.emit("end");
self.setSpeaking(false); self.setSpeaking(false);
console.log("ending 2");
return; return;
} else { } else {
onWarning = true; onWarning = true;

View File

@@ -45,12 +45,11 @@ export default class AudioEncoder {
var self = this; var self = this;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
var enc = cpoc.spawn(self.getCommand(), [ var enc = cpoc.spawn(self.getCommand(), [
"-f", "s16le", '-i', "-",
"-ar", "48000", '-f', 's16le',
"-ac", "1", // this can be 2 but there's no point, discord makes it mono on playback, wasted bandwidth. '-ar', '48000',
"-af", "volume=1", '-ac', 1,
"pipe:1", 'pipe:1'
"-i", "-"
]); ]);
stream.pipe(enc.stdin); stream.pipe(enc.stdin);
@@ -84,12 +83,11 @@ export default class AudioEncoder {
var self = this; var self = this;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
var enc = cpoc.spawn(self.getCommand(), [ var enc = cpoc.spawn(self.getCommand(), [
"-f", "s16le", '-i', file,
"-ar", "48000", '-f', 's16le',
"-ac", "1", // this can be 2 but there's no point, discord makes it mono on playback, wasted bandwidth. '-ar', '48000',
"-af", "volume=1", '-ac', 1,
"pipe:1", 'pipe:1'
"-i", file
]); ]);
enc.stdout.once("readable", function () { enc.stdout.once("readable", function () {
@@ -104,11 +102,13 @@ export default class AudioEncoder {
}); });
enc.stdout.on("end", function () { enc.stdout.on("end", function () {
console.log("end");
callback("end"); callback("end");
reject("end"); reject("end");
}); });
enc.stdout.on("close", function () { enc.stdout.on("close", function () {
console.log("close");
callback("close"); callback("close");
reject("close"); reject("close");
}); });

View File

@@ -93,11 +93,10 @@ export default class VoiceConnection extends EventEmitter {
self.playingIntent = retStream; self.playingIntent = retStream;
function send() { function send() {
if (!self.playingIntent || !self.playing) { if (!self.playingIntent || !self.playing) {
self.setSpeaking(false); self.setSpeaking(false);
retStream.emit("end"); retStream.emit("end");
self console.log("ending 1");
return; return;
} }
try { try {
@@ -108,6 +107,7 @@ export default class VoiceConnection extends EventEmitter {
if (onWarning) { if (onWarning) {
retStream.emit("end"); retStream.emit("end");
self.setSpeaking(false); self.setSpeaking(false);
console.log("ending 2");
return; return;
} else { } else {
onWarning = true; onWarning = true;

38
test/msgbot.js Normal file
View File

@@ -0,0 +1,38 @@
/* global describe */
/* global process */
var Discord = require("../");
var client = new Discord.Client();
var request = require("request");
client.on("ready", () => {
console.log("ready");
});
client.on("message", msg => {
if(!msg.sender.equals(client.user))
console.log("received message from " + msg.sender.username);
if (msg.content === "$bind") {
msg.channel.server.channels.get("type", "voice").join();
}
if (msg.content.startsWith("$play")) {
var url = msg.content.split(" ")[1];
client.voiceConnection.playRawStream(request(url));
}
if (msg.content === "$$$") {
client.sendMessage(msg.sender, "hi!");
}
});
console.log("INIT");
client.on("debug", console.log)
client.login(process.env["ds_email"], process.env["ds_password"]).catch(console.log);