From d8b512aaa64d91a0a48d3eec92b26f3298e151a4 Mon Sep 17 00:00:00 2001 From: Joshua Laymon Date: Thu, 21 Aug 2025 01:38:17 +0000 Subject: [PATCH] Update web/core/views_tts.py --- web/core/views_tts.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/web/core/views_tts.py b/web/core/views_tts.py index 0259d65..eca75ca 100644 --- a/web/core/views_tts.py +++ b/web/core/views_tts.py @@ -33,19 +33,17 @@ def api_tts_for_entry(request, entry_id): if not combined: return HttpResponseBadRequest("No text available for this entry.") - # ---- Call OpenAI TTS (MP3) ---- + # ---- Call OpenAI TTS (MP3) ---- try: - # gpt-4o-mini-tts → mp3 bytes - # voices: "alloy", "verse", "aria", etc. - speech = client.audio.speech.create( + # Use the streaming helper for broad SDK compatibility. + # It yields MP3 audio bytes by default. + with client.audio.speech.with_streaming_response.create( model="gpt-4o-mini-tts", - voice="alloy", + voice="alloy", # or another supported voice input=combined, - format="mp3", - ) - audio_bytes = speech.read() # returns raw bytes + ) as resp: + audio_bytes = resp.read() # raw MP3 bytes except Exception as e: - # Return a plain text 500 so your client can preview it return HttpResponse(f"OpenAI TTS failed: {e}", status=500, content_type="text/plain") # ---- Serve as audio/mpeg ----