Transcribe a pre-recorded audio file
Overview
By the end of this tutorial, you’ll be able to:
- Transcribe a pre-recorded audio file.
- Select the speech model for your request (optional).
Here’s the full sample code for what you’ll build in this tutorial:
Python SDK
Python
JavaScript SDK
JavaScript
Before you begin
To complete this tutorial, you need:
- If opting to use the Python or Python SDK code, you will need Python installed.
- If opting to use the JavaScript or JavaScript SDK code, you will need Node.js installed.
-
A free AssemblyAI account.
Step 1: Install the necessary libraries
Python SDK
Python
JavaScript SDK
JavaScript
Step 2: Configure your request
Python SDK
Python
JavaScript SDK
JavaScript
In this step, you’ll create an SDK client and configure it to use your API key.
Browse to API Keys in your dashboard, and then copy your API key.
Create a new Transcriber and configure it to use your API key. Replace YOUR_API_KEY with your copied API key.
Specify a URL to the audio you want to transcribe. The URL needs to be accessible from AssemblyAI’s servers. For a list of supported formats, see FAQ.
Creating self hosted audio URLs
You can use a service like Amazon S3, Google Cloud Storage, or any platform that supports direct file access to generate a shareable audio file URL. Check out this cookbook on how to transcribe from an S3 bucket.
Local audio files
If you want to use a local file, you can also specify a local path, for example:
YouTube
YouTube URLs are not supported. If you want to transcribe a YouTube video, you need to download the audio first.
Step 3: Select the speech model (optional)
AssemblyAI offers multiple speech models optimized for different use cases. You can use the speech_models parameter to specify which model to use for your transcription.
The available models are:
- Universal (default): Best for out-of-the-box transcription with multi-language support and excellent accuracy.
- Slam-1 (beta): Highest accuracy for English content with fine-tuning support and customization via prompting.
For more details on model capabilities and pricing, see Models.
If you do not specify a speech model, the Universal model will be used by default.
Python SDK
Python
JavaScript SDK
JavaScript
To specify a speech model, create a TranscriptionConfig with the speech_models parameter:
You can also specify multiple models in priority order. The system will use the first compatible model:
For more information on selecting speech models, see Select the speech model.
Step 4: Submit for transcription
Python SDK
Python
JavaScript SDK
JavaScript
To generate the transcript, pass the audio_file or file to transcriber.transcribe(). This may take a minute while we’re processing the audio.
If you configured a TranscriptionConfig in Step 3, pass it to the transcribe() method:
Next steps
Want to learn more?
- For more ways to analyze your audio data, explore our Speech Understanding features.
- To search, summarize, and ask questions on your transcripts with LLMs, see LLM Gateway.
- For detailed endpoint documentation, see the API Reference.
Need some help?
If you get stuck, or have any other questions, we’d love to help you out. Contact our support team at support@assemblyai.com or create a support ticket.