{"record":{"id":"eb5c10be767dd277","repo":"xtekky/gpt4free","slug":"no-valid-audio-data-found-for-transcription","errorCode":null,"errorMessage":"No valid audio data found for transcription","messagePattern":"No valid audio data found for transcription","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/audio/PollinationsAudio.py","lineNumber":250,"sourceCode":"        ) as session:\n            async with session.post(cls.speech_api_endpoint, json=payload) as response:\n                await raise_for_status(response)\n                async for chunk in save_response_media(response, text, [model, voice]):\n                    yield chunk\n\n    @classmethod\n    async def _create_transcription(\n        cls,\n        media: MediaListType,\n        api_key: str,\n        proxy: str,\n        model: str = None,\n        **kwargs,\n    ) -> AsyncResult:\n        media_data, filename = media[0]\n        file_bytes = to_bytes(media_data)\n        if not file_bytes:\n            raise ValueError(\"No valid audio data found for transcription\")\n\n        form = FormData()\n        form.add_field(\n            \"file\",\n            file_bytes,\n            filename=filename or \"audio.wav\",\n            content_type=\"application/octet-stream\",\n        )\n\n        transcription_model = model\n        if transcription_model in (None, \"openai-audio\"):\n            transcription_model = cls.default_transcription_model\n        form_fields = filter_none(\n            model=transcription_model,\n            language=kwargs.get(\"language\"),\n            prompt=kwargs.get(\"prompt\"),\n            response_format=kwargs.get(\"response_format\"),\n            temperature=kwargs.get(\"temperature\"),","sourceCodeStart":232,"sourceCodeEnd":268,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/audio/PollinationsAudio.py#L232-L268","documentation":"ValueError from PollinationsAudio._create_transcription when the first media item converts to zero bytes via to_bytes(). The transcription endpoint uploads the audio file as multipart form data; empty bytes mean the file handle was exhausted, the path unreadable, or the buffer truly empty, and the request would be pointless.","triggerScenarios":"Passing an already-consumed file object (read() previously returned the content and is now at EOF), a zero-byte upload, or a bytes/path value that to_bytes() cannot read as media[0].","commonSituations":"Reusing a file handle across two uploads without seek(0); frontend sending an empty file input; temp files cleaned before the request runs.","solutions":["Seek the file before sending: f.seek(0), or reopen the file fresh","Verify the file is non-empty (os.path.getsize > 0) before attaching it","Pass raw bytes directly instead of a consumed handle"],"exampleFix":"# before\naudio = open('speech.wav', 'rb')\nawait transcribe(audio)  # ...later, same handle already at EOF\nawait transcribe(audio)  # -> ValueError\n\n# after\nwith open('speech.wav', 'rb') as f:\n    data = f.read()\nassert len(data) > 0\nawait transcribe(data)","handlingStrategy":"validation","validationCode":"def media_has_bytes(media):\n    from g4f.Provider.audio.PollinationsAudio import to_bytes\n    data = to_bytes(media[0][0])\n    return bool(data)\n\n# safer: read bytes once up front\nwith open(path, 'rb') as f:\n    audio_bytes = f.read()\nassert audio_bytes, 'empty audio file'","typeGuard":null,"tryCatchPattern":"except ValueError as e:\n    if 'No valid audio data' in str(e):\n        re-open file, seek(0), or reject the upload","preventionTips":["Always seek(0) file handles reused across uploads","Reject zero-byte uploads at the form/API layer","Pass bytes, not file handles, when retrying transcription"],"tags":["pollinations-audio","transcription","file-handling","validation"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}