diff --git a/services/discord-gateway/src/modules/voice-recording/transmitter.ts b/services/discord-gateway/src/modules/voice-recording/transmitter.ts index 8bea79e..ca4f9cf 100644 --- a/services/discord-gateway/src/modules/voice-recording/transmitter.ts +++ b/services/discord-gateway/src/modules/voice-recording/transmitter.ts @@ -50,16 +50,8 @@ export class VoiceTransmitter { "-ar", "48000", // Output sample rate: 48kHz "-ac", "2", // Output channels: stereo "-application", "lowdelay", // Low delay mode for real-time - "-frame_duration", "10", // 10ms frames (smaller = less latency) + "-frame_duration", "20", // 20ms frames "-packet_loss", "0", // No packet loss expected - "-compression_level", "0", // Fastest compression (lowest CPU latency) - "-cutoff", "20000", // Audio cutoff frequency - "-vsync", "0", // No video sync - "-fflags", "nobuffer", // No buffering - "-flags", "low_delay", // Low delay processing - "-strict", "experimental", - "-analyzeduration", "0", // No analysis duration - "-probesize", "32", // Minimal probe size "pipe:1", // Write to stdout ], { stdio: ["pipe", "pipe", "pipe"], diff --git a/services/frontend/src/shared/hooks/useAudioTransmit.ts b/services/frontend/src/shared/hooks/useAudioTransmit.ts index d80076b..5496484 100644 --- a/services/frontend/src/shared/hooks/useAudioTransmit.ts +++ b/services/frontend/src/shared/hooks/useAudioTransmit.ts @@ -61,7 +61,7 @@ export function useAudioTransmit(socketRef: { const processor = audioContext.createScriptProcessor(1024, 1, 1); processorRef.current = processor; source.connect(processor); - // Don't connect processor to destination (no monitoring feedback) + processor.connect(audioContext.destination); processor.onaudioprocess = (event) => { if (!socketRef.current || socketRef.current.readyState !== WebSocket.OPEN) return; @@ -70,14 +70,13 @@ export function useAudioTransmit(socketRef: { for (let i = 0; i < inputData.length; i++) pcmData[i] = Math.max(-1, Math.min(1, inputData[i])) * 32767; - // Fast base64 using Uint8Array + btoa - const uint8 = new Uint8Array(pcmData.buffer); - let base64 = ''; - const chunkSize = 8192; - for (let i = 0; i < uint8.length; i += chunkSize) { - const chunk = uint8.subarray(i, i + chunkSize); - base64 += btoa(String.fromCharCode(...chunk)); + // Base64 encode + const bytes = new Uint8Array(pcmData.buffer); + let binary = ''; + for (let i = 0; i < bytes.length; i++) { + binary += String.fromCharCode(bytes[i]); } + const base64 = btoa(binary); socketRef.current.send(JSON.stringify({ type: 'voice_transmit',