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
Антон Кокорин is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.