llama-index readers assemblyai integration
Project description
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"
)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file llama_index_readers_assemblyai-0.3.0.tar.gz
.
File metadata
- Download URL: llama_index_readers_assemblyai-0.3.0.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.10 Darwin/22.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ca40f985869e8ffbc38a874c62b0078b881f179f9b3e64138d025ad24b0a201 |
|
MD5 | a0fff33f8b0b04a714b123bc9511af7c |
|
BLAKE2b-256 | 51feaa0e15df50c6ea9ee0bb3908f5a9b5a7ac82d8bb6701aef33da5736a8240 |
File details
Details for the file llama_index_readers_assemblyai-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: llama_index_readers_assemblyai-0.3.0-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.10 Darwin/22.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39525edeaa8bba709ca9aaf76e4893c54687b3290ec30e05c9a39c45fd96731d |
|
MD5 | bac8ce239d12524f3f12ca3cd5811d1e |
|
BLAKE2b-256 | d62e0b78cb7c8b75ddbee706086d9a74d139a0068a9ab48c0b4c68a32f842de9 |