Skip to content

ASR / TTS 插件

ASR / TTS / Source 共用 plugin-kit 基础设施(启停、配置、清单加载工具),业务接口按能力区分:

  • 目录约定:storage/plugins/{asr|tts}/<dir>/plugin.json + 入口 ESM
  • 启停 / 配置 / rescan 热加载
  • 内置插件代码注册;外部插件本地扫描
  • 管理 API 与设置页 UI

目录

text
storage/plugins/
  source/   # 内容获取
  asr/      # 语音转写
  tts/      # 语音合成

API

方法路径说明
GET/api/asr-plugins列表
POST/api/asr-plugins/rescan热扫描
PATCH/api/asr-plugins/:id{ "enabled": true/false }
POST/api/asr-plugins/:id/reset恢复 defaultEnabled
PUT/api/asr-plugins/:id/config保存参数
POST/api/asr-plugins/:id/config/reset清空参数

TTS 将前缀换成 /api/tts-plugins

激活哪个插件(严格)

运行时 只使用 设置中的 asrProvider / ttsProvider。 未启用 / 不可用时会直接报错,不会静默切换到其他提供方。

  • 设置 → AI 服务 中的 asrProvider / ttsProvider 选择激活插件 id
  • 设置 → 插件 页切换「语音转写 / 语音合成」管理启停与参数;「设为当前」可写入 asrProvider / ttsProvider
  • 未启用或不可用时,会回落其它已启用可用插件,最后是 demo

外部插件清单

plugin.json 字段与 Source 一致(id/name/version/entry/apiVersion/...)。

ASR 导出

js
export default {
  id: 'asr.xxx',
  name: '...',
  version: '0.1.0',
  riskLevel: 'low',
  defaultEnabled: false,
  isAvailable() { return true },
  async transcribe(input, ctx) {
    // input.audioPath / format / model
    // ctx.getConfig('key')
    return { text: '...', provider: 'asr.xxx' }
  },
}

TTS 导出

js
export default {
  id: 'tts.xxx',
  name: '...',
  version: '0.1.0',
  riskLevel: 'low',
  defaultEnabled: false,
  meta: {
    id: 'tts.xxx',
    name: '...',
    description: '...',
    modes: [{ id: 'default', label: '默认' }],
    // ★ 插件自己声明音色页(宿主只渲染,不固定布局)
    voicePanel: {
      version: 1,
      fields: [
        { type: 'voiceGrid' },
        { type: 'text', bind: 'voice', label: '或手填音色 ID' },
      ],
    },
    voiceConfigKey: 'defaultVoice',
    voices: [{ id: 'v1', name: '音色 A' }],
    supportsStyleTags: false,
    supportsVoiceDesign: false,
    maxCharsPerRequest: 2000,
    suggestedModels: { tts: 'xxx', defaultVoice: 'v1' },
  },
  isAvailable() { return true },
  async synthesizeChunk(input, ctx) {
    // input.tts?.voice = 任务覆盖;否则读 ctx.getConfig(voiceConfigKey)
    return { audio: Buffer.from(...), format: 'wav', provider: 'tts.xxx' }
  },
}

开发规范:

示例

bash
# 演示插件
cp -R examples/asr-plugin-echo storage/plugins/asr/echo-asr
cp -R examples/tts-plugin-echo storage/plugins/tts/echo-tts

# Fish Speech / Fish Audio TTS
cp -R examples/tts-plugin-fishspeech storage/plugins/tts/fishspeech

curl -X POST http://localhost:8787/api/asr-plugins/rescan
curl -X POST http://localhost:8787/api/tts-plugins/rescan

音色面板(voicePanel)——插件自己画页面

宿主不固定音色页布局。 插件在 meta.voicePanel.fields 声明字段,前端通用渲染。

js
meta: {
  voicePanel: {
    version: 1,
    title: '我的音色页',
    fields: [
      { type: 'info', text: '任意提示' },
      { type: 'voiceGrid' }, // 或 text/select/tags/actions/...
    ],
  },
  voiceConfigKey: 'defaultVoice', // 插件配置默认音色字段
}

内置字段类型:info · modeTabs · voiceGrid · text · textarea · select · tags · effectiveSummary · actions

旧插件可继续用 voiceUi 简写,宿主会编译成 voicePanel
完整规范:TTS 插件开发

Fish Speech(tts.fishspeech)

接入 Fish Audio 云端或自托管 Fish Speech

  1. 复制插件到 storage/plugins/tts/fishspeech
  2. 扫描后填写 baseUrl / apiKey / referenceId
  3. 启用插件,并将 ttsProvider 设为 tts.fishspeech

详见 examples/tts-plugin-fishspeech/README.md

仓库地址:https://github.com/vastsa/BokeBox
协议:LGPL-3.0

后台上传安装

设置页「插件中心」支持上传 .zip 插件包(也可继续手动放入 storage/plugins/<kind>/ 后扫描)。 zip 根目录或唯一子目录需包含 plugin.json 与入口文件;同 id 默认覆盖安装,外部插件可卸载。

相关