音频 修改采样率sampleRate

本文介绍如何在JavaScript中利用RecorderJS库修改音频的采样率。通过开始录音、结束录音并转换采样率,结合exportWAV、downsampleBuffer和encodeWAV等函数实现。同时,提到了在本地运行接口时解决跨域问题的方法,并提供了项目源代码链接。
摘要由CSDN通过智能技术生成

js 音频修改采样率sampleRate

github上链接为: https://github.com/httggdt/RecorderToText

本地运行接口跨域,请在命令行输入:
open -n /Applications/Google\ Chrome.app/ --args --disable-web-security --user-data-dir=/Users/UserName/MyChromeDevUserData/

(UserName为电脑用户名),可调用起可跨域谷歌浏览器

调用,开始录音

navigator.mediaDevices.getUserMedia(constraints).then(function(stream) {
   
	console.log("getUserMedia() success, stream created, initializing Recorder.js ...");
    $("#recordButton").removeClass("stop");
    $("#stopButton").addClass("recoding");
    $(".errorTips").removeClass("errorShow");
    $(".refresh").removeClass("refreshShow");

    audioContext = new AudioContext();
    
		/*  assign to gumStream for later use  */
		gumStream = stream;
		
		/* use the stream */
    input = audioContext.createMediaStreamSource(stream);

		/* 
			Create the Recorder object and configure to record mono sound (1 channel)
			Recording 2 channels  will double the file size
		*/
		rec = new Recorder(input,{
   numChannels:1})

		//start the recording process
    rec.record()

		console.log("Recording started", rec);

}).catch(function(err) {
   
  	//enable the record button if getUserMedia() fails
     $("#recordButton").addClass("stop");
     $("#stopButton").removeClass("recoding");
});

结束录音–将获取的音频转换采样率

function stopRecording() {
   
	console.log("stopButton clicked"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值