Documentation Index Fetch the complete documentation index at: https://assemblyai.com/docs/llms.txt
Use this file to discover all available pages before exploring further.
Universal-2 offers accurate, cost-effective transcription across 99 languages with low latency. It supports code switching and optional keyterms prompting for domain-specific vocabulary (up to 200 words).
Key capabilities
99 language support: Transcribe audio in 99 languages with high accuracy
Keyterms prompting: Improve recognition of up to 200 domain-specific terms, rare words, and proper nouns
Code switching: Handle audio that switches between languages
Supported languages
View all 99 supported languages
Quickstart
Get started with Universal-2 using the code below. This example transcribes a pre-recorded audio file using the Universal-2 model and prints the transcript text to your terminal.
Python
Python SDK
JavaScript
JavaScript SDK
Install the required library
Create a new file main.py and paste the code below. Replace <YOUR_API_KEY> with your API key.
import requests
import time
base_url = "https://api.assemblyai.com"
headers = { "authorization" : "<YOUR_API_KEY>" }
data = {
"audio_url" : "https://assembly.ai/wildfires.mp3" ,
"speech_models" : [ "universal-2" ],
"language_detection" : True
}
response = requests.post(base_url + "/v2/transcript" , headers = headers, json = data)
if response.status_code != 200 :
print ( f "Error: { response.status_code } , Response: { response.text } " )
response.raise_for_status()
transcript_response = response.json()
transcript_id = transcript_response[ "id" ]
polling_endpoint = f " { base_url } /v2/transcript/ { transcript_id } "
while True :
transcript = requests.get(polling_endpoint, headers = headers).json()
if transcript[ "status" ] == "completed" :
print (transcript[ "text" ])
break
elif transcript[ "status" ] == "error" :
raise RuntimeError ( f "Transcription failed: { transcript[ 'error' ] } " )
else :
time.sleep( 3 )
See all 31 lines
Install the required library pip install "assemblyai>=1.0.0"
Create a new file main.py and paste the code below. Replace <YOUR_API_KEY> with your API key.
import assemblyai as aai
aai.settings.api_key = "<YOUR_API_KEY>"
audio_file = "https://assembly.ai/wildfires.mp3"
config = aai.TranscriptionConfig(
speech_models = [ "universal-2" ],
language_detection = True ,
)
transcript = aai.Transcriber().transcribe(audio_file, config)
print (transcript.text)
Install the required library
Create a new file index.mjs and paste the code below. Replace <YOUR_API_KEY> with your API key.
const baseUrl = "https://api.assemblyai.com" ;
const headers = {
authorization: "<YOUR_API_KEY>" ,
};
const data = {
audio_url: "https://assembly.ai/wildfires.mp3" ,
speech_models: [ "universal-2" ],
language_detection: true ,
};
const url = ` ${ baseUrl } /v2/transcript` ;
let res = await fetch ( url , {
method: "POST" ,
headers: { ... headers , "Content-Type" : "application/json" },
body: JSON . stringify ( data ),
});
if ( ! res . ok ) throw new Error ( `Error: ${ res . status } ` );
const response = await res . json ();
const transcriptId = response . id ;
const pollingEndpoint = ` ${ baseUrl } /v2/transcript/ ${ transcriptId } ` ;
while ( true ) {
res = await fetch ( pollingEndpoint , { headers });
if ( ! res . ok ) throw new Error ( `Error: ${ res . status } ` );
const transcriptionResult = await res . json ();
if ( transcriptionResult . status === "completed" ) {
console . log ( transcriptionResult . text );
break ;
} else if ( transcriptionResult . status === "error" ) {
throw new Error ( `Transcription failed: ${ transcriptionResult . error } ` );
} else {
await new Promise (( resolve ) => setTimeout ( resolve , 3000 ));
}
}
See all 37 lines
Install the required library
Create a new file index.mjs and paste the code below. Replace <YOUR_API_KEY> with your API key.
import { AssemblyAI } from "assemblyai" ;
const client = new AssemblyAI ({
apiKey: "<YOUR_API_KEY>" ,
});
const audioFile = "https://assembly.ai/wildfires.mp3" ;
const params = {
audio: audioFile ,
speech_models: [ "universal-2" ],
language_detection: true ,
};
const run = async () => {
const transcript = await client . transcripts . transcribe ( params );
console . log ( transcript . text );
};
run ();