finaly, it’s works perfectly :
case 'input_audio_buffer.speech_started':
console.log('Speech Start:', response.type);
twilioWs.send(
JSON.stringify({
streamSid: streamSid,
event: 'clear',
})
);
console.log('Cancelling AI speech from the server');
const interruptMessage = {
type: 'response.cancel'
};
openaiWs.send(JSON.stringify(interruptMessage));
}
Edit: You have to see this PR because you need to manage interrupt handling in both side - Twilio and OpenAI. When the user speaks and OpenAI sends input_audio_buffer.speech_started
, the code in the PR clears the Twilio Media Streams buffer and sends conversation.item.truncate
to OpenAI which is so important in this case."