diff --git a/daras_ai_v2/asr.py b/daras_ai_v2/asr.py index 04a2f25fe..8f39d0312 100644 --- a/daras_ai_v2/asr.py +++ b/daras_ai_v2/asr.py @@ -988,7 +988,15 @@ def download_youtube_to_wav(youtube_url: str) -> bytes: def audio_url_to_wav(audio_url: str) -> tuple[str, int]: r = requests.get(audio_url) - raise_for_status(r, is_user_url=True) + try: + raise_for_status(r, is_user_url=True) + except requests.HTTPError: + # wait 3 seconds and try again (handles cases where the url has just been uploaded but cache is not updated yet, e.g. for Twilio) + from time import sleep + + sleep(3) + r = requests.get(audio_url) + raise_for_status(r, is_user_url=True) wavdata, size = audio_bytes_to_wav(r.content) if not wavdata: