純js實現web端錄音功能,功能並非特別多,逐步增長中,詳細地址:github。前端
getUserMedia在非localhost和127的狀況下,須要開啓https,因爲騰訊雲的沒備案,demo就不放了,能夠自行獲取代碼並啓動測試。git
實現原理的話,主要是如下三點,github
直接引入dist下的recorder.js便可web
let recorder = new Recorder();
安裝:chrome
npm i js-audio-recorder
調用:npm
import Recorder from 'js-audio-recorder'; let recorder = new Recorder();
// 開始錄音 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);
sampleBits,採樣位數,默認是16
sampleRate,採樣頻率,瀏覽器默認的,個人chrome是48000
numChannels,聲道數,默認是1瀏覽器
new Recorder時支持傳入參數,函數
{ sampleBits: 16, // 採樣位數,範圍8或16 sampleRate: 16000, // 採樣率,範圍1102五、16000、22050、24000、44100、48000 numChannels: 1, // 聲道,範圍1或2 }
主要是如下幾個方面:學習
https://caniuse.com/#search=w...測試
https://caniuse.com/#search=g...
https://caniuse.com/#search=t...
歡迎訪問和查看:recorder。
基於阿里雲實現簡單的語音識別功能
web Audio學習與音頻播放
web Audio實現pcm音頻數據收集
js實現pcm數據編碼
js轉化pcm到wav格式與播放