Skip to main content

AssemblyAI 音频记录

¥AssemblyAI Audio Transcript

本概述如何使用 AssemblyAI API 从文件加载音频(和视频)转录文本作为文档对象。

¥This covers how to load audio (and video) transcripts as document objects from a file using the AssemblyAI API.

用法

¥Usage

首先,你需要安装官方 AssemblyAI 软件包:

¥First, you'll need to install the official AssemblyAI package:

npm install @langchain/community @langchain/core assemblyai

要使用加载器,你需要一个 AssemblyAI 账户 和一个 从仪表板获取 AssemblyAI API 密钥

¥To use the loaders you need an AssemblyAI account and get your AssemblyAI API key from the dashboard.

然后,将 API 密钥配置为 ASSEMBLYAI_API_KEY 环境变量或 apiKey 选项参数。

¥Then, configure the API key as the ASSEMBLYAI_API_KEY environment variable or the apiKey options parameter.

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 = "https://storage.googleapis.com/aai-docs-samples/espn.m4a";

// Use `AudioTranscriptParagraphsLoader` or `AudioTranscriptSentencesLoader` for splitting the transcript into paragraphs or sentences
const loader = new AudioTranscriptLoader(
{
audio: audioUrl,
// any other parameters as documented here: https://www.assemblyai.com/docs/api-reference/transcripts/submit
},
{
apiKey: "<ASSEMBLYAI_API_KEY>", // or set the `ASSEMBLYAI_API_KEY` env variable
}
);
const docs = await loader.load();
console.dir(docs, { depth: Infinity });

API Reference:

信息

¥ info

  • 你可以使用 AudioTranscriptParagraphsLoaderAudioTranscriptSentencesLoader 将文本拆分为段落或句子。

    ¥You can use the AudioTranscriptParagraphsLoader or AudioTranscriptSentencesLoader to split the transcript into paragraphs or sentences.

  • audio 参数可以是 URL、本地文件路径、缓冲区或流。

    ¥The audio parameter can be a URL, a local file path, a buffer, or a stream.

  • audio 也可以是视频文件。请参阅 常见问题解答文档中支持的文件类型列表

    ¥The audio can also be a video file. See the list of supported file types in the FAQ doc.

  • 如果你未传入 apiKey 选项,加载器将使用 ASSEMBLYAI_API_KEY 环境变量。

    ¥If you don't pass in the apiKey option, the loader will use the ASSEMBLYAI_API_KEY environment variable.

  • 除了 audio 之外,你还可以添加更多属性。在 AssemblyAI API 文档 中查找完整的请求参数列表。

    ¥You can add more properties in addition to audio. Find the full list of request parameters in the AssemblyAI API docs.

你还可以使用 AudioSubtitleLoadersrtvtt 字幕作为文档获取。

¥You can also use the AudioSubtitleLoader to get srt or vtt subtitles as a document.

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 = "https://storage.googleapis.com/aai-docs-samples/espn.m4a";

const loader = new AudioSubtitleLoader(
{
audio: audioUrl,
// any other parameters as documented here: https://www.assemblyai.com/docs/api-reference/transcripts/submit
},
"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 });

API Reference: