Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
水玉婷
ai-wechat
Commits
86790086
Commit
86790086
authored
Nov 27, 2025
by
水玉婷
Browse files
feat: 添加env环境变量
parent
9e1b9591
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/views/components/VoiceRecognition.vue
View file @
86790086
...
...
@@ -4,9 +4,14 @@
<button
class=
"voice-btn"
:class=
"
{ 'recording': isRecording, 'disabled': disabled }"
@click="toggleRecording"
@mousedown="startRecording"
@mouseup="stopRecording"
@mouseleave="stopRecording"
@touchstart="startRecording"
@touchend="stopRecording"
@touchcancel="stopRecording"
:disabled="disabled"
:title="isRecording ? '停止
录音
' : '
开始
说话'"
:title="isRecording ? '
松开
停止' : '
按住
说话'"
>
<!-- 语音图标始终显示 -->
<span
class=
"voice-icon"
>
...
...
@@ -48,6 +53,8 @@ const props = withDefaults(defineProps<Props>(), {
const
emit
=
defineEmits
<
{
audio
:
[
audioUrl
:
string
,
audioBlob
:
Blob
]
error
:
[
error
:
string
]
recordingStart
:
[]
recordingStop
:
[]
}
>
()
// 响应式数据
...
...
@@ -128,7 +135,7 @@ const showPermissionGuide = () => {
// 开始录音
const
startRecording
=
async
()
=>
{
if
(
props
.
disabled
)
return
if
(
props
.
disabled
||
isRecording
.
value
)
return
// 检查权限
const
hasPermission
=
await
checkMicrophonePermission
();
...
...
@@ -180,6 +187,9 @@ const startRecording = async () => {
isRecording
.
value
=
true
;
showStatusMessage
(
'
正在录音...
'
);
// 通知父组件开始录音
emit
(
'
recordingStart
'
);
if
(
props
.
debug
)
{
console
.
log
(
'
开始录音,MediaRecorder状态:
'
,
mediaRecorder
.
value
.
state
);
}
...
...
@@ -202,6 +212,8 @@ const startRecording = async () => {
// 停止录音
const
stopRecording
=
()
=>
{
if
(
!
isRecording
.
value
)
return
if
(
mediaRecorder
.
value
&&
mediaRecorder
.
value
.
state
===
'
recording
'
)
{
mediaRecorder
.
value
.
stop
();
isRecording
.
value
=
false
;
...
...
@@ -212,6 +224,9 @@ const stopRecording = () => {
audioStream
.
value
=
null
;
}
// 通知父组件停止录音
emit
(
'
recordingStop
'
);
if
(
props
.
debug
)
{
console
.
log
(
'
停止录音,MediaRecorder状态:
'
,
mediaRecorder
.
value
.
state
);
}
...
...
@@ -281,15 +296,6 @@ const sendRecordedAudio = async () => {
}
}
// 切换录音状态
const
toggleRecording
=
()
=>
{
if
(
isRecording
.
value
)
{
stopRecording
();
}
else
{
startRecording
();
}
}
// 组件卸载时清理资源
onUnmounted
(()
=>
{
if
(
isRecording
.
value
)
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment