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
test/auth.json
examples/auth.json
test/msgbot.js
docs/_build

View File

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

View File

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

View File

@@ -45,12 +45,11 @@ export default class AudioEncoder {
var self = this;
return new Promise((resolve, reject) => {
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", "-"
'-i', "-",
'-f', 's16le',
'-ar', '48000',
'-ac', 1,
'pipe:1'
]);
stream.pipe(enc.stdin);
@@ -84,12 +83,11 @@ export default class AudioEncoder {
var self = this;
return new Promise((resolve, reject) => {
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", file
'-i', file,
'-f', 's16le',
'-ar', '48000',
'-ac', 1,
'pipe:1'
]);
enc.stdout.once("readable", function () {
@@ -104,11 +102,13 @@ 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");
});

View File

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