|
@@ -28,25 +28,37 @@ export default {
|
|
|
methods: {
|
|
|
// 开始录音
|
|
|
microphone() {
|
|
|
- if (this.microphoneStatus) {
|
|
|
- this.recorder.stop();
|
|
|
- // 录音结束,获取取录音数据
|
|
|
- let wav = this.recorder.getWAVBlob(); // 获取 WAV 数据
|
|
|
- this.microphoneStatus = false;
|
|
|
- let reader = new window.FileReader();
|
|
|
- reader.readAsDataURL(wav);
|
|
|
- reader.onloadend = () => {
|
|
|
- SaveFileByteBase64Text({
|
|
|
- base64_text: reader.result.replace('data:audio/wav;base64,', ''),
|
|
|
- file_suffix_name: 'mp3',
|
|
|
- }).then(({ file_id }) => {
|
|
|
- this.$emit('saveWav', file_id);
|
|
|
+ if (navigator && navigator.mediaDevices) {
|
|
|
+ const constraints = { audio: true }; // 设置只获取音频流
|
|
|
+ navigator.mediaDevices
|
|
|
+ .getUserMedia(constraints)
|
|
|
+ .then(() => {
|
|
|
+ if (this.microphoneStatus) {
|
|
|
+ this.recorder.stop();
|
|
|
+ // 录音结束,获取取录音数据
|
|
|
+ let wav = this.recorder.getWAVBlob(); // 获取 WAV 数据
|
|
|
+ this.microphoneStatus = false;
|
|
|
+ let reader = new window.FileReader();
|
|
|
+ reader.readAsDataURL(wav);
|
|
|
+ reader.onloadend = () => {
|
|
|
+ SaveFileByteBase64Text({
|
|
|
+ base64_text: reader.result.replace('data:audio/wav;base64,', ''),
|
|
|
+ file_suffix_name: 'mp3',
|
|
|
+ }).then(({ file_id }) => {
|
|
|
+ this.$emit('saveWav', file_id);
|
|
|
+ });
|
|
|
+ };
|
|
|
+ } else {
|
|
|
+ // 开始录音
|
|
|
+ this.recorder.start();
|
|
|
+ this.microphoneStatus = true;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(() => {
|
|
|
+ this.$message.warning('请打开浏览器录音权限');
|
|
|
});
|
|
|
- };
|
|
|
} else {
|
|
|
- // 开始录音
|
|
|
- this.recorder.start();
|
|
|
- this.microphoneStatus = true;
|
|
|
+ this.$message.warning('该浏览器不支持录音');
|
|
|
}
|
|
|
},
|
|
|
},
|