{"record":{"id":"edc471c7c531bea1","repo":"xtekky/gpt4free","slug":"unsupported-audio-format-audio-format","errorCode":null,"errorMessage":"Unsupported audio format: {audio_format}","messagePattern":"Unsupported audio format: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"g4f/integration/markitdown/_transcribe_audio.py","lineNumber":45,"sourceCode":"    if _dependency_exc_info is not None:\n        raise MissingDependencyException(\n            \"Speech transcription requires installing MarkItdown with the [audio-transcription] optional dependencies. E.g., `pip install markitdown[audio-transcription]` or `pip install markitdown[all]`\"\n        ) from _dependency_exc_info[\n            1\n        ].with_traceback(  # type: ignore[union-attr]\n            _dependency_exc_info[2]\n        )\n\n    if audio_format in [\"wav\", \"aiff\", \"flac\"]:\n        audio_source = file_stream\n    elif audio_format in [\"mp3\", \"mp4\", \"webm\"]:\n        audio_segment = pydub.AudioSegment.from_file(file_stream, format=audio_format)\n\n        audio_source = io.BytesIO()\n        audio_segment.export(audio_source, format=\"wav\")\n        audio_source.seek(0)\n    else:\n        raise ValueError(f\"Unsupported audio format: {audio_format}\")\n\n    recognizer = sr.Recognizer()\n    with sr.AudioFile(audio_source) as source:\n        audio = recognizer.record(source)\n        if language is None:\n            language = \"en-US\"\n        try:\n            transcript = recognizer.recognize_faster_whisper(\n                audio, language=language.split(\"-\")[0]\n            ).strip()\n        except ImportError:\n            transcript = recognizer.recognize_google(audio, language=language).strip()\n        return \"[No speech detected]\" if transcript == \"\" else transcript.strip()\n","sourceCodeStart":27,"sourceCodeEnd":59,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/integration/markitdown/_transcribe_audio.py#L27-L59","documentation":"Thrown by transcribe_audio() (g4f/integration/markitdown/_transcribe_audio.py) when audio_format is not one of the hardcoded accepted values: wav, aiff, flac (passed through directly) or mp3, mp4, webm (converted to wav via pydub). Any other string — including case variants and close relatives like ogg or m4a — is rejected.","triggerScenarios":"transcribe_audio(f, audio_format='ogg'); audio_format='WAV' (uppercase fails the exact-match list); 'm4a' or 'opus' files forwarded from a browser MediaRecorder that records audio/webm;codecs=opus with the codec suffix left in the format string.","commonSituations":"Browser uploads where the client reports 'audio/ogg; codecs=opus' and the code passes the whole subtype; uppercase formats from MIME tables; AAC/M4A voice notes from iPhones.","solutions":["Lowercase and strip parameters before calling: audio_format = fmt.lower().split(';')[0].split('/')[0].","Transcode unsupported containers to wav or mp3 first (pydub.AudioSegment.from_file(...).export(fmt='wav')).","For MediaRecorder output use 'webm' (or 'mp4' on Safari), which are both accepted."],"exampleFix":"// before\ntranscribe_audio(stream, audio_format=mime_subtype)  # e.g. 'ogg'\n\n// after\nfmt = mime_subtype.lower()\nif fmt not in (\"wav\", \"aiff\", \"flac\", \"mp3\", \"mp4\", \"webm\"):\n    audio = pydub.AudioSegment.from_file(stream).export(format=\"wav\")\n    fmt = \"wav\"\n    stream = audio\ntranscribe_audio(stream, audio_format=fmt)","handlingStrategy":"validation","validationCode":"ACCEPTED = {\"wav\", \"aiff\", \"flac\", \"mp3\", \"mp4\", \"webm\"}\n\ndef acceptable_format(fmt: str) -> bool:\n    return fmt.lower() in ACCEPTED","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Lowercase and strip MIME parameters before deriving audio_format.","Transcode ogg/m4a/opus inputs to wav or mp3 upstream."],"tags":["markitdown","audio","format","validation"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}