From b082b5eb1b256a9048c32d249276fbaa0dc7975d Mon Sep 17 00:00:00 2001 From: 505030475 Date: Mon, 3 Jul 2023 23:20:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E9=98=BF=E9=87=8C=E4=BA=91TOKEN?= =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E5=88=B0config=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.py | 8 +++++--- crazy_functions/live_audio/aliyunASR.py | 14 +++++++------- crazy_functions/辅助面试.py | 17 ++++++++++++++++- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/config.py b/config.py index 6fff280..0d67983 100644 --- a/config.py +++ b/config.py @@ -62,8 +62,6 @@ AUTO_CLEAR_TXT = False # 色彩主体,可选: "Default", "Green" THEME = "Default" -ENABLE_AUDIO = True - # 加一个live2d装饰 ADD_WAIFU = False @@ -91,9 +89,13 @@ your bing cookies here SLACK_CLAUDE_BOT_ID = '' SLACK_CLAUDE_USER_TOKEN = '' - # 如果需要使用AZURE 详情请见额外文档 docs\use_azure.md AZURE_ENDPOINT = "https://你的api名称.openai.azure.com/" AZURE_API_KEY = "填入azure openai api的密钥" AZURE_API_VERSION = "填入api版本" AZURE_ENGINE = "填入ENGINE" + +# 阿里云实时语音识别 配置门槛较高 限高级用户使用 参考 https://help.aliyun.com/document_detail/450255.html +ENABLE_AUDIO = True +ALIYUN_TOKEN="" # 例如 f37f30e0f9934c34a992f6f64f7eba4f +ALIYUN_APPKEY="" # 例如 RoPlZrM88DnAFkZK diff --git a/crazy_functions/live_audio/aliyunASR.py b/crazy_functions/live_audio/aliyunASR.py index 3b56e49..aa8ecc9 100644 --- a/crazy_functions/live_audio/aliyunASR.py +++ b/crazy_functions/live_audio/aliyunASR.py @@ -34,17 +34,17 @@ class AliyunASR(): def audio_convertion_thread(self, uuid): # 在一个异步线程中采集音频 import nls # pip install git+https://github.com/aliyun/alibabacloud-nls-python-sdk.git - from scipy import io - from .audio_io import change_sample_rate - NEW_SAMPLERATE = 16000 - from .audio_io import RealtimeAudioDistribution - rad = RealtimeAudioDistribution() import tempfile + from scipy import io + from toolbox import get_conf + from .audio_io import change_sample_rate + from .audio_io import RealtimeAudioDistribution + NEW_SAMPLERATE = 16000 + rad = RealtimeAudioDistribution() temp_folder = tempfile.gettempdir() + TOKEN, APPKEY = get_conf('ALIYUN_TOKEN', 'ALIYUN_APPKEY') URL="wss://nls-gateway.cn-shanghai.aliyuncs.com/ws/v1" - TOKEN="f37f30e0f9934c34a992f6f64f7eba4f" # 参考https://help.aliyun.com/document_detail/450255.html获取token - APPKEY="RoPlZrM88DnAFkZK" # 获取Appkey请前往控制台:https://nls-portal.console.aliyun.com/applist sr = nls.NlsSpeechTranscriber( url=URL, token=TOKEN, diff --git a/crazy_functions/辅助面试.py b/crazy_functions/辅助面试.py index d1d79e3..9a70987 100644 --- a/crazy_functions/辅助面试.py +++ b/crazy_functions/辅助面试.py @@ -1,5 +1,5 @@ from toolbox import update_ui -from toolbox import CatchException, report_execption, write_results_to_file +from toolbox import CatchException, get_conf, write_results_to_file from crazy_functions.crazy_utils import request_gpt_model_in_new_thread_with_ui_alive from request_llm.bridge_all import predict_no_ui_long_connection import threading, time @@ -108,6 +108,21 @@ def 辅助面试(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt chatbot.append(["函数插件功能:辅助面试", "辅助面试助手, 正在监听音频 ..."]) yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 + # 尝试导入依赖,如果缺少依赖,则给出安装建议 + try: + import nls + from scipy import io + except: + chatbot.append(["导入依赖失败", "使用该模块需要额外依赖, 安装方法:```pip install scipy git+https://github.com/aliyun/alibabacloud-nls-python-sdk.git```"]) + yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 + return + + TOKEN, APPKEY = get_conf('ALIYUN_TOKEN', 'ALIYUN_APPKEY') + if TOKEN == "" or APPKEY == "": + chatbot.append(["导入依赖失败", "没有阿里云语音识别APPKEY和TOKEN, 详情见https://help.aliyun.com/document_detail/450255.html"]) + yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 + return + yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 ia = InterviewAssistant() yield from ia.begin(llm_kwargs, plugin_kwargs, chatbot, history, system_prompt)