2fps / recorder

html5 js 浏览器 web端录音

Home Page:https://recorder.zhuyuntao.cn/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

如何实现监听录音阈值,大于多少之后开始录音,几秒之后没声音自动停止录音

Mirroring-19 opened this issue · comments

目前是新建两个recorder实例,并使用onprogress方法进行监听recorder1的vol参数,大于某个值后recorder2开始录音,小于这个值三秒之后recorder2录音停止。但是这么做有个问题,使用onporegress监听会出现recorder2的第一个字录不清楚的问题,有大佬帮忙看看如何解决吗
`

		startRecord() {
			let flag = false
			let time = 9999
			recorder.start().then(() => {
			    // 开始录音
			}, (error) => {
			    // 出错了
			    console.log(`${error.name} : ${error.message}`);
			});
			recorder.onprogress = function(params) {
				this.time = parseInt(params.duration)
				if(params.vol >= 30){
					recorder2.start().then(() => {
					    // 开始录音
						console.log('开始录音')
					}, (error) => {
					    // 出错了
					    console.log(error);
					});	
					time = params.duration					
					flag = true
				}
				if(params.vol <= 30 && params.duration-time>=3 && flag == true){
					console.log('录音结束')
					recorder2.stop()
					flag = false
					console.log(recorder2)
					// recorder2.downloadWAV('recordTest')
					recorder2.play()
				}
			}
		},

`