πŸ¦œοΈπŸ”— LangChain JavaScript 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 Python integration?
Go to the LangChain Python integration.

Quickstart

Add the AssemblyAI SDK to your project:

$npm install langchain @langchain/community

To 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.

1import {
2 AudioTranscriptLoader,
3 // AudioTranscriptParagraphsLoader,
4 // AudioTranscriptSentencesLoader
5} from "@langchain/community/document_loaders/web/assemblyai";
6
7// You can also use a local file path and the loader will upload it to AssemblyAI for you.
8const audioUrl = "https://assembly.ai/espn.m4a";
9
10// Use `AudioTranscriptParagraphsLoader` or `AudioTranscriptSentencesLoader` for splitting the transcript into paragraphs or sentences
11const loader = new AudioTranscriptLoader(
12 {
13 audio: audioUrl,
14 // any other parameters as documented here: https://www.assemblyai.com/docs/api-reference/transcript#create-a-transcript
15 },
16 {
17 apiKey: "<ASSEMBLYAI_API_KEY>", // or set the `ASSEMBLYAI_API_KEY` env variable
18 }
19);
20const docs = await loader.load();
21console.dir(docs, { depth: Infinity });
  • You can use the AudioTranscriptParagraphsLoader or AudioTranscriptSentencesLoader to split the transcript into paragraphs or sentences. - If the audio_file is a local file path, the loader will upload it to AssemblyAI for you. - The audio_file can also be a video file. See the list of supported file types in the FAQ doc. - If you don’t pass in the apiKey option, the loader will use the ASSEMBLYAI_API_KEY environment variable. - You can add more properties in addition to audio. 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.

1import { AudioSubtitleLoader } from "@langchain/community/document_loaders/web/assemblyai";
2
3// You can also use a local file path and the loader will upload it to AssemblyAI for you.
4const audioUrl = "https://assembly.ai/espn.m4a";
5
6const loader = new AudioSubtitleLoader(
7 {
8 audio: audioUrl,
9 // any other parameters as documented here: https://www.assemblyai.com/docs/api-reference/transcript#create-a-transcript
10 },
11 "srt", // srt or vtt
12 {
13 apiKey: "<ASSEMBLYAI_API_KEY>", // or set the `ASSEMBLYAI_API_KEY` env variable
14 }
15);
16
17const docs = await loader.load();
18console.dir(docs, { depth: Infinity });

Additional resources

You can learn more about using LangChain with AssemblyAI in these resources: