Use
script way
It can be introduced directly into the recorder.js under dist
let recorder = new Recorder();
npm way
installation:npm i js-audio-recorder
Call: introducing where needed recording
import Recorder from 'js-audio-recorder'
let recorder = new Recorder()
API
// 开始录音
recorder.start();
// 暂停录音
recorder.pause();
// 继续录音
recorder.resume()
// 结束录音
recorder.stop();
// 录音播放
recorder.play();
// 销毁录音实例,释放资源,fn为回调函数,
recorder.destroy(fn);
recorder =
null
;
下载功能
// 下载pcm文件
recorder.downloadPCM();
// 下载wav文件
recorder.downloadWAV();
// 重命名pcm文件,wav也支持
recorder.downloadPCM(
'重命名'
);
获取录音时长
// 回调持续输出时长
recorder.onprocess =
function
(duration) {
console.log(duration);
}
// 手动获取录音时长
console.log(recorder.duration);
Example of use:
<template>
<div class="home">
<H1 @ click = "handleclick ()"> Start Recording </ h1>
<H1 @ click = "handleclickl ()"> continue recording </ h1>
<H1 @ click = "handleclicks ()"> End Record </ h1>
<H1 @ click = "handleclickp ()"> Play Recording </ h1>
</div>
</template>
<script>
import Recorder from 'js-audio-recorder'
let recorder = new Recorder()
export default {
name: 'home',
methods: {
handleclick () {
console.log(1)
recorder.start () // start recording
},
handleclickl () {
console.log(2)
recorder.resume () // continue recording
},
handleclickt () {
console.log(3)
recorder.stop () // end the recording
},
handleclickb () {
console.log(4)
recorder.play () // Recording Playback
}
}
}
</script>