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.
If you’d prefer to use one of our official SDKs, check our documentation for the full list of available SDKs.
The Gladia
documentation
uses cURL commands to demonstrate API usage. In this guide, we will use Python
code snippets to illustrate the same functionality across both APIs. If you
prefer to use cURL, you can find the equivalent commands in the AssemblyAI
API Reference.
Below is a side-by-side comparison of a basic snippet to transcribe pre-recorded audio with Gladia and AssemblyAI:
Gladia
AssemblyAI
import requestsimport timebase_url = "https://api.gladia.io"headers = { "x-gladia-key": "<YOUR_API_KEY>"}with open("./my-audio.mp3", "rb") as f: files = {"audio": ("my-audio.mp3", f, "audio/mp3")} response = requests.post(base_url + "/v2/upload", headers=headers, files=files)upload_url = response.json()["audio_url"]data = { "audio_url": upload_url # You can also use a URL to an audio or video file on the web.}url = base_url + "/v2/pre-recorded"response = requests.post(url, json=data, headers=headers)transcript_id = response.json()['id'] # You can also use response.json()['result_url'] to get the polling_endpoint directly.polling_endpoint = url + "/" + transcript_idwhile True: transcript = requests.get(polling_endpoint, headers=headers).json() if transcript['status'] == 'done': print(f"Full Transcript: {transcript['result']['transcription']['full_transcript']}") break elif transcript['status'] == 'error': raise RuntimeError(f"Transcription failed: {transcript['error_code']}") else: time.sleep(3)
import requestsimport timebase_url = "https://api.assemblyai.com"headers = { "authorization": "<YOUR_API_KEY>"}with open("./my-audio.mp3", "rb") as f: response = requests.post(base_url + "/v2/upload", headers=headers, data=f)upload_url = response.json()["upload_url"]data = { "audio_url": upload_url, # You can also use a URL to an audio or video file on the web "speech_models": ["universal-3-pro", "universal-2"], "language_detection": True,}url = base_url + "/v2/transcript"response = requests.post(url, json=data, headers=headers)transcript_id = response.json()['id']polling_endpoint = url + "/" + transcript_idwhile True: transcript = requests.get(polling_endpoint, headers=headers).json() if transcript['status'] == 'completed': print(f"Full Transcript: {transcript['text']}") break elif transcript['status'] == 'error': raise RuntimeError(f"Transcription failed: {transcript['error']}") else: time.sleep(3)
Transcription statusNote that our APIs possible values for transcription status are queued, processing, completed, and error. Check out the AssemblyAI API Reference for the full list of possible transcription status values.
If you’d rather not poll the API, you can use our SDKs which handle polling internally. Alternatively, you can also use webhooks to get notified when your transcript is complete.
Here are helpful things to know when migrating your audio input handling:
Both AssemblyAI and Gladia allow you the option of uploading a local file or specifying a publicly accessible URL.