Restored to '7aa09373aacdcc1083018c718e608e30b6be2b33'

Replit-Restored-To: 7aa09373aa
This commit is contained in:
sebastjanartic
2026-02-28 20:34:36 +00:00
parent a8643ecdd2
commit abd322871b
76 changed files with 213 additions and 4640 deletions
@@ -1,36 +0,0 @@
/**
* Audio utility functions for voice chat.
* Handles PCM16 decoding and AudioContext initialization.
*/
/**
* Decode base64 PCM16 audio to Float32Array for Web Audio API
*/
export function decodePCM16ToFloat32(base64Audio: string): Float32Array {
const raw = atob(base64Audio);
const bytes = new Uint8Array(raw.length);
for (let i = 0; i < raw.length; i++) {
bytes[i] = raw.charCodeAt(i);
}
const pcm16 = new Int16Array(bytes.buffer);
const float32 = new Float32Array(pcm16.length);
for (let i = 0; i < pcm16.length; i++) {
float32[i] = pcm16[i] / 32768;
}
return float32;
}
/**
* Create and initialize AudioContext with worklet
*/
export async function createAudioPlaybackContext(
workletPath = "/audio-playback-worklet.js",
sampleRate = 24000
): Promise<{ ctx: AudioContext; worklet: AudioWorkletNode }> {
const ctx = new AudioContext({ sampleRate });
await ctx.audioWorklet.addModule(workletPath);
const worklet = new AudioWorkletNode(ctx, "audio-playback-processor");
worklet.connect(ctx.destination);
return { ctx, worklet };
}