当前位置: 首页 > news >正文

LLM(3) : 浏览器录制16K的音频并上传到后端

可被阿里云[qwen-audio-asr]大模型识别 

 HTML

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><title>录音并上传</title></head><body><button id="recordButton">开始/停止录音</button><audio id="audioPlayback" controls style="display:none;"></audio><script>let mediaRecorder;let audioChunks = [];let recording = false;document.getElementById('recordButton').addEventListener('click', () => {if (recording) {// 停止录音stopRecording();} else {// 开始录音startRecording();}});async function startRecording() {try {const stream = await navigator.mediaDevices.getUserMedia({audio: true});// 创建 MediaRecorder 实例,但不连接到任何音频输出mediaRecorder = new MediaRecorder(stream, {mimeType: 'audio/webm; codecs=opus'});mediaRecorder.ondataavailable = event => {audioChunks.push(event.data);};mediaRecorder.onstop = async () => {const audioBlob = new Blob(audioChunks, {type: 'audio/webm; codecs=opus'});const audioUrl = URL.createObjectURL(audioBlob);const audio = document.getElementById('audioPlayback');audio.src = audioUrl;audio.style.display = 'block';// 自动上传录音文件到后端接口await uploadAudioFile(audioBlob);// 清空 audioChunks 以便下次录音audioChunks = [];};mediaRecorder.start();recording = true;document.getElementById('recordButton').textContent = '停止录音';} catch (err) {console.error('Error accessing media devices.', err);}}function stopRecording() {if (mediaRecorder && mediaRecorder.state !== 'inactive') {mediaRecorder.stop();mediaRecorder.stream.getTracks().forEach(track => track.stop()); // 停止媒体流轨道}recording = false;document.getElementById('recordButton').textContent = '开始录音';}async function uploadAudioFile(blob) {const formData = new FormData();formData.append('file', blob, 'recording.webm');try {const response = await fetch('http://127.0.0.1:30025/sound', {method: 'POST',body: formData,});if (!response.ok) {throw new Error(`HTTP error! status: ${response.status}`);}const result = await response.json();console.log('Server response:', result);} catch (error) {console.error('There was a problem with the fetch operation:', error);}}</script></body>
</html>

python接口

@app.route('/sound', methods=['POST'])
def sound():file = request.files['file']# ... 处理文件return "SUCCESS"

http://www.lryc.cn/news/523853.html

相关文章:

  • PyTorch使用教程(13)-一文搞定模型的可视化和训练过程监控
  • 服务器日志自动上传到阿里云OSS备份
  • 树莓派学习
  • NestJS中实现注入多个实现了同一个接口的Service
  • Qt按钮美化教程
  • 基于单片机的多功能蓝牙语音智能台灯(论文+源码)
  • 第15章:Python TDD应对货币类开发变化(二)
  • 算法随笔_13: 有效三角形的个数
  • WSL 2 自动更新 虚拟 IP 到 window hosts
  • 我在广州学Mysql 系列——触发器的使用
  • 【useCallback Hook】在多次渲染中缓存组件中的函数,避免重复创建函数
  • 2025/1/20 学习Vue的第三天
  • Kotlin Bytedeco OpenCV 图像图像49 仿射变换 图像裁剪
  • 金融项目实战 07|Python实现接口自动化——连接数据库和数据清洗、测试报告、持续集成
  • (快速入门)保姆级详细的 Midjourney 基础教程
  • leetcode——找到字符串中所有字母异位词(java)
  • 大文件上传服务-后端V1V2
  • Single-Model and Any-Modality for Video Object Tracking——2024——cvpr-阅读笔记
  • 阳振坤:AI 大模型的基础是数据,AI越发达,数据库价值越大
  • Linux磁盘空间不足,12个详细的排查方法
  • Spring Web MVC综合案例
  • 微软预测 AI 2025,AI Agents 重塑工作形式
  • lvgl性能调优
  • CSS实现实现票据效果 mask与切图方式
  • STL--list(双向链表)
  • ZooKeeper 中的 ZAB 一致性协议与 Zookeeper 设计目的、使用场景、相关概念(数据模型、myid、事务 ID、版本、监听器、ACL、角色)
  • “深入浅出”系列之C++:(11)推荐一些C++的开源项目
  • 《重生到现代之从零开始的C++生活》—— 类和对象2
  • “UniApp的音频播放——点击视频进入空白+解决视频播放器切换视频时一直加载的问题”——video.js、video-js.css
  • 【Pandas】pandas Series transform