1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| initRecorder() { let that = this if (typeof (navigator.mediaDevices.getUserMedia) == "undefined") { this.$message.error('当前没有语音权限!') return } if (navigator.mediaDevices.getUserMedia) { const constraints = { audio: true }; navigator.mediaDevices.getUserMedia(constraints).then(() => { console.log("授权成功!"); }, () => { console.error("授权失败!"); }); } else { console.error("浏览器不支持 getUserMedia"); } this.recorder = new Recorder({ sampleBits: 16, sampleRate: 16000, numChannels: 1, }); this.recorder.start().then(function () { console.log("开始录音...") }); },
|