Added stereo support

This commit is contained in:
Amish Shah
2015-12-05 21:19:38 +00:00
parent d122184b6b
commit e16211c4fb
7 changed files with 167 additions and 35 deletions

View File

@@ -12,7 +12,7 @@ try {
export default class AudioEncoder {
constructor() {
if (opus) {
this.opus = new opus.OpusEncoder(48000, 1);
this.opus = new opus.OpusEncoder(48000, 2);
}
this.choice = false;
}
@@ -48,7 +48,7 @@ export default class AudioEncoder {
'-i', "-",
'-f', 's16le',
'-ar', '48000',
'-ac', 1,
'-ac', 2,
'pipe:1'
]);
@@ -58,12 +58,14 @@ export default class AudioEncoder {
callback(null, {
proc: enc,
stream: enc.stdout,
instream: stream
instream: stream,
channels : 2
});
resolve({
proc: enc,
stream: enc.stdout,
instream: stream
instream: stream,
channels : 2
});
});
@@ -86,18 +88,20 @@ export default class AudioEncoder {
'-i', file,
'-f', 's16le',
'-ar', '48000',
'-ac', 1,
'-ac', 2,
'pipe:1'
]);
enc.stdout.once("readable", function () {
callback(null, {
proc: enc,
stream: enc.stdout
stream: enc.stdout,
channels : 2
});
resolve({
proc: enc,
stream: enc.stdout
stream: enc.stdout,
channels : 2
});
});

View File

@@ -73,7 +73,7 @@ export default class VoiceConnection extends EventEmitter {
}
}
playStream(stream) {
playStream(stream, channels=2) {
var self = this;
@@ -101,7 +101,7 @@ export default class VoiceConnection extends EventEmitter {
}
try {
var buffer = stream.read(1920);
var buffer = stream.read(1920 * channels);
if (!buffer) {
if (onWarning) {
@@ -116,8 +116,8 @@ export default class VoiceConnection extends EventEmitter {
}
}
if(buffer.length !== 1920) {
var newBuffer = new Buffer(1920).fill(0);
if(buffer.length !== 1920 * channels) {
var newBuffer = new Buffer(1920 * channels).fill(0);
buffer.copy(newBuffer);
buffer = newBuffer;
}
@@ -213,7 +213,7 @@ export default class VoiceConnection extends EventEmitter {
.catch(error)
.then(data => {
self.streamProc = data.proc;
var intent = self.playStream(data.stream);
var intent = self.playStream(data.stream, 2);
resolve(intent);
callback(null, intent);