Pre-Recorded Audio Transcription
An overview of the Deepgram Python SDK and Deepgram speech-to-text pre-recorded.
The Deepgram Prerecorded Client
allows you to request transcripts for pre-recorded audio. To request a transcript for a pre-recorded particular audio file, you'll use one of the following functions depending on your audio source:
Pre-recorded Transcription Parameters
Parameter | Type | Description |
---|---|---|
source | Buffer, Url | Provides the source of audio to transcribe |
options | Object | Parameters to filter requests. See below. |
You can pass a Buffer or URL to a file to transcribe. Here's how to construct each:
Sending a URL
source = {'url': URL_TO_AUDIO_FILE}
Sending a Buffer
Open a file and send the buffer returned. You will also need to provide the MIMETYPE of the file.
with open(PATH_TO_FILE, 'rb') as audio:
source = {'buffer': audio}
Pre-recorded Transcription Options
Additional transcription options can be provided for pre-recorded transcriptions. They are provided as an object as the second parameter of the transcription.prerecorded
function. Each of these parameters map to a feature in the Deepgram API. Reference the features documentation to learn what features may be appropriate for your request.
Pre-recorded Transcription Example Request
With the source you chose above, call the transcription.prerecorded
function and provide any additional options as an object.
try:
# STEP 1 Create a Deepgram client using the DEEPGRAM_API_KEY from environment variables
deepgram = DeepgramClient()
# STEP 2 Call the transcribe_url method on the prerecorded class
options = PrerecordedOptions(
model="nova-2",
smart_format=True,
summarize="v2",
)
url_response = deepgram.listen.prerecorded.v("1").transcribe_url(
AUDIO_URL, options
)
print(url_response)
except Exception as e:
print(f"Exception: {e}")
Where To Find Additional Examples
The repository has a good collection of live audio transcription examples. You can find links to them in the README. Each example below will attempt to provide different options on how you might transcribe an audio source.
- From an Audio File - examples/prerecorded/file
- From an URL - examples/prerecorded/url
For larger files, you might need to increase the default HTTP Timeout setting, which is 300 seconds (or 5 mins).
# this will increase the timeout to 300 seconds or 5 minutes
response = deepgram.listen.prerecorded.v("1").transcribe_file(
payload, options, timeout=httpx.Timeout(300.0, connect=10.0)
)
Updated about 5 hours ago