Appearance
For clean Markdown of any page, append .md to the page URL. For a complete documentation index, see For full documentation content, see For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at
🦜️🔗 LangChain JavaScript Integration with AssemblyAI
Transcribe audio in LangChain.JS using the built-in integration with AssemblyAI.
For the complete documentation index, see llms.txt
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 Python integration? Go to the LangChain Python integration.
Quickstart
Add the AssemblyAI SDK to your project:
bash
npm install langchain @langchain/communitybash
yarn add langchain @langchain/communitybash
pnpm add langchain @langchain/communitybash
bun add langchain @langchain/communityTo use the loaders, you need an AssemblyAI account and get your AssemblyAI API key from the dashboard. Configure the API key as the ASSEMBLYAI_API_KEY environment variable or the apiKey options parameter.
javascript
import {
AudioTranscriptLoader,
// AudioTranscriptParagraphsLoader,
// AudioTranscriptSentencesLoader
} from "@langchain/community/document_loaders/web/assemblyai";
// You can also use a local file path and the loader will upload it to AssemblyAI for you.
const audioUrl = "";
// Use `AudioTranscriptParagraphsLoader` or `AudioTranscriptSentencesLoader` for splitting the transcript into paragraphs or sentences
const loader = new AudioTranscriptLoader(
{
audio: audioUrl,
// any other parameters as documented here:
},
{
apiKey: "<ASSEMBLYAI_API_KEY>", // or set the `ASSEMBLYAI_API_KEY` env variable
}
);
const docs = await loader.load();
console.dir(docs, { depth: Infinity });- You can use the
AudioTranscriptParagraphsLoaderorAudioTranscriptSentencesLoaderto split the transcript into paragraphs or sentences. - If theaudio_fileis a local file path, the loader will upload it to AssemblyAI for you. - Theaudio_filecan also be a video file. See the list of supported file types in the FAQ doc. - If you don't pass in theapiKeyoption, the loader will use theASSEMBLYAI_API_KEYenvironment variable. - You can add more properties in addition toaudio. Find the full list of request parameters in the AssemblyAI API docs.
You can also use the AudioSubtitleLoader to get srt or vtt subtitles as a document.
javascript
import { AudioSubtitleLoader } from "@langchain/community/document_loaders/web/assemblyai";
// You can also use a local file path and the loader will upload it to AssemblyAI for you.
const audioUrl = "";
const loader = new AudioSubtitleLoader(
{
audio: audioUrl,
// any other parameters as documented here:
},
"srt", // srt or vtt
{
apiKey: "<ASSEMBLYAI_API_KEY>", // or set the `ASSEMBLYAI_API_KEY` env variable
}
);
const docs = await loader.load();
console.dir(docs, { depth: Infinity });Additional resources
You can learn more about using LangChain with AssemblyAI in these resources:
- The LangChain docs for the AssemblyAI document loader
- How to integrate spoken audio into LangChain.js using AssemblyAI
- Integrate Audio into LangChain.js apps in 5 Minutes
- AssemblyAI JavaScript SDK