xtekky/gpt4free · error · ValueError
No valid audio data found for transcription
Error message
No valid audio data found for transcription
What it means
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.
Source
Thrown at g4f/Provider/audio/PollinationsAudio.py:250
) as session:
async with session.post(cls.speech_api_endpoint, json=payload) as response:
await raise_for_status(response)
async for chunk in save_response_media(response, text, [model, voice]):
yield chunk
@classmethod
async def _create_transcription(
cls,
media: MediaListType,
api_key: str,
proxy: str,
model: str = None,
**kwargs,
) -> AsyncResult:
media_data, filename = media[0]
file_bytes = to_bytes(media_data)
if not file_bytes:
raise ValueError("No valid audio data found for transcription")
form = FormData()
form.add_field(
"file",
file_bytes,
filename=filename or "audio.wav",
content_type="application/octet-stream",
)
transcription_model = model
if transcription_model in (None, "openai-audio"):
transcription_model = cls.default_transcription_model
form_fields = filter_none(
model=transcription_model,
language=kwargs.get("language"),
prompt=kwargs.get("prompt"),
response_format=kwargs.get("response_format"),
temperature=kwargs.get("temperature"),View on GitHub (pinned to 973504e177)
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
Example fix
# before
audio = open('speech.wav', 'rb')
await transcribe(audio) # ...later, same handle already at EOF
await transcribe(audio) # -> ValueError
# after
with open('speech.wav', 'rb') as f:
data = f.read()
assert len(data) > 0
await transcribe(data) Defensive patterns
Strategy: validation
Validate before calling
def media_has_bytes(media):
from g4f.Provider.audio.PollinationsAudio import to_bytes
data = to_bytes(media[0][0])
return bool(data)
# safer: read bytes once up front
with open(path, 'rb') as f:
audio_bytes = f.read()
assert audio_bytes, 'empty audio file' Try / catch
except ValueError as e:
if 'No valid audio data' in str(e):
re-open file, seek(0), or reject the upload Prevention
- 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
When it happens
Trigger: 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].
Common situations: Reusing a file handle across two uploads without seek(0); frontend sending an empty file input; temp files cleaned before the request runs.
Related errors
- Provider '{item}' not found
- Label must be provided
- Provider with label '{label}' not found
- Prompt is empty.
- Prompt is empty.
AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14).
Data as JSON: /api/errors/eb5c10be767dd277.
Report an issue: GitHub.