openai-whisper-asr-webservice接入dify

openai-whisper-asr-webservice提供的asr的api其实并不兼容openai的api,所以在dify中是不能直接添加到语音转文字的模型中,对比了下两个api的传参情况,其实只要改动一处,就能支持:

openai兼容的asr调用中formdata中音频文件是file=XXX这样的,而openai-whisper-asr-webservice提供的asr的api中formdata中音频文件是audio_file=XXX这样的。感觉使用openresty的lua简单处理一下改formdata中的信息转发到后端就可以搞定,折腾了半天没有进展 😦 只好先用nodejs做个express服务来转发下,效果是ok的。

javascript 复制代码
const express = require("express");
const app = express();
const multer = require("multer");
const uploader = multer({ storage: multer.memoryStorage() });
const FormData = require('form-data');
const fetch = require('node-fetch');
const asrurl="http://127.0.0.1:9000/asr?output=json"

app.post("/v1/audio/transcriptions", uploader.single("file"), (req, res)=> {
	let newForm = new FormData();
	newForm.append('audio_file', req.file.buffer,{ filename: req.file.originalname, contentType: req.file.mimetype });
	fetch(asrurl, { method: 'POST', body: newForm, headers: newForm.getHeaders() }).then(resp=>resp.json()).then(response=> res.json({"text":response.text}) ).catch(error=>{ res.status(500).send(error.message); });
});


var server=app.listen(9100,()=>{ console.log("openai whisper 进程启动 "); });

这样可以在dify中添加openai兼容模型,选择speech2text模型,模型名称随便填,API endpoint URL

http://ip:9100/v1

又更新了下代码:采用内存存储上传文件,减少写入磁盘文件和读取磁盘文件环节

相关推荐
见过夏天20 小时前
Node.js 常用命令全攻略
node.js
前端双越老师1 天前
我从 0 开发的 AI Agent 智语项目发布了
前端·node.js·agent
doiito1 天前
【Agent Harness】Gliding Horse 的 L2 作战地图:让多 Agent 协作从“摸黑”变成“透明”
ai·rust·架构设计·系统设计·ai agent
xiezhr1 天前
逛GitHub发现一款免费带有AI功能的数据库管理工具DBX
ai·开源软件·自然语言·数据库管理工具
kyriewen2 天前
2026 年了,还在用 Node.js?Bun 迁移实战:20 分钟搞定,附踩坑记录
前端·javascript·node.js
donecoding2 天前
3 条命令搞定闭环 Monorepo:Lerna 版本管理 + 拓扑构建 + 自定义分发
前端·前端框架·node.js
垚森3 天前
我用 GLM-5.2 造了个炸裂主题后台:16 套主题随心切,可在线体验
ai·react
Flynt3 天前
npm v12 来了:allowScripts 默认关闭,我的项目差点跑不起来
安全·npm·node.js
doiito3 天前
【Agent Harness】Gliding Horse 工具结果压缩体系:如何用“指针”驯服上下文膨胀
ai·rust·架构设计·系统设计·ai agent
叫我Paul就好4 天前
尝试 Node 搭建后端-开发框架
node.js