Migration guide: Deepgram to AssemblyAI

This guide walks through the process of migrating from Deepgram to AssemblyAI for transcribing pre-recorded audio.

Get Started

Before we begin, make sure you have an AssemblyAI account and an API key. You can sign up for a free account and get your API key from your dashboard.

Side-By-Side Code Comparison

Below is a side-by-side comparison of a basic snippet to transcribe a local file by Deepgram and AssemblyAI:

1from deepgram import (
2 DeepgramClient,
3 PrerecordedOptions,
4 FileSource,
5)
6
7API_KEY = "YOUR_DG_API_KEY"
8
9AUDIO_FILE = "./example.wav"
10
11def main():
12 try:
13 deepgram = DeepgramClient(API_KEY)
14
15 with open(AUDIO_FILE, "rb") as file:
16 buffer_data = file.read()
17
18 payload: FileSource = {
19 "buffer": buffer_data,
20 }
21
22 options = PrerecordedOptions(
23 model="nova-2",
24 smart_format=True,
25 diarize=True
26 )
27
28 response = deepgram.listen.prerecorded.v("1").transcribe_file(payload, options)
29
30 print(response.to_json(indent=4))
31
32 except Exception as e:
33 print(f"Exception: {e}")
34
35if name == "main":
36 main()

Below is a side-by-side comparison of a basic snippet to transcribe a publicly-accessible URL by Deepgram and AssemblyAI:

1from deepgram import (
2 DeepgramClient,
3 PrerecordedOptions
4)
5
6API_KEY = "YOUR_DG_API_KEY"
7
8AUDIO_URL = {
9 "url": "https://dpgr.am/spacewalk.wav"
10}
11
12def main():
13 try:
14 deepgram = DeepgramClient(API_KEY)
15
16 options = PrerecordedOptions(
17 model="nova-2",
18 smart_format=True,
19 diarize=True
20 )
21
22 response = deepgram.listen.prerecorded.v("1").transcribe_url(AUDIO_URL, options)
23
24 print(response.to_json(indent=4))
25
26 except Exception as e:
27 print(f"Exception: {e}")
28
29if name == "main":
30 main()

Here are helpful things to know about our transcribe method:

  • The SDK handles polling under the hood
  • Transcript is directly accessible via transcript.text
  • English is the default language and Best is the default speech model if none is specified
  • We have a cookbook for error handling common errors when using our API.

Installation

1from deepgram import (
2 DeepgramClient,
3 PrerecordedOptions,
4 FileSource,
5)
6
7API_KEY = "YOUR_DG_API_KEY"
8deepgram = DeepgramClient(API_KEY)

When migrating from Deepgram to AssemblyAI, you’ll first need to handle authentication and SDK setup:

Get your API key from your AssemblyAI dashboard
To follow this guide, install AssemblyAI’s Python SDK by typing this code into your terminal:
pip install assemblyai

Things to know:

  • Store your API key securely in an environment variable
  • API key authentication works the same across all AssemblyAI SDKs

Audio File Sources

1# Local Files
2AUDIO_FILE = "example.wav"
3with open(AUDIO_FILE, "rb") as file:
4 buffer_data = file.read()
5
6payload: FileSource = {
7 "buffer": buffer_data,
8}
9
10options = PrerecordedOptions(
11 smart_format=True,
12 summarize="v2",
13)
14
15file_response = deepgram.listen.rest.v("1").transcribe_file(payload, options)
16
17json = file_response.to_json()
18
19#Public URLs
20AUDIO_URL = {
21 "url": "https://static.deepgram.com/examples/Bueller-Life-moves-pretty-fast.wav"
22}
23
24options = PrerecordedOptions(
25 smart_format=True,
26 summarize="v2"
27)
28
29url_response = deepgram.listen.rest.v("1").transcribe_url(AUDIO_URL, options)
30
31json = url_response.to_json()

Here are helpful things to know when migrating your audio input handling:

Adding Features

1options = PrerecordedOptions(
2 model="nova-2",
3 smart_format=True,
4 diarize=True,
5 detect_entities=True
6)
7
8response = deepgram.listen.prerecorded.v("1").transcribe_url(AUDIO_URL, options)

Key differences:

  • Use aai.TranscriptionConfig to specify any extra features that you wish to use
  • The results for Speaker Diarization are stored in transcript.utterances. To see the full transcript response object, refer to our API Reference.
  • Check our documentation for our full list of available features and their parameters