MCPcopy Index your code
hub / github.com/codeaashu/claude-code / computeLevel

Function computeLevel

src/hooks/useVoice.ts:185–197  ·  view source on GitHub ↗
(chunk: Buffer)

Source from the content-addressed store, hash-verified

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.
185export 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
199export function useVoice({
200 onTranscript,

Callers 1

startRecordingSessionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected