Bad request error #232
-
Which Deepgram product are you using?Prerecorded Speech-To-Text. Details
This code snippet showing some bad request error. I need to get the text transcription from chunked audio datas real time. Is there any other way to do that. Is my code snippet wrong? If you are making a request to the Deepgram API, what is the full Deepgram URL you are making a request to?https://api.deepgram.com/v1/listen?model=whisper If you are making a request to the Deepgram API and have a request ID, please paste it below:No response If possible, please attach your code or paste it into the text box.No response If possible, please attach an example audio file to reproduce the issue.No response |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Hey @samueljazzjohn your code looks good and works for me, so it could be two things:
To figure out if it's the mimetype, take a look at the audio file's extension and look up the mimetype for that audio file. For example, Below is the complete code that works for me (it took a while to run with whisper-large, so run it on Nova if you're testing with English - Nova is cheaper too): from deepgram import Deepgram
import asyncio
import os
DEEPGRAM_API_KEY = os.environ["DEEPGRAM_API_KEY"] # Your Deepgram API Key
def transcribe():
dg_client = Deepgram(DEEPGRAM_API_KEY)
loop = asyncio.get_event_loop()
# Download the audio from: https://static.deepgram.com/examples/en_NatGen_Medical_DocDictation.m4a
with open("./test-audio-files/en_NatGen_Medical_DocDictation.m4a", "rb") as audio_file:
audio_data = {"buffer": audio_file, "mimetype": "audio/mp4"}
response = dg_client.transcription.prerecorded(audio_data, {"model": "whisper"})
task = loop.create_task(
response
) # Schedule the coroutine to run in the background
result = loop.run_until_complete(
task
) # Execute the coroutine and get the result
print("text", result)
if __name__ == "__main__":
transcribe() |
Beta Was this translation helpful? Give feedback.
-
Thank you so much for your help. Finally I got the data in Json format is there any way to get the transcript in text format directly
|
Beta Was this translation helpful? Give feedback.
-
Thank you for your response. It helped. I would like to know that how to get speaker information from this transcription. |
Beta Was this translation helpful? Give feedback.
I can't quite tell how
audio_file
is getting created, but it sounds like it's anio.BytesIO
object. Anio.BytesIO
object cannot be passed to the Deepgram SDK. Instead, you'll need to pass anio.BufferedReader
object. Luckily, the conversation is very simple! You can convert it viaio.BufferedReader(audio_data)
.Below is a synchronous example that demonstrates how this works: