fix: audio haché depuis carte son par chunks sox de taille variable

- Ajout buffer d'accumulation dans CoreAudioBackend pour garantir frames fixes
- sox envoie des chunks de taille variable → accumuler jusqu'à frameSize complet
- Émission de frames exactement 960 samples × 2ch × 2 bytes = 3840 bytes
- Adaptation automatique mono/stéréo selon config channels
- Audio fluide sans hachage/robotique vers clients LiveKit
This commit is contained in:
2026-06-02 01:14:49 +02:00
parent 9aff58c528
commit 2b88ea0ad5
6 changed files with 92 additions and 51 deletions
+10 -3
View File
@@ -264,11 +264,18 @@ export class LiveKitClient extends EventEmitter {
}
try {
// Création d'un AudioFrame (conversion en int32 explicite)
const samplesPerChannel = Math.floor(pcmData.length / 2 / this.options.channels);
// AudioFrame attend Int16Array, pas Buffer
// Convertir Buffer → Int16Array (éviter .slice, utiliser .subarray selon doc)
const int16Array = new Int16Array(
pcmData.buffer,
pcmData.byteOffset,
pcmData.length / 2 // length en samples, pas en bytes
);
const samplesPerChannel = Math.floor(int16Array.length / this.options.channels);
const frame = new AudioFrame(
pcmData,
int16Array,
parseInt(this.options.sampleRate, 10),
parseInt(this.options.channels, 10),
samplesPerChannel