bugfix: 语音输入动画重复初始化

This commit is contained in:
zhangyh
2025-10-20 11:24:11 +08:00
parent 8994b4a1d2
commit 617351d0dd
3 changed files with 10 additions and 38 deletions

View File

@@ -13,7 +13,8 @@
<div class="input-container">
<!-- 加号图标 -->
<div class="icon-wrapper">
<SvgIcon name="plus" size="40" />
<SvgIcon v-if="!isRecording" name="plus" size="40" />
<SvgIcon v-else name="pause" size="60" @click="stopRecording" />
</div>
<!-- 分隔线 -->
@@ -97,12 +98,12 @@ const handleInput = (): void => {
if (textareaRef.value) {
textareaRef.value.style.height = 'auto'
// const lineHeight = 4.8
// const lineHeight = 4.8
// const maxLines = 3
// const maxHeight = lineHeight * maxLines
const scrollHeight = textareaRef.value.scrollHeight
// const newHeight = Math.min(scrollHeight, maxHeight * 10)
// const newHeight = Math.min(scrollHeight, maxHeight * 10)
textareaRef.value.style.height = `${scrollHeight}px`
}
@@ -138,9 +139,6 @@ const handleClickAudio = async (): Promise<void> => {
audioVisualizerRef.value.updateLines?.()
}
}, 50)
}
if (isRecording.value) {
startRecording()
} else {
stopRecording()
@@ -174,7 +172,7 @@ const startRecording = () => {
}
// 识别结果
speechRecognition.onresult = (event) => {
speechRecognition.onresult = (event: any) => {
let finalTranscript = ''
let interimTranscript = ''
@@ -213,7 +211,7 @@ const startRecording = () => {
}
// 识别错误
speechRecognition.onerror = (event) => {
speechRecognition.onerror = (event: any) => {
console.error('语音识别错误:', event.error)
isRecording.value = false
// alert('语音识别失败,请重试')
@@ -273,6 +271,7 @@ const stopRecording = () => {
align-items: center;
justify-content: center;
cursor: pointer;
color: #6d6868;
&.send-icon {
margin-left: 4.38rem;