From d4f32673ab4c034a3080f56cbc5eeed78fe2944e Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Fri, 10 Jan 2025 22:08:43 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=8C=81=E4=B9=85?= =?UTF-8?q?=E5=8C=96=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/dashboard/routes/chat.py | 5 +++-- dashboard/src/views/ChatPage.vue | 9 ++++++--- stt.py | 33 ++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 stt.py diff --git a/astrbot/dashboard/routes/chat.py b/astrbot/dashboard/routes/chat.py index 2e44db351..735673976 100644 --- a/astrbot/dashboard/routes/chat.py +++ b/astrbot/dashboard/routes/chat.py @@ -68,8 +68,9 @@ class ChatRoute(Route): conversation = self.db.get_webchat_conversation_by_user_id(username, conversation_id) try: - history = json.loads(conversation['history']) - except BaseException: + history = json.loads(conversation.history) + except BaseException as e: + print(e) history = [] history.append({ 'type': 'user', diff --git a/dashboard/src/views/ChatPage.vue b/dashboard/src/views/ChatPage.vue index 0a60e4c23..fcf7f92a8 100644 --- a/dashboard/src/views/ChatPage.vue +++ b/dashboard/src/views/ChatPage.vue @@ -14,12 +14,13 @@ marked.setOptions({
-
+
- 创建对话 - 删除对话 + + 创建对话 + @@ -36,6 +37,8 @@ marked.setOptions({ + + 删除此对话
diff --git a/stt.py b/stt.py new file mode 100644 index 000000000..9eee69b8a --- /dev/null +++ b/stt.py @@ -0,0 +1,33 @@ +import torch +from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline +from datasets import load_dataset + + +device = "cuda:0" if torch.cuda.is_available() else "cpu" +torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32 + +model_id = "openai/whisper-large-v3" + +model = AutoModelForSpeechSeq2Seq.from_pretrained( + model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True +) +model.to(device) + +processor = AutoProcessor.from_pretrained(model_id) + +pipe = pipeline( + "automatic-speech-recognition", + model=model, + tokenizer=processor.tokenizer, + feature_extractor=processor.feature_extractor, + chunk_length_s=30, + batch_size=16, # batch size for inference - set based on your device + torch_dtype=torch_dtype, + device=device, +) + +dataset = load_dataset("distil-whisper/librispeech_long", "clean", split="validation") +sample = dataset[0]["audio"] + +result = pipe(sample) +print(result["text"])