1、引入插件
npm install recorderx -S
2、import 进页面
import Recorder from 'recorderx';
const rc=0
;
3、开始录音
let that = this;
this.$nextTick(function () {
that.rc = new Recorder(true);
that.rc.start();
//可以用下面的代码来边录音边听
// const audio = new Audio()
// audio.autoplay = true
// this.rc.start().then(stream => {
// audio.srcObject = stream
// })
// .catch(error => alert(error));
})
4、其他
//暂停录音
this.rc.pause()
//销毁录音
this.rc.close()
//获取pcm录音
this.rc.getRecord()
//获取wav录音
this.rc.getRecordWav();//(这是返回wav转成blob的url)
//如果要获取blob对象(二进制)
要先在上面引入encodeWAV()
import {encodeWAV} from 'recorderx';
然后就可以写:
var pcm = this.rc.getRecord();
const blob = encodeWAV(pcm,16,44100)