I want to create async func for transcribing telegram voices (.ogg files), but when i try send request to OpenAI API i recive error:
Error code: 400 – {‘error’: {‘message’: "Unrecognized file format.
Supported formats: [‘flac’, ‘m4a’, ‘mp3’, ‘mp4’, ‘mpeg’, ‘mpga’,
‘oga’, ‘ogg’, ‘wav’, ‘webm’]", ‘type’: ‘invalid_request_error’,
‘param’: None, ‘code’: None}}
Here is code of my functions:
sync def transcribe_voice_message(file_path):
"""OpenAI Speech To Text request"""
client = AsyncOpenAI(api_key=openai_api_key)
try:
async with aiofiles.open(file_path, 'rb') as f:
file_content = await f.read()
transcription = await client.audio.transcriptions.create(
model="whisper-1", file=file_content
)
except Exception as e:
logger.error(
f"Open API error: {e}"
)
return transcription.text
I wil be aprecciate for your help
I tried different ways to solve problem, change type files to .mp3, chande object types to IO[bytes] or bytes, but always same
2
Answers
Solved by this message: https://stackoverflow.com/a/77616053/12834417
New code:
There are two codecs that encode in
.ogg
format:opus
andvorbis
. Most probably OpenAI support only one of this codecs, not both of them. I would suggest to check your audio file format by runningffprobe
on it: