Allow for configuration of audio bitrate and frames per packet

This commit is contained in:
Jonas Herzig 2018-09-26 13:06:37 +02:00
parent 2432206646
commit 5ca332a151
2 changed files with 26 additions and 13 deletions

View file

@ -114,7 +114,9 @@ class SettingsDialog {
if (this._testVad) { if (this._testVad) {
this._testVad.end() this._testVad.end()
} }
this._testVad = new VADVoiceHandler(null, this.vadLevel()) let dummySettings = new Settings()
this.applyTo(dummySettings)
this._testVad = new VADVoiceHandler(null, dummySettings)
this._testVad.on('started_talking', () => this.testVadActive(true)) this._testVad.on('started_talking', () => this.testVadActive(true))
.on('stopped_talking', () => this.testVadActive(false)) .on('stopped_talking', () => this.testVadActive(false))
.on('level', level => this.testVadLevel(level)) .on('level', level => this.testVadLevel(level))
@ -162,6 +164,8 @@ class Settings {
this.vadLevel = load('vadLevel') || 0.3 this.vadLevel = load('vadLevel') || 0.3
this.toolbarVertical = load('toolbarVertical') || false this.toolbarVertical = load('toolbarVertical') || false
this.showAvatars = ko.observable(load('showAvatars') || 'always') this.showAvatars = ko.observable(load('showAvatars') || 'always')
this.audioBitrate = Number(load('audioBitrate')) || 40000
this.samplesPerPacket = Number(load('samplesPerPacket')) || 960
} }
save () { save () {
@ -171,6 +175,8 @@ class Settings {
save('vadLevel', this.vadLevel) save('vadLevel', this.vadLevel)
save('toolbarVertical', this.toolbarVertical) save('toolbarVertical', this.toolbarVertical)
save('showAvatars', this.showAvatars()) save('showAvatars', this.showAvatars())
save('audioBitrate', this.audioBitrate)
save('samplesPerPacket', this.samplesPerPacket)
} }
} }
@ -584,11 +590,11 @@ class GlobalBindings {
} }
let mode = this.settings.voiceMode let mode = this.settings.voiceMode
if (mode === 'cont') { if (mode === 'cont') {
voiceHandler = new ContinuousVoiceHandler(this.client) voiceHandler = new ContinuousVoiceHandler(this.client, this.settings)
} else if (mode === 'ptt') { } else if (mode === 'ptt') {
voiceHandler = new PushToTalkVoiceHandler(this.client, this.settings.pttKey) voiceHandler = new PushToTalkVoiceHandler(this.client, this.settings)
} else if (mode === 'vad') { } else if (mode === 'vad') {
voiceHandler = new VADVoiceHandler(this.client, this.settings.vadLevel) voiceHandler = new VADVoiceHandler(this.client, this.settings)
} else { } else {
log('Unknown voice mode:', mode) log('Unknown voice mode:', mode)
return return
@ -606,6 +612,11 @@ class GlobalBindings {
if (this.selfMute()) { if (this.selfMute()) {
voiceHandler.setMute(true) voiceHandler.setMute(true)
} }
this.client.setAudioQuality(
this.settings.audioBitrate,
this.settings.samplesPerPacket
)
} }
this.messageBoxHint = ko.pureComputed(() => { this.messageBoxHint = ko.pureComputed(() => {

View file

@ -9,9 +9,10 @@ import vad from 'voice-activity-detection'
import DropStream from 'drop-stream' import DropStream from 'drop-stream'
class VoiceHandler extends Writable { class VoiceHandler extends Writable {
constructor (client) { constructor (client, settings) {
super({ objectMode: true }) super({ objectMode: true })
this._client = client this._client = client
this._settings = settings
this._outbound = null this._outbound = null
this._mute = false this._mute = false
} }
@ -47,7 +48,7 @@ class VoiceHandler extends Writable {
}) })
this._outbound this._outbound
.pipe(chunker(4 * 480)) .pipe(chunker(4 * this._settings.samplesPerPacket))
.pipe(buffer2Float32Array) .pipe(buffer2Float32Array)
.pipe(this._client.createVoiceStream()) .pipe(this._client.createVoiceStream())
@ -71,8 +72,8 @@ class VoiceHandler extends Writable {
} }
export class ContinuousVoiceHandler extends VoiceHandler { export class ContinuousVoiceHandler extends VoiceHandler {
constructor (client) { constructor (client, settings) {
super(client) super(client, settings)
} }
_write (data, _, callback) { _write (data, _, callback) {
@ -85,9 +86,9 @@ export class ContinuousVoiceHandler extends VoiceHandler {
} }
export class PushToTalkVoiceHandler extends VoiceHandler { export class PushToTalkVoiceHandler extends VoiceHandler {
constructor (client, key) { constructor (client, settings) {
super(client) super(client, settings)
this._key = key this._key = settings.pttKey
this._pushed = false this._pushed = false
this._keydown_handler = () => this._pushed = true this._keydown_handler = () => this._pushed = true
this._keyup_handler = () => { this._keyup_handler = () => {
@ -114,8 +115,9 @@ export class PushToTalkVoiceHandler extends VoiceHandler {
} }
export class VADVoiceHandler extends VoiceHandler { export class VADVoiceHandler extends VoiceHandler {
constructor (client, level) { constructor (client, settings) {
super(client) super(client, settings)
let level = settings.vadLevel
const self = this const self = this
this._vad = vad(audioContext, theUserMedia, { this._vad = vad(audioContext, theUserMedia, {
onVoiceStart () { onVoiceStart () {