You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I noticed that when using the conversation.item.truncate event in the OpenAI Realtime API (referenced from this repo), you can run into the following error:
Audio content of X ms is already shorter than Y ms
Root Cause
This issue happens because, when truncating the audio playback, the truncate position (audio_end_ms) is sometimes set to a value (e.g., 57340ms) that exceeds the actual length of the audio content generated by OpenAI (e.g., 9250ms). OpenAI throws an error when this happens:
Audio content of 9250ms is already shorter than 57340ms
Quick Fix
Change the following code in the send_twilio method from:
ifresponse_start_timestamp_twilioisNone:
response_start_timestamp_twilio=latest_media_timestampifSHOW_TIMING_MATH:
print(f"Setting start timestamp for new response: {response_start_timestamp_twilio}ms")
# Update last_assistant_item safelyifresponse.get('item_id'):
last_assistant_item=response['item_id']
Yes, I was running into the same concern. According to the open ai docs, the audio_end_ms should represent the "Inclusive duration up to which audio is truncated, in milliseconds."
Thus, if we want to set audio_end_ms as elapsed_time = latest_media_timestamp - response_start_timestamp_twilio, then response_start_timestamp_twilio should be the time stamp of when the currently in-progress response started, and null if there is no response in progress. Additionally, latest_media_timestamp should correspond to the timestamp of when the user started interrupting the open AI response.
However, both timestamps are set from the time stamps of incoming Twilio messages and thus seem somewhat divorced from what they ought to be. Am I misunderstanding the open ai docs, the example code, or this a bug?
Hey Twilio team,
I noticed that when using the
conversation.item.truncate
event in the OpenAI Realtime API (referenced from this repo), you can run into the following error:Root Cause
This issue happens because, when truncating the audio playback, the truncate position (
audio_end_ms
) is sometimes set to a value (e.g., 57340ms) that exceeds the actual length of the audio content generated by OpenAI (e.g., 9250ms). OpenAI throws an error when this happens:Quick Fix
Change the following code in the
send_twilio
method from:to
The text was updated successfully, but these errors were encountered: