音频 修改采样率sampleRate
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"