Skip to main content
The SpeechToTextLoader 允许通过 Google Cloud Speech-to-Text API 转录音频文件并将转录文本加载到文档中。 使用该功能前,您需要安装 google-cloud-speech Python 包,并拥有已启用 Speech-to-Text API 的 Google Cloud 项目。

安装与配置

首先需要安装 google-cloud-speech Python 包。 更多详情请参考 Speech-to-Text 客户端库 页面。 按照 Google Cloud 文档中的 快速入门指南 创建项目并启用 API。

示例

SpeechToTextLoader 必须包含 project_id 和 file_path 参数。音频文件可通过 Google Cloud Storage URI(gs://...)或本地文件路径指定。 该加载器仅支持同步请求,对单个音频文件有 60秒或10MB 的限制。
注意:调用 loader.load() 会阻塞直到转录完成。 转录文本将保存在 page_content 中:
metadata 包含完整的JSON响应及更多元数据:

识别配置

可通过 config 参数指定不同语音识别模型并启用特定功能。 参考 Speech-to-Text 识别器文档 和 RecognizeRequest API 参考文档以了解如何设置自定义配置。 未指定 config 时,系统将自动选择以下默认配置:

官方原文:src/oss/python/integrations/document_loaders/google_speech_to_text.mdx · 非官方翻译,译文由 AI 生成,以英文原文为准。
Last modified on November 3, 2026