client.appendInputAudio not working
Opened this issue · 3 comments
aarizirf commented
Seems like server-side VAD isn't working. I'm routing audio from ReactJS client through Node.JS WebSocket and then through the RealtimeClient.
GPT never creates a response, or updates the conversation. I can't pick up on these events.
Anyone else have this problem? Did manual (not server_vad) end up working?
aarizirf commented
Nevermind, got it working
const buf = new Uint8Array(e.data).buffer;
the crucial line to convert ArrayBuffer(8192) --> ArrayBuffer that can used in client.appendInputAudio
Wish this was included in docs
BadMask121 commented
amitdadon commented
if you get audio payload as base64 you'll have to convert it to an array buffer.
this code helped me:
// 1. Decode using built-in atob (returns a binary string)
const binaryString = atob(base64Payload);
const len = binaryString.length;
// 2. Convert binary string to Uint8Array
const bytes = new Uint8Array(len);
const bytes = new Uint8Array(len);
for (let i = 0; i < len; i++) {
bytes[i] = binaryString.charCodeAt(i);
}
// 3. Get the underlying ArrayBuffer
const audioBuffer: ArrayBuffer = bytes.buffer;
client.appendInputAudio(audioBuffer);
