-
-
Notifications
You must be signed in to change notification settings - Fork 40
Closed
Description
I'm not sure why, perhaps i'm using it incorrectly. I have this snippet
const playAudio = (audioData: ArrayBuffer): void => {
console.log("Playing audio chunk, size:", audioData.byteLength)
try {
if (!audioContext) {
audioContext = new AudioContext({ sampleRate })
}
const float32Array = convert16BitPCMToFloat32(audioData)
const audioBuffer = createAudioBuffer(float32Array)
const source = audioContext.createBufferSource()
source.buffer = audioBuffer
source.connect(audioContext.destination)
const currentTime = audioContext.currentTime
const startTime = Math.max(currentTime, nextStartTime)
console.log("currentTime:", currentTime, "startTime:", startTime)
const now = Date.now()
console.log("***AUDIO CHUNK START ", now)
source.start(startTime)
nextStartTime = startTime + audioBuffer.duration
source.onEnded = () => {
console.log("***AUDIO CHUNK END ", (Date.now() - now) / 1000, " seconds")
lastSourceNode = null
isPlaying = false
_processQueue()
}
lastSourceNode = source
} catch (error: any) {
console.error("Audio playback error:", error)
}
}
and I'm noticing for the first audio chunk (and sporadically others at times), even if the audioBuffer duration is < 200ms, the onEnded gets fired seconds later. For example one audio chunk finished after 1.79seconds even if the duration was 0.2s
I'm trying to isolate the issue (if its my code or something else) but I'm not able to find it yet. It's more noticeable on lower end Android devices.
In my system, I get a lot 10-20 audio chunks from gemini to be played so maybe some js issue on my side as well. I'm still debugging but would appreciate it anyone had ideas on if it could be something with the audio api.
Metadata
Metadata
Assignees
Labels
No labels