perf: Optimization of recording function on mobile devices (#2719)

This commit is contained in:
shaohuzhang1 2025-03-28 13:52:54 +08:00 committed by GitHub
parent 89be3e317d
commit bdaeb1bec4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -142,7 +142,7 @@
<div class="operate flex align-center"> <div class="operate flex align-center">
<template v-if="props.applicationDetails.stt_model_enable"> <template v-if="props.applicationDetails.stt_model_enable">
<span v-if="mode === 'mobile'"> <span v-if="mode === 'mobile'">
<el-button text @click="isMicrophone = !isMicrophone"> <el-button text @click="switchMicrophone(!isMicrophone)">
<!-- 键盘 --> <!-- 键盘 -->
<AppIcon v-if="isMicrophone" iconName="app-keyboard"></AppIcon> <AppIcon v-if="isMicrophone" iconName="app-keyboard"></AppIcon>
<el-icon v-else> <el-icon v-else>
@ -444,15 +444,19 @@ const isDisabledChat = computed(
) )
// //
const isMicrophone = ref(false) const isMicrophone = ref(false)
watch(isMicrophone, (value: boolean) => { const switchMicrophone = (status: boolean) => {
if (value) { if (status) {
// //
recorderManage.open() recorderManage.open(() => {
isMicrophone.value = true
})
} else { } else {
// //
recorderManage.close() recorderManage.close()
isMicrophone.value = false
} }
}) }
const TouchEnd = (bool: Boolean) => { const TouchEnd = (bool: Boolean) => {
if (bool) { if (bool) {
stopRecording() stopRecording()
@ -471,7 +475,7 @@ class RecorderManage {
constructor(uploadRecording: (blob: Blob, duration: number) => void) { constructor(uploadRecording: (blob: Blob, duration: number) => void) {
this.uploadRecording = uploadRecording this.uploadRecording = uploadRecording
} }
open() { open(callback?: () => void) {
const recorder = new Recorder({ const recorder = new Recorder({
type: 'mp3', type: 'mp3',
bitRate: 128, bitRate: 128,
@ -480,6 +484,9 @@ class RecorderManage {
if (!this.recorder) { if (!this.recorder) {
recorder.open(() => { recorder.open(() => {
this.recorder = recorder this.recorder = recorder
if (callback) {
callback()
}
}, this.errorCallBack) }, this.errorCallBack)
} }
} }
@ -556,7 +563,7 @@ const uploadRecording = async (audioBlob: Blob) => {
try { try {
// //
if (!props.applicationDetails.stt_autosend) { if (!props.applicationDetails.stt_autosend) {
isMicrophone.value = false switchMicrophone(false)
} }
recorderStatus.value = 'TRANSCRIBING' recorderStatus.value = 'TRANSCRIBING'
const formData = new FormData() const formData = new FormData()
@ -572,7 +579,7 @@ const uploadRecording = async (audioBlob: Blob) => {
autoSendMessage() autoSendMessage()
}) })
} else { } else {
isMicrophone.value = false switchMicrophone(false)
} }
}) })
.catch((error) => { .catch((error) => {