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

ParameterTypeDescription
sourceBuffer, UrlProvides the source of audio to transcribe
optionsObjectParameters 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.