feat(chat): add SiliconFlow ASR for agent voice input
Replace Web Speech API with MediaRecorder upload to POST /api/speech/transcribe, calling SenseVoice via the existing GJL API credentials. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
445763e144
commit
8f69131872
9 files changed
+350
-215
No files matched your search
@@ -21,7 +21,7 @@ import DeleteConfirmDialog from '../components/DeleteConfirmDialog.vue';
|
||||
import GeneralFeedbackDialog from '../components/GeneralFeedbackDialog.vue';
|
||||
import { useMessage } from '../composables/useMessage';
|
||||
import { useIsMobile } from '../composables/useIsMobile';
|
||||
import { getVoiceUnavailableErrorKey, useSpeechRecognition } from '../composables/useSpeechRecognition';
|
||||
import { getVoiceUnavailableErrorKey, useAudioTranscription } from '../composables/useAudioTranscription';
|
||||
import { useTheme } from '../composables/useTheme';
|
||||
import { getAuthHeaders, getStoredAuthUser, logoutAuth } from '../utils/auth';
|
||||
import { copyTextToClipboard } from '../utils/clipboard';
|
||||
@@ -664,11 +664,11 @@ const copiedIndex = ref<number | null>(null);
|
||||
const { messages, isThinking, conversationId, runs, activeRunId, activateRun, createNewChatView, sendMessage } = useChat();
|
||||
const input = ref('');
|
||||
const {
|
||||
isListening: isVoiceListening,
|
||||
isRecording: isVoiceRecording,
|
||||
isTranscribing: isVoiceTranscribing,
|
||||
toggle: toggleVoiceInput,
|
||||
stop: stopVoiceInput,
|
||||
} = useSpeechRecognition({
|
||||
lang: locale,
|
||||
cancel: cancelVoiceInput,
|
||||
} = useAudioTranscription({
|
||||
onResult: (text) => {
|
||||
input.value = text;
|
||||
},
|
||||
@@ -678,7 +678,7 @@ const {
|
||||
});
|
||||
|
||||
const handleVoiceFeatureClick = () => {
|
||||
if (isThinking.value) return;
|
||||
if (isThinking.value || isVoiceTranscribing.value) return;
|
||||
const unavailable = getVoiceUnavailableErrorKey();
|
||||
if (unavailable) {
|
||||
msg.warning(t(unavailable));
|
||||
@@ -688,7 +688,7 @@ const handleVoiceFeatureClick = () => {
|
||||
};
|
||||
|
||||
watch(isThinking, (thinking) => {
|
||||
if (thinking) stopVoiceInput();
|
||||
if (thinking) cancelVoiceInput();
|
||||
});
|
||||
|
||||
const currentAgent = ref<any>(null);
|
||||
@@ -2484,7 +2484,7 @@ const syncChatStateForRoute = async () => {
|
||||
|
||||
const syncToken = ++routeSyncToken;
|
||||
resetChatStateForAgentChange();
|
||||
stopVoiceInput();
|
||||
cancelVoiceInput();
|
||||
setLastChatAgentId(agentId);
|
||||
syncOpenAgentRegistration();
|
||||
|
||||
@@ -3285,10 +3285,10 @@ const showChatRating = ref(false);
|
||||
v-model="input"
|
||||
@keydown.enter.prevent="handleSend"
|
||||
rows="1"
|
||||
:placeholder="isVoiceListening ? $t('chat.voiceListening') : $t('chat.askAnything')"
|
||||
:placeholder="isVoiceTranscribing ? $t('chat.voiceTranscribing') : isVoiceRecording ? $t('chat.voiceListening') : $t('chat.askAnything')"
|
||||
class="w-full resize-none border-none bg-transparent px-3 py-2 text-[15px] leading-relaxed text-primary placeholder-slate-400 focus:outline-none focus:ring-0 focus:border-transparent"
|
||||
style="min-height: 44px; max-height: 220px;"
|
||||
:disabled="isThinking"
|
||||
:disabled="isThinking || isVoiceTranscribing"
|
||||
spellcheck="false"
|
||||
autocorrect="off"
|
||||
autocapitalize="off"
|
||||
@@ -3323,12 +3323,13 @@ const showChatRating = ref(false);
|
||||
<button
|
||||
@click="handleVoiceFeatureClick"
|
||||
type="button"
|
||||
:disabled="isThinking"
|
||||
:title="isVoiceListening ? $t('chat.voiceStop') : $t('chat.voiceFeature')"
|
||||
:disabled="isThinking || isVoiceTranscribing"
|
||||
:title="isVoiceRecording ? $t('chat.voiceStop') : isVoiceTranscribing ? $t('chat.voiceTranscribing') : $t('chat.voiceFeature')"
|
||||
class="transition-colors disabled:cursor-not-allowed disabled:opacity-50"
|
||||
:class="isVoiceListening ? 'text-red-500 animate-pulse' : 'text-muted hover:text-brand-600'"
|
||||
:class="isVoiceRecording ? 'text-red-500 animate-pulse' : isVoiceTranscribing ? 'text-brand-500' : 'text-muted hover:text-brand-600'"
|
||||
>
|
||||
<Mic class="h-5 w-5" />
|
||||
<Loader2 v-if="isVoiceTranscribing" class="h-5 w-5 animate-spin" />
|
||||
<Mic v-else class="h-5 w-5" />
|
||||
</button>
|
||||
<div v-if="attachmentPolicy.anyEnabled" ref="attachmentMenuRef" class="relative">
|
||||
<button
|
||||
|
||||
Reference in new issue
Block a user