🦜️🔗 LangChain Python Integration with AssemblyAI
To apply LLMs to speech, you first need to transcribe the audio to text, which is what the AssemblyAI integration for LangChain helps you with.
Looking for the LangChain JavaScript integration?
Go to the LangChain.JS integration.
Quickstart
Install the AssemblyAI package and the AssemblyAI Python SDK:
Set your AssemblyAI API key as an environment variable named ASSEMBLYAI_API_KEY. You can get a free AssemblyAI API key from the AssemblyAI dashboard.
Import the AssemblyAIAudioTranscriptLoader from langchain.document_loaders.
- Pass the local file path or URL as the
file_pathargument of theAssemblyAIAudioTranscriptLoader. - Call the
loadmethod to get the transcript as LangChain documents.
The load method returns an array of documents, but by default, there’s only one document in the array with the full transcript.
The transcribed text is available in the page_content attribute:
The metadata contains the full JSON response with more meta information:
Transcript formats
You can specify the transcript_format argument to load the transcript in different formats.
Depending on the format, load_data() returns either one or more documents. 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
Transcription config
You can also specify the config argument to use different transcript features and audio intelligence models.
Here’s an example of using the config argument to enable speaker labels, auto chapters, and entity detection:
For the full list of options, see Transcript API reference.
Pass the AssemblyAI API key as an argument
Instead of configuring the AssemblyAI API key as the ASSEMBLYAI_API_KEY environment variable,
you can also pass it as the api_key argument.
Additional resources
You can learn more about using LangChain with AssemblyAI in these resources.