MCPcopy Index your code
hub / github.com/simstudioai/sim / floatTo16BitPCM

Function floatTo16BitPCM

apps/sim/lib/speech/audio.ts:5–13  ·  view source on GitHub ↗
(float32Array: Float32Array)

Source from the content-addressed store, hash-verified

3 * Required for ElevenLabs realtime STT (pcm_16000 format).
4 */
5export function floatTo16BitPCM(float32Array: Float32Array): ArrayBuffer {
6 const buffer = new ArrayBuffer(float32Array.length * 2)
7 const view = new DataView(buffer)
8 for (let i = 0; i < float32Array.length; i++) {
9 const s = Math.max(-1, Math.min(1, float32Array[i]))
10 view.setInt16(i * 2, s < 0 ? s * 0x8000 : s * 0x7fff, true)
11 }
12 return buffer
13}
14
15/**
16 * Encode an ArrayBuffer as a base64 string for WebSocket transport.

Callers 2

VoiceInterfaceFunction · 0.90
useSpeechToTextFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected