Vue 使用 js-audio-recorder 实现录制、播放、下载音频

使用js-audio-recorder插件实现前端的录音功能 使用js-audio-recorder插件实现网页上的录音功能 阅读详情
AI摘要

本文介绍了如何在Vue项目中使用js-audio-recorder库实现音频录制、暂停、恢复、播放、下载以及上传功能,包括组件设计、路由配置和依赖管理。

Vue 使用 js-audio-recorder 实现录制、播放、下载 PCM 数据

js-audio-recorder 简介

纯 js 实现浏览器端录音。

支持功能:

  • 支持录音,暂停,恢复,和录音播放。
  • 支持音频数据的压缩,支持单双通道录音。
  • 支持录音时长、录音大小的显示。
  • 支持边录边转(播放) 后续支持。
  • 支持导出录音文件,格式为 pcm 或 wav。
  • 支持录音波形显示,可自己定制。

项目地址:https://github.com/2fps/recorder

演示地址:https://recorder.zhuyuntao.cn/

Vue 项目创建

按下面的步骤创建 Vue 项目:

在这里插入图片描述

然后 cd 到 vue_recorder 下,终端输入 npm run serve,出现下面输出说明成功了:

在这里插入图片描述

浏览器打开 http://localhost:8080/:

在这里插入图片描述

下载相关依赖

在项目中我们会用到 js-audio-plugin 以及 Element ,所以需要下载相关依赖并在 main.js 中引入。

安装 js-audio-plugin 指令:npm i js-audio-recorder。

安装 Element 指令:npm install element-ui。

安装好以后,在 main.js 添加:

// 引入 element-ui
import ElementUI from 'element-ui';
// element-ui 的 css 样式要单独引入
import 'element-ui/lib/theme-chalk/index.css';

Vue.use(ElementUI);

主界面设计

主页面的设计在根组件 App.vue 中进行,主要负责一些全局内容的显示。

<template>
  <div id="app">
    <!-- <nav>
      <router-link to="/">Recorder</router-link> |
    </nav> -->
    <router-view />
  </div>
</template>

<style lang="scss">
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

nav {
  padding: 30px;

  a {
    font-weight: bold;
    color: #2c3e50;

    &.router-link-exact-active {
      color: #42b983;
    }
  }
}
</style>

设置路由

在 router 目录下的 index.js 中设置路由:

import Vue from 'vue'
import VueRouter from 'vue-router'
import RecorderView from '../views/RecorderView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'recorder',
    component: RecorderView
  },
]

const router = new VueRouter({
  routes
})

export default router

组件及页面设计

在 compoments 文件夹下新建 MyRecorder.vue:

@ -0,0 +1,179 @@
<template>
  <div style="padding: 20px;">
    <h1>{{ msg }}</h1>
    <div style="font-size:14px">
      <h3>录音时长:{{ recorder && recorder.duration.toFixed(4) }}</h3>
      <br />
      <el-button type="primary" @click="handleStart">开始录音</el-button>
      <el-button type="info" @click="handlePause">暂停录音</el-button>
      <el-button type="success" @click="handleResume">继续录音</el-button>
      <el-button type="warning" @click="handleStop">停止录音</el-button>
      <br />
      <br />
      <h3>
        播放时长:{{ recorder && (playTime > recorder.duration ? recorder.duration.toFixed(4) : playTime.toFixed(4)) }}
      </h3>
      <br />
      <br />
      <el-button type="primary" @click="handlePlay">播放录音</el-button>
      <el-button type="info" @click="handlePausePlay">暂停播放</el-button>
      <el-button type="success" @click="handleResumePlay">继续播放</el-button>
      <el-button type="warning" @click="handleStopPlay">停止播放</el-button>
      <el-button type="error" @click="handleDestroy">销毁录音</el-button>
      <br />
      <br />
      <el-button type="primary" @click="downloadPCM">下载PCM数据</el-button>
      <el-button type="primary" @click="downloadWAV">下载WAV数据</el-button>
      <el-button type="primary" @click="uploadRecord">上传</el-button>
    </div>
  </div>
</template>

<script>
import Recorder from 'js-audio-recorder'
import axios from 'axios'

export default {
  name: 'MyRecorder',
  props: {
    msg: String
  },
  data() {
    return {
      recorder: null,
      playTime: 0,
      timer: null,
      src: null
    }
  },
  created() {
    this.recorder = new Recorder({
      sampleBits: 16, // 采样位数,支持 8 或 16,默认是 16
      sampleRate: 16000, // 采样率,支持 11025、16000、22050、24000、44100、48000,根据浏览器默认值,Chrome 是 48000
      numChannels: 1, // 声道数,支持 1 或 2, 默认是 1
    })
  },
  methods: {
    // 开始录音
    handleStart() {
      this.recorder = new Recorder({
        sampleBits: 16, // 采样位数,支持 8 或 16,默认是 16
        sampleRate: 16000, // 采样率,支持 11025、16000、22050、24000、44100、48000,根据浏览器默认值,Chrome 是 48000
        numChannels: 1, // 声道数,支持 1 或 2, 默认是 1
      }),
        Recorder.getPermission().then(() => {
          console.log('开始录音')
          this.recorder.start() // 开始录音
        }, (error) => {
          this.$message({
            message: '请先允许该网页使用麦克风',
            type: 'info'
          })
          console.log(`${error.name} : ${error.message}`)
        })
    },
    handlePause() {
      console.log('暂停录音')
      this.recorder.pause() // 暂停录音
    },
    handleResume() {
      console.log('恢复录音')
      this.recorder.resume() // 恢复录音
    },
    handleStop() {
      console.log('停止录音')
      this.recorder.stop() // 停止录音
    },
    handlePlay() {
      console.log('播放录音')
      console.log(this.recorder)
      this.recorder.play() // 播放录音

      // 播放时长
      this.timer = setInterval(() => {
        try {
          this.playTime = this.recorder.getPlayTime()
        } catch (error) {
          this.timer = null
        }
      }, 100)
    },
    handlePausePlay() {
      console.log('暂停播放')
      this.recorder.pausePlay() // 暂停播放

      // 播放时长
      this.playTime = this.recorder.getPlayTime()
      this.time = null
    },
    handleResumePlay() {
      console.log('恢复播放')
      this.recorder.resumePlay() // 恢复播放

      // 播放时长
      this.timer = setInterval(() => {
        try {
          this.playTime = this.recorder.getPlayTime()
        } catch (error) {
          this.timer = null
        }
      }, 100)
    },
    handleStopPlay() {
      console.log('停止播放')
      this.recorder.stopPlay() // 停止播放

      // 播放时长
      this.playTime = this.recorder.getPlayTime()
      this.timer = null
    },
    handleDestroy() {
      console.log('销毁实例')
      this.recorder.destroy() // 销毁实例
      this.timer = null
    },
    downloadPCM() {
      console.log('下载PCM格式数据')
      // 注:使用该方法会默认调用 stop() 方法
      this.recorder.downloadPCM("record" + new Date().getTime())
    },
    downloadWAV() {
      console.log('下载WAV格式数据')
      // 注:使用该方法会默认调用 stop() 方法
      this.recorder.downloadWAV("record" + new Date().getTime())
    },
    uploadRecord() {
      if (this.recorder == null || this.recorder.duration === 0) {
        this.$message({
          message: '请先录音',
          type: 'error'
        })
        return false
      }
      this.recorder.pause() // 暂停录音
      this.timer = null
      console.log('上传录音') // 上传录音

      const blob = this.recorder.getPCMBlob() // 获取 pcm 格式音频数据
      const newBlob = new Blob([blob])
      // 此处获取到 blob 对象后需要设置 fileName 满足项目上传需求,这里选择把 blob 包装成 file 塞入 formData
      const fileOfBlob = new File([newBlob], new Date().getTime() + '.pcm')

      const formData = new FormData()
      formData.append('file', fileOfBlob)
      const url = window.URL.createObjectURL(fileOfBlob)
      this.src = url
      axios.post('http://localhost:8087/upload', formData, {
        headers: {
          'Content-Type': 'multipart/form-data'
        }
      }).then(response => {
        console.log('上传成功', response.data);
      }).then(res => {
        console.log(res.data.data[0].url)
      })
        .catch(error => {
          console.error('上传失败', error);
        })
    },
  }
}
</script>

在 views 文件夹下新建 RecorderView.vue:

<template>
    <div class="home">
        <!-- <img
      alt="Vue logo"
      src="../assets/logo.png"
    > -->
        <MyRecorder msg="Welcome to Vue Recorder" />
    </div>
</template>
  
<script>
// @ is an alias to /src
import MyRecorder from '@/components/MyRecorder.vue'

export default {
    name: 'RecorderView',
    components: {
        MyRecorder
    }
}
</script>

项目启动

在终端中输入指令:npm run serve。

可以看到如下界面,说明项目成功运行:

在这里插入图片描述

根据提示访问本地地址 http://localhost:8080/。

在这里插入图片描述

经过测试,页面正常排布,所有功能都正常使用(除了上传功能)。

源码下载

GitHub:https://github.com/UestcXiye/Vue-Recorder

CSDN:vue-recorder.zip

Vue3 + js-audio-recorder 保姆级教程:从录音权限获取到PCM/WAV文件下载 本文详细介绍了如何在Vue3项目中使用js-audio-recorder库实现音频录制功能,包括录音权限获取、PCM/WAV文件下载等核心功能。通过Composition API封装可复用逻辑,结合Element Plus实现UI集成,并提供了音频可视化、性能优化等高级技巧,帮助开发者快速构建高可用的Web音频录制系统。 阅读详情

相关推荐

【Recorder】在 vue3 中使用 Recorder 实现录音并上传(mp3、wav)兼容 PC 和移动端

使用 Recorder插件可以在网页中进行录音。生成 blob 文件并可以自定义上传,同时,录音过程中会显示可视化波形,同时能够做到兼容PC端、Android、和iOS,十分好用!

日常问题bug解决、学习分享、个人杂谈等等随便写写哈哈哈 1万+

vue使用js-audio-recorder实现录音功能

vue使用js-audio-recorder实现录音功能前言1.安装2.引用3.页面4.方法5.播放总结 前言 最近项目中需要实现一个录音上传功能,用于考试、作业中,学生可以上传朗读课文的录音,安排。 效果图 1.安装 npm i js-audio-recorder 2.引用 import Recorder from 'js-audio-recorder' this.recorder = new Recorder() 3.页面 <!-- 录音上传 --> <Moda

qsya的博客 1万+

vue使用js-audio-recorder实现一句话识别功能

vue使用js-audio-recorder实现一句话识别功能:以vue前端框架+腾讯云语音识别为基础,实现客户端长按录音,获取语音转换编译出来的识别码,传给后端去腾讯云语音识别库去换取识别回来的文本尽心客户端的文本查询!实现一句话查询效果!以vue前端框架+腾讯云语音识别为基础,实现客户端长按录音,获取语音转换编译出来的识别码,传给后端去腾讯云语音识别库去换取识别回来的文本尽心客户端的文本查询!实现一句话查询效果!以vue前端框架+腾讯云语音识别为基础,实现客户端长按录音,获取语音转换编译出来的识别码,传给后端去腾讯云语音识别库去换取识别回来的文本尽心客户端的文本查询!实现一句话查询效果!以vue前端框架+腾讯云语音识别为基础,实现客户端长按录音,获取语音转换编译出来的识别码,传给后端去腾讯云语音识别库去换取识别回来的文本尽心客户端的文本查询!实现一句话查询效果!以vue前端框架+腾讯云语音识别为基础,实现客户端长按录音,获取语音转换编译出来的识别码,传给后端去腾讯云语音识别库去换取识别回来的文本尽心客户端的文本查询!实现一句话查询效果!以vue前端框架+腾讯云语音识别为基础,实现客

uniapp中使用网页录音并上传声音文件(发语音)——js-audio-recorder的使用【伸手党福利】

uniapp中上传音频只能在app或小程序当中实现,如何使用网页完成语音的录制和上传则成为了困扰前端童鞋的重点。本文着重解决:js-audio-recorder报 error:浏览器不支持getUserMedia!的问题。js-audio-recorder报 NotFoundError : Requested device not found 的问题js-audio-recorder的使用、demo以及文件上传的问题。......

wwppp987的博客 1万+

JS-Audio-Recorder

JS录音机 这是什么? 这是一个仅使用 HTML 和 Javascript 实现录音功能的演示程序。您可以使用录音、回放录音、保存语音等功能。 操作环境 它是比 Google Chrome 23 更新的版本,可在启用了网络音频输入的环境中使用。 要启用 Web 音频输入,您需要执行以下操作:首先,启动谷歌浏览器后,在地址栏中指定chrome://flags 。接下来,在 Web Audio Input 项中单击“启用”后,重新启动 Google Chrome。 如何使用 首先,当您打开页面时,会要求您授予访问麦克风的权限,因此请单击权限按钮。然后点击录制按钮开始录制。此时录音按钮变为停止按钮,点击该停止按钮停止录音。如果录音过程成功,按钮顶部显示的播放器可以播放录制的语音。您还可以通过单击下载按钮播放录制的语音。

PLC编程入门基础知识

PLC即为可编程逻辑控制器,实质是一种专用于工业控制的计算机,其硬件结构基本上与微型计算机相同。

SANRENYIXING的博客 2万+

Vue 使用 js-audio-recorder 实现录制、播放、下载音频,上传后台

转载。

weixin_40112036的博客 271

Rsoft仿真实战:长周期光纤光栅参数优化与模式耦合分析

本文详细介绍了使用Rsoft软件进行长周期光纤光栅(LPFG)参数优化与模式耦合分析的实战方法。通过Rsoft仿真,可以高效优化光栅周期、包层厚度等关键参数,深入分析纤芯模与包层模的耦合特性,为光纤通信和传感应用提供可靠的设计依据。

h0i1j2k3l的博客 1120

语音消息实现(聊天向)

语音消息实现记录下:SpringBoot+Vue3客服项目,网页录制发送语音消息 Vue中使用js-audio-recorder插件实现录音功能并实现上传Blob数据到SpringBoot后台接口2fps/recorder github地址Recorder的API语音测试地址

pscool的博客 1274

dxf-viewer 查看器

dxf-viewer SDK 的示例,它是一个基于 Three.js 和 Vue3 构建的基于 WebGL 的 BIM 模型查看器。它用于查看 DWG/DXF/PDF 文件。面积测量 - 角度测量 -标记。

qq_25547755的博客 881

定位精度再突破!Inner-MPDIoU让YOLOv11边界框回归更精准

Inner-MPDIoU 凭借辅助边框与最小点距离的双机制创新,彻底解决了传统 IoU 损失在边界框回归上的精度瓶颈。本教程从原理到代码实现,再到工业场景适配,完整呈现了其在 YOLOv11 中的集成路径。只需简单修改两处核心脚本,你的目标检测模型就能在边界框定位精度上实现跨越式提升——无论是学术研究中的指标突破,还是工业场景下的精细检测需求,Inner-MPDIoU 都能成为你攻克边界框回归难题的利器。现在就动手尝试,让你的检测模型在定位精度上再上一个台阶吧。

FJN110的博客 162

Vue 结合 js-audio-recorder 实现高保真音频录制与实时波形可视化

本文详细介绍了如何在Vue项目中集成js-audio-recorder实现高保真音频录制功能,包括环境搭建、基础录音控制、音频播放与下载,以及实时波形可视化等核心功能。通过实战代码演示,帮助开发者快速掌握音频处理技术,适用于语音笔记、在线教育等多种应用场景。

weixin_33691700的博客 217

C# Socket通信从入门到精通(14)——多个异步UDP客户端C#代码实现(史上最全)

本文详细介绍了Socket通信中多个异步Udp客户端功能的实现、介绍如何使用多个客户端与多个服务器进行数据的交互,包含连接服务器、断开服务器、发送数据、读取数据、C#代码实现,由高级工程师多年经验总结而成,绝对干货!

qq_34059233的博客 1988

vue录音使用

使用方式 script方式 直接引入dist下的recorder.js即可 let recorder = new Recorder(); npm方式 安装:npm i js-audio-recorder 调用:在需要录音的地方引入 importRecorderfrom'js-audio-recorder' letrecorder=newRecor...

684

n8n AI高效工作流自动化 部署使用教程

摘要: n8n是一款开源可视化工作流自动化工具,结合AI能力可高效解决重复性任务。文章详细介绍了从Docker部署到实战应用的完整流程:1)通过Docker Compose自托管n8n,确保数据可控;2)以AI客服日报机器人为例,演示如何串联工单系统、ChatGPT和邮件通知,实现定时自动化;3)进阶搭建交互式AI助手,利用ToolsAgent节点调用业务API;4)整合向量数据库构建RAG知识库问答。关键建议包括:拆分复杂工作流、严格管理凭据、区分开发与生产环境,并建议从高频刚性需求(如日报生成)切入,逐

专注AI大模型,软件混淆,授权 283

MuJoCo 入门教程(八)Model仓库

一个物理仿真器的好坏取决于它所仿真的模型,而在像 MuJoCo 这样功能强大、建模选项众多的仿真器中,很容易创建出行为与预期不符的 "坏 "模型。MuJoCo Menagerie 的目标是为社区提供一个设计精良、开箱即用的模型集。更多信息,请访问 Menagerie 资源库。

机器人控制与仿真应用 1943

【免费下载】 Vue-Audio-Recorder:前端录音神器,轻松集成音频录制功能

在Web开发中,用户体验是至关重要的,而实时交互功能如语音记录,为用户提供更直观便捷的沟通方式。Vue-Audio-Recorder就是这样一款专为Vue.js开发者打造的开源组件,它可以帮助你在项目中快速实现高质量的音频录制功能。 ## 项目简介 是一个轻量级且易于使用的Vue插件,它基于Web Audio API和MediaStream Recording API,让你能够在浏览器环境中...

gitblog_00080的博客 2883

10倍开发者的 Dify 魔法书:从零构建全栈 AI 应用

“不懂底层算法,也能开发爆款 AI 应用吗?” 答案是:绝对可以。 Dify 正在重新定义 AI 应用的开发范式——通过可视化的低代码平台,将原本需要数周的开发周期压缩到几小时。无论你是前端、后端、产品经理,还是渴望破局的独立开发者,这都是你不可错过的红利。 我们将手把手教你利用 Dify 快速接入百模大战,零代码搭建企业级知识库,并一键发布你的专属 AI 助手、智能客服和自动化工作流。 告别重复造轮子,掌握 Dify,一个人就是一支 AI 团队。现在上车,开启你的 10 倍速开发之旅!

davidwang456的专栏 742

前端使用js-audio-recorder组件实现录音、语音下载、播放等【含blob对象转换为file对象】

本文范例代码使用vue2.0开发 首先当然是在项目中安装包 npm install js-audio-recorder 然后在页面中引入 import Recorder from 'js-audio-recorder' 该插件可以控制录得的语音的质量,以下是插件内配置对象的定义**【这是插件里面的东西,我贴在这里给大家看一眼而已,不用抄】** interface recorderConfig { sampleBits?: number, // 采样位数 sampleRate

shay的博客 7935

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

【亲测免费】 开源项目推荐:Vue-audio-recorder,打造交互式音频录制体验

在这个数字化时代,语音交互已成为应用程序不可或缺的一部分。对于Vue.js开发者而言,`vue-audio-recorder`是一个令人兴奋的开源工具,它不仅简化了在Vue应用中集成音频录制功能的过程,还赋予了高度定制和用户友好的特性。通过这个插件,你可以轻松实现录音创建、播放、下载以及服务器存储等功能,极大地丰富你的应用交互体验。 ## 项目技术分析 `vue-audio-recorder`...

gitblog_00367的博客 1000

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

探索vue-audio-recorder:让Vue应用拥有专业录音能力的Web音频捕获解决方案

在当今Web应用交互体验日益丰富的背景下,前端音频录制功能正从边缘需求转变为核心交互模块。无论是在线教育的口语作业提交,还是企业客服系统的语音留言,高质量的音频捕获能力都成为提升用户体验的关键。vue-audio-recorder作为一款专为Vue.js生态设计的开源组件,通过封装Web Audio API与MediaStream Recording API的底层能力,为开发者提供了开箱即用的音频

gitblog_00735的博客 897

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

如何快速实现Vue音频录制功能:vue-audio-recorder完整指南

**vue-audio-recorder** 是一个专为VueJS应用开发的简单音频录制工具,让开发者能够轻松集成高质量的音频录制功能到Web项目中。本教程将详细介绍如何使用这个强大的组件,从项目结构解析到实际应用场景,帮助你快速掌握音频录制的核心技能。 ## ???? 项目核心文件与目录结构解析 vue-audio-recorder采用模块化设计,核心功能主要集中在`src`目录下,以下是关键文...

gitblog_00345的博客 492

vue使用实现录音功能js-audio-recorder

vue使用实现录音功能js-audio-recorder 最近项目中需要实现一个录音上传功能,用于语音评论可以上录音。 完整代码

boundle_ss的博客 1969

【亲测免费】 Vue-Audio-Recorder 安装和配置指南

### 项目基础介绍 Vue-Audio-Recorder 是一个基于 Vue.js 的简单音频录制组件。它允许用户在 Vue.js 应用程序中创建、播放、下载和存储音频记录。该项目提供了美观的用户界面,支持多种音频格式(如 MP3 和 WAV),并且具有时间限制和记录限制等功能。 ### 主要编程语言 该项目主要使用 JavaScript 和 Vue.js 框架进行开发。 ## 2. 项目使...

gitblog_07220的博客 1039

Vue中使用js-audio-recorder插件实现录音功能并实现上传Blob数据到SpringBoot后台接口

浏览器web端实现语音消息录制并在录制结束之后将其上传到后台接口。在上面的基础上,搭建前后端的架构。

BADAO_LIUMANG_QIZHI的博客 1万+

Vue音频组件实战指南:用vue-audio-recorder打造专业前端录音功能

你是否曾想过在网页上轻松实现录音功能?无论是语音笔记应用、在线客服系统还是语音识别功能,`vue-audio-recorder`这个轻量级组件都能帮你快速搞定。本教程将带你从基础认知到实战配置,一步步掌握这个强大工具的使用技巧。 ## 基础认知:vue-audio-recorder是什么? ### 组件能为我们解决什么问题? 想象一下,你正在开发一个在线语言学习平台,需要让用户录制自己的发音

gitblog_00866的博客 741
上一篇: 剑指 Offer(第2版)面试题 38:字符串的排列
下一篇: 剑指 Offer(第2版)面试题 41:数据流的中位数
UestcXiye
博客等级 码龄8年 9047粉丝 1306原创
评论 10
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

UestcXiye

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址