get voice sort of working

This commit is contained in:
Amish Shah
2016-10-24 14:26:24 +01:00
parent 9b3dd540ef
commit e13e2447d4
8 changed files with 81 additions and 15 deletions

View File

@@ -0,0 +1,41 @@
const PCMConverters = require('../pcm/ConverterEngineList');
const OpusEncoders = require('../opus/OpusEngineList');
const EventEmitter = require('events').EventEmitter;
const StreamDispatcher = require('../dispatcher/StreamDispatcher');
class AudioPlayer extends EventEmitter {
constructor(voiceConnection) {
super();
this.voiceConnection = voiceConnection;
this.audioToPCM = new (PCMConverters.fetch())();
this.opusEncoder = OpusEncoders.fetch();
this.audioToPCM.on('error', e => this.emit('error', e));
}
playUnknownStream(stream) {
const conversionProcess = this.audioToPCM.createConvertStream(0);
stream.pipe(conversionProcess.process.stdin, { end: false });
return this.playPCMStream(conversionProcess.process.stdout);
}
playPCMStream(stream) {
stream.on('error', e => this.emit('error', e));
const dispatcher = new StreamDispatcher(this, stream, {
channels: 2,
count: 0,
sequence: 0,
timestamp: 0,
pausedTime: 0,
}, {
volume: 1,
});
dispatcher.on('error', e => console.log('error', e));
dispatcher.on('end', e => console.log('end', e));
dispatcher.on('speaking', value => this.voiceConnection.setSpeaking(value));
}
}
module.exports = AudioPlayer;