MLX Transcribe 是一款使用 MLX Whisper 转写音频文件的工具。

前提条件

  1. 安装 ffmpeg

  2. 安装 mlx-whisper 库

    pip install mlx-whisper
    
  3. 准备音频文件

    • 创建一个 ‘storage/audio’ 目录
    • 将您的音频文件放入此目录
    • 支持的格式:mp3, mp4, wav 等。
  4. 下载示例音频 (可选)

    • 前往 audio-samples (作为示例),并将音频文件保存至 storage/audio 目录。

示例

以下 Agent 将使用 MLX Transcribe 来转写音频文件。

cookbook/tools/mlx_transcribe_tools.py

from pathlib import Path
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.mlx_transcribe import MLXTranscribeTools

# 从 storage/audio 目录获取音频文件
agno_root_dir = Path(__file__).parent.parent.parent.resolve()
audio_storage_dir = agno_root_dir.joinpath("storage/audio")
if not audio_storage_dir.exists():
    audio_storage_dir.mkdir(exist_ok=True, parents=True)

agent = Agent(
    name="Transcription Agent",
    model=OpenAIChat(id="gpt-4o"),
    tools=[MLXTranscribeTools(base_dir=audio_storage_dir)],
    instructions=[
        "要转写音频文件,请使用 `transcribe` 工具,并将音频文件名作为参数。",
        "您可以使用 `read_files` 工具查找所有可用的音频文件。",
    ],
    markdown=True,
)

agent.print_response("总结 Reid Hoffman 的 TED 演讲,并将其分成几个部分", stream=True)

Toolkit 参数

参数类型默认值描述
base_dirPathPath.cwd()音频文件的基础目录
read_files_in_base_dirboolTrue是否注册 read_files 函数
path_or_hf_repostr"mlx-community/whisper-large-v3-turbo"模型的路径或 HuggingFace 仓库
verboseboolNone启用详细输出
temperaturefloatTuple[float, ...]None采样温度
compression_ratio_thresholdfloatNone压缩率阈值
logprob_thresholdfloatNone对数概率阈值
no_speech_thresholdfloatNone无语音阈值
condition_on_previous_textboolNone是否基于先前文本进行条件设置
initial_promptstrNone转写的初始提示
word_timestampsboolNone启用词级时间戳
prepend_punctuationsstrNone在句首添加的标点符号
append_punctuationsstrNone在句尾添加的标点符号
clip_timestampsstrList[float]None裁剪时间戳
hallucination_silence_thresholdfloatNone幻觉静默阈值
decode_optionsdictNone其他解码选项

Toolkit 函数

函数描述
transcribe使用 MLX Whisper 转写音频文件
read_files列出基础目录中的所有音频文件

开发者资源