DeepSeek前端调研-第二篇

背景

在开发过程中,AI团队他们需要语音格式为opus,但是h5录音的格式为webm,这就需要ffmpeg来进行格式转换,为了验证这一技术可行性,就写了个demo验证下。

安装ffmpeg

以windows举例,在官网下载安装包:www.gyan.dev/ffmpeg/buil... 点击Windows builds from gyan.dev,进入下图,点击ffmpeg-git-full.7z,就会下载安装包,解压即可使用。 配置PATH环境变量

验证是否安装成功,在cmd里输入ffmpeg -version,下图即为安装成功

实现过程

npm安装核心依赖,fluent-ffmpeg是简化库,@ffmpeg-installer/ffmpeg用于获取安装路径。

bash 复制代码
npm install fluent-ffmpeg @ffmpeg-installer/ffmpeg

下面是nodejs代码

js 复制代码
const http = require('http');
const path = require('path');
const ffmpeg = require('fluent-ffmpeg');
// 设置ffmpeg安装包路径
const ffmpegPath = require('@ffmpeg-installer/ffmpeg').path;
ffmpeg.setFfmpegPath(ffmpegPath);
 
// 创建HTTP服务器并监听3000端口
const server = http.createServer(async (req, res) => {
    // 假设你已经有一个 WebM 格式的 Blob 文件
    const inputBlobPath = path.join(__dirname, 'recording.webm'); // 输入文件路径
    const outputOpusPath = path.join(__dirname, 'output.opus'); // 输出文件路径
    // 转换为 Opus
    const opusFilePath = await convertWebMToOpus(inputBlobPath, outputOpusPath);
    console.log('Opus 文件已生成:', opusFilePath);
});
 
server.listen(3000, () => {
    console.log('Proxy server is listening on port 3000');
});

// webm转opus
function convertWebMToOpus(inputPath, outputPath) {
  return new Promise((resolve, reject) => {
    ffmpeg(inputPath)
      .output(outputPath)
      .audioCodec('libopus') // 指定音频编码器为 libopus
      .on('end', () => {
        console.log('转换完成:', outputPath);
        resolve(outputPath);
      })
      .on('error', (err) => {
        console.error('转换失败:', err.message);
        reject(err);
      })
      .run();
  });
}
相关推荐
ayqy贾杰2 小时前
Agent First Engineering
前端·vue.js·面试
IT_陈寒2 小时前
SpringBoot实战:5个让你的API性能翻倍的隐藏技巧
前端·人工智能·后端
iceiceiceice2 小时前
iOS PDF阅读器段评实现:如何从 PDFSelection 精准还原一个自然段
前端·人工智能·ios
大金乄3 小时前
封装一个vue2的elementUI 表格组件(包含表格编辑以及多级表头)
前端·javascript
葡萄城技术团队3 小时前
【性能优化篇】面对万行数据也不卡顿?揭秘协同服务器的“片段机制 (Fragments)”
前端
程序员阿峰4 小时前
2026前端必备:TensorFlow.js,浏览器里的AI引擎,不写Python也能玩转智能
前端
Jans4 小时前
Shipfe — Rust 写的前端静态部署工具:一条命令上线 + 零停机 + 可回滚 + 自动清理
前端
徐小夕4 小时前
JitWord 2.3: 墨定,行远
前端·vue.js·github
南果梨4 小时前
OpenClaw 完整教程!从安装到使用(官方脚本版)
前端·git·开源
大雨还洅下4 小时前
前端手写: new操作符
前端