From c9938ff704765414ad119e0ea42822d96eefc23f Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Tue, 23 Mar 2021 18:24:40 -0600 Subject: [PATCH] Adjust settings/docs for encoder --- src/voice/VoiceRecorder.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/voice/VoiceRecorder.ts b/src/voice/VoiceRecorder.ts index ec1a745272..9fa2faad1e 100644 --- a/src/voice/VoiceRecorder.ts +++ b/src/voice/VoiceRecorder.ts @@ -22,8 +22,8 @@ import {SimpleObservable} from "matrix-widget-api"; const CHANNELS = 1; // stereo isn't important const SAMPLE_RATE = 48000; // 48khz is what WebRTC uses. 12khz is where we lose quality. -const BITRATE = 64000; // 64kbps is average for WebRTC, so we might as well use it too. -const FREQ_SAMPLE_RATE = 4; // Target rate of frequency data. We don't need this super often. +const BITRATE = 24000; // 24kbps is pretty high quality for our use case in opus. +const FREQ_SAMPLE_RATE = 4; // Target rate of frequency data (samples / sec). We don't need this super often. export interface IFrequencyPackage { dbBars: Float32Array; @@ -75,7 +75,11 @@ export class VoiceRecorder { numberOfChannels: CHANNELS, sourceNode: this.recorderSource, encoderBitRate: BITRATE, - encoderComplexity: 3, // 0-10, 0 is fast and low complexity + + // We use low values for the following to ease CPU usage - the resulting waveform + // is indistinguishable for a voice message. Note that the underlying library will + // pick defaults which prefer the highest possible quality, CPU be damned. + encoderComplexity: 3, // 0-10, 10 is slow and high quality. resampleQuality: 3, // 0-10, 10 is slow and high quality }); this.recorder.ondataavailable = (a: ArrayBuffer) => {