这是我引入的步骤,因为我第一次引入不会搞,浪费了很多时间,写个博客记录一下~通过询问写这个插件的大神才解决了我的问题~

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)

Logo

前往低代码交流专区

更多推荐