Migration guide: Deepgram to AssemblyAI

This guide walks through the process of migrating from Deepgram to AssemblyAI.

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():
12try:
13deepgram = 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
29 response = deepgram.listen.prerecorded.v("1").transcribe_file(payload, options)
30
31 print(response.to_json(indent=4))
32
33except Exception as e:
34print(f"Exception: {e}")
35
36if name == "main":
37main()

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():
13try:
14deepgram = 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":
30main()

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
Check our documentation for the full list of available SDKs

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(
11smart_format=True,
12summarize="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(
25smart_format=True,
26summarize="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