From 88e390fe81005608ae3518fc37e114627eed2c73 Mon Sep 17 00:00:00 2001 From: untunt Date: Fri, 8 Mar 2024 12:50:40 +0800 Subject: [PATCH 1/3] Translate into Chinese and simplify UI --- src/App.tsx | 20 +------ src/components/AudioManager.tsx | 91 +++++++++++++---------------- src/components/AudioRecorder.tsx | 8 +-- src/components/TranscribeButton.tsx | 6 +- src/components/Transcript.tsx | 7 ++- src/components/modal/Modal.tsx | 4 +- src/css/index.css | 6 ++ src/utils/Constants.ts | 7 ++- src/worker.js | 8 ++- vite.config.ts | 18 ++++++ 10 files changed, 90 insertions(+), 85 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index cf9844e..1e87f50 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -6,27 +6,11 @@ function App() { const transcriber = useTranscriber(); return ( -
-
-

- Whisper Web -

-

- ML-powered speech recognition directly in your browser -

+
+
- -
- Made with{" "} - - 🤗 Transformers.js - -
); } diff --git a/src/components/AudioManager.tsx b/src/components/AudioManager.tsx index 6919a2d..46b361c 100644 --- a/src/components/AudioManager.tsx +++ b/src/components/AudioManager.tsx @@ -11,7 +11,7 @@ import AudioRecorder from "./AudioRecorder"; function titleCase(str: string) { str = str.toLowerCase(); - return (str.match(/\w+.?/g) || []) + return (str.match(/\w+.?|.*语 /g) || []) .map((word) => { return word.charAt(0).toUpperCase() + word.slice(1); }) @@ -23,7 +23,7 @@ function titleCase(str: string) { // https://github.com/openai/whisper/blob/248b6cb124225dd263bb9bd32d060b6517e067f8/whisper/tokenizer.py#L79 const LANGUAGES = { en: "english", - zh: "chinese", + zh: "汉语 chinese", de: "german", es: "spanish/castilian", ru: "russian", @@ -241,18 +241,22 @@ export function AudioManager(props: { transcriber: Transcriber }) { <>
- } - text={"From URL"} - onUrlUpdate={(e) => { - props.transcriber.onInputChange(); - setAudioDownloadUrl(e); - }} - /> - + {navigator.mediaDevices && ( + <> + } + text={"录制音频"} + setAudioData={(e) => { + props.transcriber.onInputChange(); + setAudioFromRecording(e); + }} + /> + + + )} } - text={"From file"} + text={"打开音频"} onFileUpdate={(decoded, blobUrl, mimeType) => { props.transcriber.onInputChange(); setAudioData({ @@ -263,19 +267,12 @@ export function AudioManager(props: { transcriber: Transcriber }) { }); }} /> - {navigator.mediaDevices && ( - <> - - } - text={"Record"} - setAudioData={(e) => { - props.transcriber.onInputChange(); - setAudioFromRecording(e); - }} - /> - - )} + + } + />
{ - - } - />
{props.transcriber.progressItems.length > 0 && (
{props.transcriber.progressItems.map((data) => (
@@ -329,7 +320,7 @@ export function AudioManager(props: { transcriber: Transcriber }) { function SettingsTile(props: { icon: JSX.Element; - className?: string; + text: string; transcriber: Transcriber; }) { const [showModal, setShowModal] = useState(false); @@ -347,15 +338,15 @@ function SettingsTile(props: { }; return ( -
- + <> + -
+ ); } @@ -381,10 +372,10 @@ function SettingsModal(props: { return ( - + { props.transcriber.setQuantized( - e.target.checked, + !e.target.checked, ); }} >
{props.transcriber.multilingual && ( <> - + - + )} @@ -680,17 +669,17 @@ function RecordModal(props: { return ( - {"Record audio using your microphone"} } onClose={onClose} - submitText={"Load"} + submitText={"使用录音"} submitEnabled={audioBlob !== undefined} onSubmit={onSubmit} + closeText={"放弃录音"} /> ); } diff --git a/src/components/AudioRecorder.tsx b/src/components/AudioRecorder.tsx index 5bdfe6d..8dd4804 100644 --- a/src/components/AudioRecorder.tsx +++ b/src/components/AudioRecorder.tsx @@ -120,7 +120,7 @@ export default function AudioRecorder(props: { return (
- + ? `结束录音 (${formatAudioTimestamp(duration)})` + : "开始录音"} + )} {recordedBlob && (