chore: wip

This commit is contained in:
DDMeaqua 2024-10-12 16:54:02 +08:00
parent 5999604df4
commit 80a7a1d9d0
4 changed files with 13 additions and 7 deletions

View File

@ -370,6 +370,7 @@ export function ChatAction(props: {
text: string; text: string;
icon: JSX.Element; icon: JSX.Element;
onClick: () => void; onClick: () => void;
recording?: boolean;
}) { }) {
const iconRef = useRef<HTMLDivElement>(null); const iconRef = useRef<HTMLDivElement>(null);
const textRef = useRef<HTMLDivElement>(null); const textRef = useRef<HTMLDivElement>(null);
@ -378,7 +379,7 @@ export function ChatAction(props: {
icon: 16, icon: 16,
}); });
function updateWidth() { function updateWidth(recording?: boolean) {
if (!iconRef.current || !textRef.current) return; if (!iconRef.current || !textRef.current) return;
const getWidth = (dom: HTMLDivElement) => dom.getBoundingClientRect().width; const getWidth = (dom: HTMLDivElement) => dom.getBoundingClientRect().width;
const textWidth = getWidth(textRef.current); const textWidth = getWidth(textRef.current);
@ -559,7 +560,7 @@ export function ChatActions(props: {
useEffect(() => { useEffect(() => {
if (isFirefox()) config.sttConfig.engine = FIREFOX_DEFAULT_STT_ENGINE; if (isFirefox()) config.sttConfig.engine = FIREFOX_DEFAULT_STT_ENGINE;
setSpeechApi( setSpeechApi(
config.sttConfig.engine === DEFAULT_STT_ENGINE config.sttConfig.engine !== DEFAULT_STT_ENGINE
? new WebTranscriptionApi((transcription) => ? new WebTranscriptionApi((transcription) =>
onRecognitionEnd(transcription), onRecognitionEnd(transcription),
) )
@ -570,6 +571,7 @@ export function ChatActions(props: {
}, []); }, []);
const startListening = async () => { const startListening = async () => {
showToast(Locale.Chat.StartSpeak);
if (speechApi) { if (speechApi) {
await speechApi.start(); await speechApi.start();
setIsListening(true); setIsListening(true);
@ -582,6 +584,7 @@ export function ChatActions(props: {
await speechApi.stop(); await speechApi.stop();
setIsListening(false); setIsListening(false);
} }
showToast(Locale.Chat.CloseSpeak);
}; };
const onRecognitionEnd = (finalTranscript: string) => { const onRecognitionEnd = (finalTranscript: string) => {
console.log(finalTranscript); console.log(finalTranscript);
@ -832,6 +835,7 @@ export function ChatActions(props: {
} }
text={isListening ? Locale.Chat.StopSpeak : Locale.Chat.StartSpeak} text={isListening ? Locale.Chat.StopSpeak : Locale.Chat.StartSpeak}
icon={isListening ? <VoiceOpenIcon /> : <VoiceCloseIcon />} icon={isListening ? <VoiceOpenIcon /> : <VoiceCloseIcon />}
recording={isListening}
/> />
)} )}
</div> </div>

View File

@ -271,8 +271,8 @@ export const DEFAULT_TTS_VOICES = [
"shimmer", "shimmer",
]; ];
export const DEFAULT_STT_ENGINE = "Web Speech API"; export const DEFAULT_STT_ENGINE = "OpenAI Whisper";
export const DEFAULT_STT_ENGINES = ["Web Speech API", "OpenAI Whisper"]; export const DEFAULT_STT_ENGINES = ["OpenAI Whisper", "Web Speech API"];
export const DEFAULT_STT_LANGUAGE = "zh-CN"; export const DEFAULT_STT_LANGUAGE = "zh-CN";
export const DEFAULT_STT_LANGUAGES = [ export const DEFAULT_STT_LANGUAGES = [
"zh-CN", // 中文(简体) "zh-CN", // 中文(简体)

View File

@ -92,8 +92,9 @@ const cn = {
return inputHints + "/ 触发补全,: 触发命令"; return inputHints + "/ 触发补全,: 触发命令";
}, },
Send: "发送", Send: "发送",
StartSpeak: "说话", StartSpeak: "启用语音输入",
StopSpeak: "停止", CloseSpeak: "关闭语音输入",
StopSpeak: "录音中....点击结束",
Config: { Config: {
Reset: "清除记忆", Reset: "清除记忆",
SaveAs: "存为面具", SaveAs: "存为面具",

View File

@ -94,7 +94,8 @@ const en: LocaleType = {
}, },
Send: "Send", Send: "Send",
StartSpeak: "Start Speak", StartSpeak: "Start Speak",
StopSpeak: "Stop Speak", CloseSpeak: "Stop Speak",
StopSpeak: "Recording...",
Config: { Config: {
Reset: "Reset to Default", Reset: "Reset to Default",
SaveAs: "Save as Mask", SaveAs: "Save as Mask",