Transcribe Audio and Load Transcripts
LlamaIndex reader that transcribes audio files via AssemblyAI into loadable documents.
Why it matters
Transcribe audio files using the AssemblyAI API and load the resulting text into documents for further processing or analysis. This asset bridges the gap between raw audio and structured text data.
Outcomes
What it gets done
Transcribe audio files from URLs or local paths.
Load transcribed text into LlamaIndex documents.
Support various transcript formats (text, sentences, paragraphs, SRT, VTT).
Configure transcription with advanced options like speaker labels and auto-chapters.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/li-reader-readers-assemblyai | bash Overview
AssemblyAI Audio Transcript Loader
The AssemblyAI Audio Transcript Loader transcribes audio via the AssemblyAI API into LlamaIndex documents, with format options (single document, per-sentence, per-paragraph, SRT/VTT subtitles) and optional audio-intelligence features like speaker labels and auto chapters. Use it when you need audio transcribed into LlamaIndex documents. It requires the assemblyai package and an API key, and load_data() blocks until transcription finishes.
What it does
The AssemblyAI Audio Transcript Loader transcribes audio files via the AssemblyAI API and loads the transcribed text into documents. Given at least a file_path (a URL or local path), AssemblyAIAudioTranscriptReader.load_data() blocks until transcription finishes, then returns documents whose text holds the transcript (for example "Load time, a new president and new congressional makeup. Same old ...") and whose metadata carries the full JSON response, including fields like language_code (an enum such as LanguageCode.en_us), audio_url, punctuate, and format_text.
When to use - and when NOT to
Use it when you need to turn audio (a URL or local file) into LlamaIndex documents -- as one document, split by sentence or paragraph, or exported as SRT/VTT subtitles -- optionally enriched with audio-intelligence features like speaker labels, auto chapters, or entity detection. It requires the assemblyai Python package and an AssemblyAI API key (via the ASSEMBLYAI_API_KEY environment variable or an api_key argument), and it blocks until transcription completes, so it is not a fit for a fire-and-forget or fully async workflow without extra handling.
Inputs and outputs
Install with:
pip install llama-index-readers-assemblyai
Transcribe a file (URL or local path) and load it as documents:
from llama_index.readers.assemblyai import AssemblyAIAudioTranscriptReader
audio_file = "https://storage.googleapis.com/aai-docs-samples/nbc.mp3"
### or a local file path: audio_file = "./nbc.mp3"
reader = AssemblyAIAudioTranscriptReader(file_path=audio_file)
docs = reader.load_data()
transcript_format controls how many documents come back: TEXT (one document), SENTENCES or PARAGRAPHS (one document per sentence or paragraph), or SUBTITLES_SRT/SUBTITLES_VTT (one document in that subtitle format). config accepts an aai.TranscriptionConfig to turn on models like speaker_labels, auto_chapters, or entity_detection -- the AssemblyAI API documentation lists the full set of available models. The API key can be set via ASSEMBLYAI_API_KEY or passed directly as api_key; a free API key is available by signing up on AssemblyAI's website, which also hosts the full API documentation.
Who it's for
Developers building LlamaIndex pipelines that need transcribed audio content -- podcasts, calls, recordings -- as documents, with optional speaker, chapter, or entity metadata attached.
Source README
AssemblyAI Audio Transcript Loader
pip install llama-index-readers-assemblyai
The AssemblyAI Audio Transcript Loader allows to transcribe audio files with the AssemblyAI API and loads the transcribed text into documents.
To use it, you should have the assemblyai python package installed, and the environment variable ASSEMBLYAI_API_KEY set with your API key. Alternatively, the API key can also be passed as an argument.
More info about AssemblyAI:
Usage
The AssemblyAIAudioTranscriptReader needs at least the file_path argument. Audio files can be specified as an URL or a local file path.
from llama_index.readers.assemblyai import AssemblyAIAudioTranscriptReader
audio_file = "https://storage.googleapis.com/aai-docs-samples/nbc.mp3"
### or a local file path: audio_file = "./nbc.mp3"
reader = AssemblyAIAudioTranscriptReader(file_path=audio_file)
docs = reader.load_data()
Note: Calling reader.load_data() blocks until the transcription is finished.
The transcribed text is available in the text:
docs[0].text
### "Load time, a new president and new congressional makeup. Same old ..."
The metadata contains the full JSON response with more meta information:
docs[0].metadata
### {'language_code': <LanguageCode.en_us: 'en_us'>,
### 'audio_url': 'https://storage.googleapis.com/aai-docs-samples/nbc.mp3',
### 'punctuate': True,
### 'format_text': True,
### ...
### }
Transcript Formats
You can specify the transcript_format argument for different formats.
Depending on the format, one or more documents are returned. These are the different TranscriptFormat options:
TEXT: One document with the transcription textSENTENCES: Multiple documents, splits the transcription by each sentencePARAGRAPHS: Multiple documents, splits the transcription by each paragraphSUBTITLES_SRT: One document with the transcript exported in SRT subtitles formatSUBTITLES_VTT: One document with the transcript exported in VTT subtitles format
from llama_index.readers.assemblyai import TranscriptFormat
reader = AssemblyAIAudioTranscripReader(
file_path="./your_file.mp3",
transcript_format=TranscriptFormat.SENTENCES,
)
docs = reader.load_data()
Transcription Config
You can also specify the config argument to use different audio intelligence models.
Visit the AssemblyAI API Documentation to get an overview of all available models!
import assemblyai as aai
config = aai.TranscriptionConfig(
speaker_labels=True, auto_chapters=True, entity_detection=True
)
reader = AssemblyAIAudioTranscriptReader(
file_path="./your_file.mp3", config=config
)
Pass the API Key as argument
Next to setting the API key as environment variable ASSEMBLYAI_API_KEY, it is also possible to pass it as argument.
reader = AssemblyAIAudioTranscriptReader(
file_path="./your_file.mp3", api_key="YOUR_KEY"
)
FAQ
Common questions
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.