@@ -446,10 +446,53 @@ async def _download_media(m, file=None):
446446
447447 assert result == {"status" : "ok" , "text" : "hello world" , "lang" : "ru" }
448448 assert calls [0 ]["headers" ]["Authorization" ] == "Bearer test-key"
449- assert calls [0 ]["files" ]["file" ][0 ] == "voice.oga "
449+ assert calls [0 ]["files" ]["file" ][0 ] == "voice.ogg "
450450 assert calls [0 ]["data" ]["model" ] == transcription .GROQ_MODEL
451451
452452
453+ @pytest .mark .asyncio
454+ @pytest .mark .parametrize (
455+ "ext_in,expected_filename" ,
456+ [
457+ (".oga" , "voice.ogg" ),
458+ ("oga" , "voice.ogg" ),
459+ (".ogg" , "voice.ogg" ),
460+ (".mp3" , "voice.mp3" ),
461+ (".wav" , "voice.wav" ),
462+ (None , "voice.ogg" ),
463+ ],
464+ )
465+ async def test_transcribe_via_groq_normalizes_audio_file_extension (
466+ monkeypatch , ext_in , expected_filename
467+ ):
468+ """Groq API audio transcription only accepts [flac mp3 mp4 mpeg mpga m4a ogg opus wav webm].
469+ Telegram voice notes arrive as .oga, which Groq rejects with 400 unsupported_audio_format.
470+ Naming the upload as .ogg satisfies Groq while preserving the identical audio content (issue #219).
471+ """
472+ monkeypatch .setenv ("GROQ_API_KEY" , "test-key" )
473+ calls = []
474+ response = _FakeGroqResponse ({"text" : "ok" , "language" : "en" })
475+ monkeypatch .setattr (
476+ transcription .httpx , "AsyncClient" , lambda ** kw : _FakeHttpxClient (response , calls )
477+ )
478+
479+ file_obj = (
480+ SimpleNamespace (duration = 10 , ext = ext_in , mime_type = "audio/ogg" )
481+ if ext_in is not None
482+ else None
483+ )
484+ msg = _voice_msg (file = file_obj )
485+
486+ async def _download_media (m , file = None ):
487+ return b"audio-bytes"
488+
489+ client = SimpleNamespace (download_media = _download_media )
490+ result = await transcription ._transcribe_via_groq (client , msg )
491+
492+ assert result ["status" ] == "ok"
493+ assert calls [0 ]["files" ]["file" ][0 ] == expected_filename
494+
495+
453496@pytest .mark .asyncio
454497async def test_transcribe_via_groq_requires_api_key (monkeypatch ):
455498 monkeypatch .delenv ("GROQ_API_KEY" , raising = False )
0 commit comments