Open History to see the last commit
1export const VOICE_WAVEFORM_SAMPLE_COUNT = 64;
2
3const VOICE_NOISE_FLOOR_DECIBELS = -60;
4const VOICE_NOISE_FLOOR_AMPLITUDE = 10 ** (VOICE_NOISE_FLOOR_DECIBELS / 20);
5
6export function normalizeVoiceInputDecibels(decibels: number | undefined) {
7 if (decibels === undefined || !Number.isFinite(decibels)) return 0;
8 if (decibels <= VOICE_NOISE_FLOOR_DECIBELS) return 0;
9 if (decibels >= 0) return 1;
10
11 const amplitude = 10 ** (decibels / 20);
12 return Math.sqrt((amplitude - VOICE_NOISE_FLOOR_AMPLITUDE) / (1 - VOICE_NOISE_FLOOR_AMPLITUDE));
13}