Skip to content

Commit e910733

Browse files
committed
perf: Optimization of recording function on mobile devices
1 parent bd098e6 commit e910733

File tree

1 file changed

+15
-8
lines changed
  • ui/src/components/ai-chat/component/chat-input-operate

1 file changed

+15
-8
lines changed

ui/src/components/ai-chat/component/chat-input-operate/index.vue

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@
142142
<div class="operate flex align-center">
143143
<template v-if="props.applicationDetails.stt_model_enable">
144144
<span v-if="mode === 'mobile'">
145-
<el-button text @click="isMicrophone = !isMicrophone">
145+
<el-button text @click="switchMicrophone(!isMicrophone)">
146146
<!-- 键盘 -->
147147
<AppIcon v-if="isMicrophone" iconName="app-keyboard"></AppIcon>
148148
<el-icon v-else>
@@ -444,15 +444,19 @@ const isDisabledChat = computed(
444444
)
445445
// 是否显示移动端语音按钮
446446
const isMicrophone = ref(false)
447-
watch(isMicrophone, (value: boolean) => {
448-
if (value) {
447+
const switchMicrophone = (status: boolean) => {
448+
if (status) {
449449
// 如果显示就申请麦克风权限
450-
recorderManage.open()
450+
recorderManage.open(() => {
451+
isMicrophone.value = true
452+
})
451453
} else {
452454
// 关闭麦克风
453455
recorderManage.close()
456+
isMicrophone.value = false
454457
}
455-
})
458+
}
459+
456460
const TouchEnd = (bool: Boolean) => {
457461
if (bool) {
458462
stopRecording()
@@ -471,7 +475,7 @@ class RecorderManage {
471475
constructor(uploadRecording: (blob: Blob, duration: number) => void) {
472476
this.uploadRecording = uploadRecording
473477
}
474-
open() {
478+
open(callback?: () => void) {
475479
const recorder = new Recorder({
476480
type: 'mp3',
477481
bitRate: 128,
@@ -480,6 +484,9 @@ class RecorderManage {
480484
if (!this.recorder) {
481485
recorder.open(() => {
482486
this.recorder = recorder
487+
if (callback) {
488+
callback()
489+
}
483490
}, this.errorCallBack)
484491
}
485492
}
@@ -556,7 +563,7 @@ const uploadRecording = async (audioBlob: Blob) => {
556563
try {
557564
// 非自动发送切换输入框
558565
if (!props.applicationDetails.stt_autosend) {
559-
isMicrophone.value = false
566+
switchMicrophone(false)
560567
}
561568
recorderStatus.value = 'TRANSCRIBING'
562569
const formData = new FormData()
@@ -572,7 +579,7 @@ const uploadRecording = async (audioBlob: Blob) => {
572579
autoSendMessage()
573580
})
574581
} else {
575-
isMicrophone.value = false
582+
switchMicrophone(false)
576583
}
577584
})
578585
.catch((error) => {

0 commit comments

Comments
 (0)