From 4f73aa2030238e00600d371c92aebcbdd14d0492 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Tue, 8 Oct 2024 12:58:17 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E6=A3=80=E6=9F=A5=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E6=96=B9=E4=BA=BA=E5=91=98=E9=97=A8=E7=A6=81=E5=88=B0?= =?UTF-8?q?=E6=9C=9F=E8=AE=BE=E4=B8=BA=E7=A6=BB=E8=81=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/rpm/tasks.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/apps/rpm/tasks.py b/apps/rpm/tasks.py index aa24d3f9..8d314a34 100644 --- a/apps/rpm/tasks.py +++ b/apps/rpm/tasks.py @@ -5,6 +5,7 @@ from apps.rpm.services import rpj_member_leave from apps.utils.tasks import CustomTask from celery import shared_task from django.utils import timezone +from datetime import datetime @shared_task(base=CustomTask) @@ -30,3 +31,13 @@ def close_rpj_by_leave_time(): for m in Rpjmember.objects.filter(rpj__in=rpjs): rpj_member_leave(m) + + +def check_remployee_leave(): + """ + 检查相关方是否已经离开 + """ + now = datetime.now() + now_str = now.strftime('%Y-%m-%d %H:%M:%S') + from apps.hrm.models import Employee + Employee.objects.filter(type='remployee', third_info__dh_face_card_end__lte=now_str).update(job_state=Employee.JOB_OFF) \ No newline at end of file From 494b078a09ba02f4b748700421de341330b0d550 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Tue, 8 Oct 2024 15:10:42 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20save=5Fvoice=5Fand=5Fspeak=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/ecm/service.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/apps/ecm/service.py b/apps/ecm/service.py index f7c981f9..756481e2 100644 --- a/apps/ecm/service.py +++ b/apps/ecm/service.py @@ -159,10 +159,9 @@ def save_voice_and_speak(event: Event): if event.voice: # 如果已经生成了报警声音不用再请求 pass else: - if getattr(settings, 'BD_SP_ENABLED', False): - _, event.voice, _ = generate_voice(event.voice_msg, v_p) - event.save() - if main_cate.speaker_on: + _, event.voice, _ = generate_voice(event.voice_msg, v_p) + event.save() + if main_cate.speaker_on and event.voice: sps = [] if event.area: # 如果事件存在发生区域 sps = list(TDevice.objects.filter(area=event.area, From 7c71eafa416bd10dc38794e856fc52524f6e58e4 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Tue, 8 Oct 2024 15:10:59 +0800 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0edge-tts=E8=AF=AD?= =?UTF-8?q?=E9=9F=B3=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/utils/speech.py | 37 ++++++++++++++++++++++++++----------- requirements.txt | 1 + 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/apps/utils/speech.py b/apps/utils/speech.py index d48b3a3f..9925f4c6 100644 --- a/apps/utils/speech.py +++ b/apps/utils/speech.py @@ -3,6 +3,8 @@ from django.conf import settings import uuid import os from django.utils import timezone +import edge_tts +from asgiref.sync import async_to_sync def generate_voice(msg: str, per: int = 0): @@ -17,16 +19,29 @@ def generate_voice(msg: str, per: int = 0): str: 地址 dict: result """ - client = AipSpeech(settings.BD_SP_ID, settings.BD_SP_KEY, settings.BD_SP_SECRET) - result = client.synthesis(msg, 'zh', 1, {'vol': 5, 'spd': 5, 'per': per}) - # 识别正确返回语音二进制 错误则返回dict 参照下面错误码 - if not isinstance(result, dict): - file_name = '{}.mp3'.format(uuid.uuid4()) - path = '/media/' + timezone.now().strftime('%Y/%m/%d/') - full_path = settings.BASE_DIR + path - if not os.path.exists(full_path): - os.makedirs(full_path) - with open(full_path + file_name, 'wb') as f: - f.write(result) + file_name = '{}.mp3'.format(uuid.uuid4()) + path = '/media/' + timezone.now().strftime('%Y/%m/%d/') + full_path = settings.BASE_DIR + path + if not os.path.exists(full_path): + os.makedirs(full_path) + result = None + if getattr(settings, 'BD_SP_ENABLED', False): + client = AipSpeech(settings.BD_SP_ID, settings.BD_SP_KEY, settings.BD_SP_SECRET) + result = client.synthesis(msg, 'zh', 1, {'vol': 5, 'spd': 5, 'per': per}) + # 识别正确返回语音二进制 错误则返回dict 参照下面错误码 + if not isinstance(result, dict): + with open(full_path + file_name, 'wb') as f: + f.write(result) + return True, path + file_name, None + elif getattr(settings, 'EDGE_TTS_ENABLED', False): + if per == 0: + per = 'zh-CN-XiaoxiaoNeural' + else: + per = 'zh-CN-YunjianNeural' + communicate = edge_tts.Communicate(msg, per) + try: + async_to_sync(communicate.save(full_path + file_name)) return True, path + file_name, None + except Exception as e: + result = str(e) return False, None, result diff --git a/requirements.txt b/requirements.txt index ed37fcc6..f04b0c51 100755 --- a/requirements.txt +++ b/requirements.txt @@ -34,3 +34,4 @@ pymysql==1.0.3 docxtpl==0.16.7 paho-mqtt==2.0.0 # deepface==0.0.79 +# edge-tts==6.1.12