Compare commits

...

2 Commits

Author SHA1 Message Date
MythEclipse
3dbe3105af fix: simplify AudioData playback with direct copyTo approach
- Rename playAudioData to playAudioDataDirect for clarity
- Remove duplicate playAudioData function with debug logging
- Use direct copyTo into temp Float32Array per channel
- Check isListening state in output callback
2026-05-13 22:20:15 +07:00
MythEclipse
638d5fc005 debug: add logging to AudioData playback
- Log frame count, channels, sample rate from AudioData
- Log destination channel size before copyTo
- Identify frame count mismatch issue
2026-05-13 22:19:25 +07:00
3 changed files with 30 additions and 29 deletions

BIN
bun.lockb

Binary file not shown.

View File

@@ -33,6 +33,7 @@
"react": "^19.2.6",
"react-dom": "^19.2.6",
"sodium-native": "^4.3.2",
"tone": "^15.1.22",
"ws": "^8.20.1",
"zod": "^4.4.3"
},

View File

@@ -437,7 +437,7 @@ const state = {
}
try {
state.opusDecoder = new AudioDecoder({
output: (audioData) => playAudioData(audioData),
output: (audioData) => playAudioDataDirect(audioData),
error: (error) => {
console.error('Opus decode error:', error);
showError(`Opus decode error: ${error.message}`);
@@ -458,34 +458,8 @@ const state = {
}
}
function decodeOpus(opusBuffer) {
if (!state.isListening || !state.opusDecoderReady) {
if (state.isListening) {
state.opusDecodeQueue.push(opusBuffer);
}
return;
}
try {
const chunk = new EncodedAudioChunk({
type: 'key',
timestamp: 0,
data: opusBuffer,
});
state.opusDecoder.decode(chunk);
} catch (error) {
console.error('Opus decode chunk error:', error);
}
}
function processOpusQueue() {
while (state.opusDecodeQueue.length > 0 && state.opusDecoderReady) {
const buffer = state.opusDecodeQueue.shift();
decodeOpus(buffer);
}
}
function playAudioData(audioData) {
if (!state.audioContextListen) {
function playAudioDataDirect(audioData) {
if (!state.audioContextListen || !state.isListening) {
audioData.close();
return;
}
@@ -517,6 +491,32 @@ const state = {
}
}
function decodeOpus(opusBuffer) {
if (!state.isListening || !state.opusDecoderReady) {
if (state.isListening) {
state.opusDecodeQueue.push(opusBuffer);
}
return;
}
try {
const chunk = new EncodedAudioChunk({
type: 'key',
timestamp: 0,
data: opusBuffer,
});
state.opusDecoder.decode(chunk);
} catch (error) {
console.error('Opus decode chunk error:', error);
}
}
function processOpusQueue() {
while (state.opusDecodeQueue.length > 0 && state.opusDecoderReady) {
const buffer = state.opusDecodeQueue.shift();
decodeOpus(buffer);
}
}
function playPcm(arrayBuffer) {
if (!state.audioContextListen) return;
const bytes = new Uint8Array(arrayBuffer);