Merge branch 'master' of https://e.coding.net/ctcdevteam/ehs/ehs_server
This commit is contained in:
commit
7f9e2ad616
|
@ -159,10 +159,9 @@ def save_voice_and_speak(event: Event):
|
||||||
if event.voice: # 如果已经生成了报警声音不用再请求
|
if event.voice: # 如果已经生成了报警声音不用再请求
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if getattr(settings, 'BD_SP_ENABLED', False):
|
_, event.voice, _ = generate_voice(event.voice_msg, v_p)
|
||||||
_, event.voice, _ = generate_voice(event.voice_msg, v_p)
|
event.save()
|
||||||
event.save()
|
if main_cate.speaker_on and event.voice:
|
||||||
if main_cate.speaker_on:
|
|
||||||
sps = []
|
sps = []
|
||||||
if event.area: # 如果事件存在发生区域
|
if event.area: # 如果事件存在发生区域
|
||||||
sps = list(TDevice.objects.filter(area=event.area,
|
sps = list(TDevice.objects.filter(area=event.area,
|
||||||
|
|
|
@ -5,6 +5,7 @@ from apps.rpm.services import rpj_member_leave
|
||||||
from apps.utils.tasks import CustomTask
|
from apps.utils.tasks import CustomTask
|
||||||
from celery import shared_task
|
from celery import shared_task
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
@shared_task(base=CustomTask)
|
@shared_task(base=CustomTask)
|
||||||
|
@ -30,3 +31,13 @@ def close_rpj_by_leave_time():
|
||||||
|
|
||||||
for m in Rpjmember.objects.filter(rpj__in=rpjs):
|
for m in Rpjmember.objects.filter(rpj__in=rpjs):
|
||||||
rpj_member_leave(m)
|
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)
|
|
@ -3,6 +3,8 @@ from django.conf import settings
|
||||||
import uuid
|
import uuid
|
||||||
import os
|
import os
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
import edge_tts
|
||||||
|
from asgiref.sync import async_to_sync
|
||||||
|
|
||||||
|
|
||||||
def generate_voice(msg: str, per: int = 0):
|
def generate_voice(msg: str, per: int = 0):
|
||||||
|
@ -17,16 +19,29 @@ def generate_voice(msg: str, per: int = 0):
|
||||||
str: 地址
|
str: 地址
|
||||||
dict: result
|
dict: result
|
||||||
"""
|
"""
|
||||||
client = AipSpeech(settings.BD_SP_ID, settings.BD_SP_KEY, settings.BD_SP_SECRET)
|
file_name = '{}.mp3'.format(uuid.uuid4())
|
||||||
result = client.synthesis(msg, 'zh', 1, {'vol': 5, 'spd': 5, 'per': per})
|
path = '/media/' + timezone.now().strftime('%Y/%m/%d/')
|
||||||
# 识别正确返回语音二进制 错误则返回dict 参照下面错误码
|
full_path = settings.BASE_DIR + path
|
||||||
if not isinstance(result, dict):
|
if not os.path.exists(full_path):
|
||||||
file_name = '{}.mp3'.format(uuid.uuid4())
|
os.makedirs(full_path)
|
||||||
path = '/media/' + timezone.now().strftime('%Y/%m/%d/')
|
result = None
|
||||||
full_path = settings.BASE_DIR + path
|
if getattr(settings, 'BD_SP_ENABLED', False):
|
||||||
if not os.path.exists(full_path):
|
client = AipSpeech(settings.BD_SP_ID, settings.BD_SP_KEY, settings.BD_SP_SECRET)
|
||||||
os.makedirs(full_path)
|
result = client.synthesis(msg, 'zh', 1, {'vol': 5, 'spd': 5, 'per': per})
|
||||||
with open(full_path + file_name, 'wb') as f:
|
# 识别正确返回语音二进制 错误则返回dict 参照下面错误码
|
||||||
f.write(result)
|
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
|
return True, path + file_name, None
|
||||||
|
except Exception as e:
|
||||||
|
result = str(e)
|
||||||
return False, None, result
|
return False, None, result
|
||||||
|
|
|
@ -34,3 +34,4 @@ pymysql==1.0.3
|
||||||
docxtpl==0.16.7
|
docxtpl==0.16.7
|
||||||
paho-mqtt==2.0.0
|
paho-mqtt==2.0.0
|
||||||
# deepface==0.0.79
|
# deepface==0.0.79
|
||||||
|
# edge-tts==6.1.12
|
||||||
|
|
Loading…
Reference in New Issue