(chunk: Buffer)
| 183 | // normalized 0-1 value. A sqrt curve spreads quieter levels across more |
| 184 | // of the visual range so the waveform uses the full set of block heights. |
| 185 | export function computeLevel(chunk: Buffer): number { |
| 186 | const samples = chunk.length >> 1 // 16-bit = 2 bytes per sample |
| 187 | if (samples === 0) return 0 |
| 188 | let sumSq = 0 |
| 189 | for (let i = 0; i < chunk.length - 1; i += 2) { |
| 190 | // Read 16-bit signed little-endian |
| 191 | const sample = ((chunk[i]! | (chunk[i + 1]! << 8)) << 16) >> 16 |
| 192 | sumSq += sample * sample |
| 193 | } |
| 194 | const rms = Math.sqrt(sumSq / samples) |
| 195 | const normalized = Math.min(rms / 2000, 1) |
| 196 | return Math.sqrt(normalized) |
| 197 | } |
| 198 | |
| 199 | export function useVoice({ |
| 200 | onTranscript, |
no outgoing calls
no test coverage detected