feat(voice): 开启语音输入

This commit is contained in:
sophie committed 2026-07-09 15:48:29 +08:00
1 parent b89f9bafb6
commit 348f0fdcfd
2 files changed
+12 -9

No files matched your search

@@ -1,12 +1,13 @@
/**
* 对话页:语音输入(当前功能开关关闭,保留占位与思考态取消录音)。
* features/chat/page/useChatPageVoice.ts
* 用途:封装对话页语音输入按钮行为,将浏览器录音结果回填到输入框。
* 依赖:Vue watch、shared/composables/useAudioTranscription、聊天页 message/i18n 上下文。
* 逻辑:ChatViewContent 触发按钮点击后,本文件先做思考态与浏览器能力校验,再交给转写 composable 录音并调用后端 ASR。
*/
import { watch } from 'vue';
import { getVoiceUnavailableErrorKey, useAudioTranscription } from '@/shared/composables/useAudioTranscription';
import type { Ref } from 'vue';
const VOICE_INPUT_ENABLED = false;
export interface ChatPageVoiceContext {
input: Ref<string>;
isThinking: Ref<boolean>;
@@ -14,6 +15,12 @@ export interface ChatPageVoiceContext {
t: (key: string) => string;
}
/**
* 绑定聊天页语音输入状态与操作。
* 核心逻辑:复用 useAudioTranscription 完成录音/转写;点击时只拦截思考中、转写中、非 HTTPS 或浏览器不支持的场景。
* @param ctx - 聊天页输入框、思考态、消息提示与 i18n 翻译上下文。
* @returns 语音录制状态、转写状态、点击处理函数与取消函数。
*/
export function useChatPageVoice(ctx: ChatPageVoiceContext) {
const {
isRecording: isVoiceRecording,
@@ -30,10 +37,6 @@ export function useChatPageVoice(ctx: ChatPageVoiceContext) {
});
const handleVoiceFeatureClick = () => {
if (!VOICE_INPUT_ENABLED) {
ctx.msg.info(ctx.t('chat.devComingSoon'));
return;
}
if (ctx.isThinking.value || isVoiceTranscribing.value) return;
const unavailable = getVoiceUnavailableErrorKey();
if (unavailable) {
@@ -166,7 +166,7 @@ defineProps<{
<button
@click="kb.handleSaveMarkdown"
:disabled="kb.isMarkdownLoading || kb.isMarkdownSaving || !kb.markdownDocumentId"
class="inline-flex items-center justify-center rounded-xl bg-brand-600px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-brand-700 disabled:cursor-not-allowed disabled:opacity-60"
class="inline-flex items-center justify-center rounded-xl bg-brand-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-brand-700 disabled:cursor-not-allowed disabled:opacity-60"
>
{{ kb.isMarkdownSaving ? kb.t('kbWorkspace.markdownModal.saving') : kb.t('kbWorkspace.markdownModal.save') }}
</button>
@@ -465,7 +465,7 @@ defineProps<{
</button>
<button
@click="kb.handleConfirmPathUpload"
class="inline-flex items-center justify-center gap-2 rounded-xl bg-brand-600px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-brand-700"
class="inline-flex items-center justify-center gap-2 rounded-xl bg-brand-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-brand-700"
>
<Upload class="h-4 w-4" />
{{ kb.t('kbWorkspace.pathUploadModal.confirmUpload') }}