Skip to content

floatTo16BitPCM

Converts a Float32Array of audio samples to a 16-bit signed integer PCM Int16Array.

function floatTo16BitPCM(float32Array): Int16Array;

Defined in: src/utils/audio.ts:61

Converts a Float32Array of audio samples to a 16-bit signed integer PCM Int16Array.

Parameters

ParameterTypeDescription
float32ArrayFloat32ArrayThe input audio samples as 32-bit floats in the range [-1.0, 1.0].

Returns

Int16Array

A new Int16Array containing the converted 16-bit PCM samples.

Remarks

Float samples are expected in the range [-1.0, 1.0]. Values outside this range are clamped. The conversion maps:

  • -1.0 to -32768 (0x8000)
  • 0.0 to 0
  • 1.0 to 32767 (0x7FFF)

This is the standard conversion used for PCM audio in WAV files and WebSocket streaming to STT/TTS providers.

Example

const floatSamples = new Float32Array([0.0, 0.5, -0.5, 1.0, -1.0]);
const pcmSamples = floatTo16BitPCM(floatSamples);
// pcmSamples: Int16Array [0, 16383, -16384, 32767, -32768]

See

int16ToFloat for the inverse conversion.

© 2026 CompositeVoice. All rights reserved.

Font size
Contrast
Motion
Transparency