Cool-UniX
uni-appX 跨端移动框架
 插件市场
插件市场Cool-UniX
uni-appX 跨端移动框架
Cool-Admin-Node
后台管理系统开发、Api接口开发
Cool-Admin-Java
后台管理系统开发、Api接口开发
Cool-Admin-Vue
后台管理系统开发前端
Cool Uni
移动端基于 uni-app 的跨端开发框架
Cool Flow Ai
开发Ai应用编排流程知识库知识图谱
Cool Team
Ai多智能体团队协作完成任务
发布帖子
寻求帮助或分享知识
发布插件
分享您的插件
 Cool v8
 Cool v8Cool-UniX
Cool-Admin-Node
Cool-Admin-Java
Cool-Admin-Vue
Cool Uni
Cool Flow Ai
Cool Team
发布帖子
发布插件

豆包实时语音识别
这是一个语音识别插件,基于字节跳动火山引擎的语音识别服务,支持一次性识别和流式识别两种模式。
本插件提供了两种语音识别方式:
调用插件的时候需要用到标识,标识是唯一的,不能重复,建议使用英文。对应插件 plugin.json 中的 key 字段
{
  "appid": "your_app_id",
  "token": "your_token"
}
下面是插件提供的一些方法:
一次性识别,适用于短音频文件
/**
 * 一次性识别
 * @param audioUrl 音频文件URL
 * @param audioOptions 音频参数配置(可选)
 */
async once(
  audioUrl: string,
  audioOptions?: {
    format?: "raw" | "wav" | "mp3" | "ogg";  // 音频格式
    codec?: "raw" | "opus";                   // 编码格式
    rate?: number;                            // 采样率
    bits?: number;                            // 位深
    channel?: number;                         // 声道数
  }
)
流式识别,支持实时音频输入并获取识别结果
/**
 * 流式识别
 * @param options 音频参数配置
 * @param callbacks 回调函数
 */
async stream(
  options: {
    format?: "pcm" | "wav" | "ogg";          // 音频格式
    rate?: number;                            // 采样率
    bits?: number;                            // 位深
    channel?: number;                         // 声道数
    codec?: "raw" | "opus";                   // 编码格式
  },
  callbacks: {
    onError?: (error: any) => void;          // 错误回调
    onFinal?: (text: string) => void;        // 最终识别结果回调
    onInterim?: (text: string) => void;      // 中间识别结果回调
  }
)
@Inject()
pluginService: PluginService;
// 获取插件实例
const instance = await this.pluginService.getInstance('asr');
// 一次性识别
const text = await instance.once(
  'https://example.com/audio.mp3',
  { 
    format: 'mp3'
  }
);
console.log('识别结果:', text);
// 流式识别
const client = await instance.stream(
  {
    format: 'wav',
    rate: 16000,
    bits: 16,
    channel: 1
  },
  {
    onInterim: (text) => {
      console.log('中间识别结果:', text);
    },
    onFinal: (text) => {
      console.log('最终识别结果:', text);
    },
    onError: (error) => {
      console.error('识别错误:', error);
    }
  }
);
// 读取音频文件
const fs = require('fs');
const audioFile = fs.readFileSync('audio.wav');
// 每次发送64KB数据
const chunkSize = 64 * 1024;
// 分片发送音频
for (let offset = 0; offset < audioFile.length; offset += chunkSize) {
  const chunk = audioFile.slice(offset, offset + chunkSize);
  await client.send(chunk);
}
// 结束识别
client.done();