Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit c9938ff

Browse files
committed
Adjust settings/docs for encoder
1 parent b7e6532 commit c9938ff

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/voice/VoiceRecorder.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import {SimpleObservable} from "matrix-widget-api";
2222

2323
const CHANNELS = 1; // stereo isn't important
2424
const SAMPLE_RATE = 48000; // 48khz is what WebRTC uses. 12khz is where we lose quality.
25-
const BITRATE = 64000; // 64kbps is average for WebRTC, so we might as well use it too.
26-
const FREQ_SAMPLE_RATE = 4; // Target rate of frequency data. We don't need this super often.
25+
const BITRATE = 24000; // 24kbps is pretty high quality for our use case in opus.
26+
const FREQ_SAMPLE_RATE = 4; // Target rate of frequency data (samples / sec). We don't need this super often.
2727

2828
export interface IFrequencyPackage {
2929
dbBars: Float32Array;
@@ -75,7 +75,11 @@ export class VoiceRecorder {
7575
numberOfChannels: CHANNELS,
7676
sourceNode: this.recorderSource,
7777
encoderBitRate: BITRATE,
78-
encoderComplexity: 3, // 0-10, 0 is fast and low complexity
78+
79+
// We use low values for the following to ease CPU usage - the resulting waveform
80+
// is indistinguishable for a voice message. Note that the underlying library will
81+
// pick defaults which prefer the highest possible quality, CPU be damned.
82+
encoderComplexity: 3, // 0-10, 10 is slow and high quality.
7983
resampleQuality: 3, // 0-10, 10 is slow and high quality
8084
});
8185
this.recorder.ondataavailable = (a: ArrayBuffer) => {

0 commit comments

Comments
 (0)