录音
This commit is contained in:
@@ -84,7 +84,9 @@
|
||||
<script>
|
||||
|
||||
import {mapActions, mapState} from "vuex";
|
||||
const recorderManager = uni.getRecorderManager();
|
||||
import Recorder from 'recorder-core'
|
||||
import 'recorder-core/src/engine/mp3'
|
||||
import 'recorder-core/src/engine/mp3-engine'
|
||||
const innerAudioContext = uni.createInnerAudioContext();
|
||||
innerAudioContext.autoplay = true;
|
||||
export default {
|
||||
@@ -98,6 +100,7 @@ export default {
|
||||
backgroundSize: 'cover',
|
||||
},
|
||||
recorderManager: null,
|
||||
recorder: null,
|
||||
type: 'text',
|
||||
isStart: false,
|
||||
content: '',
|
||||
@@ -126,9 +129,6 @@ export default {
|
||||
...mapState(['user', 'token']),
|
||||
},
|
||||
onLoad() {
|
||||
recorderManager.onStop((res)=> {
|
||||
this.upLoad(res.tempFilePath)
|
||||
});
|
||||
},
|
||||
mounted() {
|
||||
this.getAiTypeList()
|
||||
@@ -144,42 +144,72 @@ export default {
|
||||
methods: {
|
||||
...mapActions(['autoLogin', 'getUserInfo']),
|
||||
startRecord() {
|
||||
if(this.isFlag) return
|
||||
this.isStart = true
|
||||
uni.authorize({
|
||||
scope: 'scope.record',
|
||||
success() {
|
||||
// if(this.isFlag) return
|
||||
// this.isStart = true
|
||||
// uni.authorize({
|
||||
// scope: 'scope.record',
|
||||
// success() {
|
||||
// // const options = {
|
||||
// // duration: 10000,
|
||||
// // sampleRate: 44100,
|
||||
// // numberOfChannels: 1,
|
||||
// // encodeBitRate: 192000,
|
||||
// // format: 'aac',
|
||||
// // frameSize: 50
|
||||
// // }
|
||||
// const options = {
|
||||
// duration: 10000,
|
||||
// sampleRate: 44100,
|
||||
// numberOfChannels: 1,
|
||||
// encodeBitRate: 192000,
|
||||
// format: 'aac',
|
||||
// frameSize: 50
|
||||
// duration: 60000,
|
||||
// sampleRate: 16000,
|
||||
// format: 'mp3'
|
||||
// }
|
||||
const options = {
|
||||
duration: 60000,
|
||||
sampleRate: 16000,
|
||||
format: 'mp3'
|
||||
}
|
||||
recorderManager.start(options);
|
||||
// recorderManager.start(options);
|
||||
|
||||
},
|
||||
fail(err) {
|
||||
this.isStart = false
|
||||
uni.showModal({
|
||||
title: "提示",
|
||||
content: "您的录音权限未开启",
|
||||
// },
|
||||
// fail(err) {
|
||||
// this.isStart = false
|
||||
// uni.showModal({
|
||||
// title: "提示",
|
||||
// content: "您的录音权限未开启",
|
||||
// })
|
||||
// }
|
||||
// })
|
||||
this.isStart = true
|
||||
this.recorder = Recorder({
|
||||
type: 'mp3',
|
||||
sampleRate: 16000,
|
||||
bitRate: 16
|
||||
})
|
||||
}
|
||||
|
||||
this.recorder.open(() => {
|
||||
this.recorder.start()
|
||||
})
|
||||
},
|
||||
endRecord() {
|
||||
this.recorder.stop((blob) => {
|
||||
var formData = new FormData();
|
||||
formData.append('file', blob, 'filename.mp3');
|
||||
this.$http.post('/admin/file/add', formData, {
|
||||
withoutToken: true,
|
||||
}).then((res) => {
|
||||
uni.hideLoading()
|
||||
if (res?.data) {
|
||||
this.voiceUrl = res.data[0].split(';')[0]
|
||||
this.voiceId = res.data[0].split(';')[1]
|
||||
this.isStart = false
|
||||
setTimeout(() => {
|
||||
this.isFlag = false
|
||||
}, 6000)
|
||||
recorderManager.stop();
|
||||
this.sendVoice()
|
||||
}
|
||||
}).catch(res => {
|
||||
this.$u.toast(res)
|
||||
uni.hideLoading()
|
||||
})
|
||||
|
||||
this.recorder.close()
|
||||
this.recorder = null
|
||||
}, msg => {
|
||||
console.log('录音失败:' + msg)
|
||||
this.recorder.close()
|
||||
this.recorder = null
|
||||
})
|
||||
},
|
||||
microPhone() {
|
||||
this.type = 'voice'
|
||||
|
||||
Reference in New Issue
Block a user