feat:修改喇叭内容
This commit is contained in:
parent
a563566623
commit
336f35ed28
|
@ -30,6 +30,7 @@ class TestAlgoSerializer(serializers.Serializer):
|
|||
|
||||
|
||||
class SpeakerSerializer(serializers.Serializer):
|
||||
text_or_path = serializers.CharField(label='文本或音频文件路径')
|
||||
sns = serializers.ListField(child=serializers.CharField(), label="喇叭列表")
|
||||
|
||||
|
||||
|
|
|
@ -465,8 +465,8 @@ class TestViewSet(CustomGenericViewSet):
|
|||
|
||||
@action(methods=['post'], detail=False, serializer_class=SpeakerSerializer)
|
||||
def test_speaker(self, request, pk=None):
|
||||
spClient.speak(path='/media/2022/09/11/349b3451-50b9-4501-aded-c85a76967920.mp3', sns=request.data['sns'],
|
||||
v_num=2)
|
||||
spClient.speak(path=request.data['text_or_path'], sns=request.data['sns'],
|
||||
v_num=2)
|
||||
return Response()
|
||||
|
||||
@action(methods=['post'], detail=False, serializer_class=Serializer)
|
||||
|
|
|
@ -156,11 +156,11 @@ def save_voice_and_speak(event: Event):
|
|||
try:
|
||||
main_cate = event.cates.all().order_by('priority', 'create_time').first()
|
||||
v_p, v_num = main_cate.voice_person, main_cate.voice_num
|
||||
if event.voice: # 如果已经生成了报警声音不用再请求
|
||||
pass
|
||||
else:
|
||||
_, event.voice, _ = generate_voice(event.voice_msg, v_p)
|
||||
event.save()
|
||||
# if event.voice: # 如果已经生成了报警声音不用再请求
|
||||
# pass
|
||||
# else:
|
||||
# _, event.voice, _ = generate_voice(event.voice_msg, v_p)
|
||||
# event.save()
|
||||
if main_cate.speaker_on and event.voice:
|
||||
sps = []
|
||||
if event.area: # 如果事件存在发生区域
|
||||
|
@ -177,7 +177,7 @@ def save_voice_and_speak(event: Event):
|
|||
sps.append(i)
|
||||
# myLogger.info('获取到喇叭:' + str(sps))
|
||||
if sps:
|
||||
spClient.speak(event.voice, sps, v_num)
|
||||
spClient.speak(event.voice_msg, sps, v_num, v_p=v_p)
|
||||
except Exception:
|
||||
myLogger.error('喇叭播放失败', exc_info=True)
|
||||
|
||||
|
|
|
@ -149,6 +149,9 @@ def cal_mpointstat_hour(mpointId: str, year: int, month: int, day: int, hour: in
|
|||
first_val = getattr(mrs0.last(), f'val_{val_type}')
|
||||
if last_val >= first_val:
|
||||
val = last_val - first_val
|
||||
elif first_val - last_val > 0 and first_val - last_val < 1:
|
||||
val = 0
|
||||
myLogger.info(f'{mpoint.code}--{dt}--{last_val}--{first_val}--last_val 小于 first_val')
|
||||
else:
|
||||
# 这里判断有可能清零了
|
||||
max_val = max(mrs.aggregate(max=Max(f'val_{val_type}'))["max"], first_val)
|
||||
|
|
|
@ -82,21 +82,30 @@ class SpClient:
|
|||
else:
|
||||
self.handle_log(result='error', response=ret)
|
||||
except RequestException:
|
||||
print(traceback.format_exc())
|
||||
self.handle_log(result='error', errors=traceback.format_exc())
|
||||
if raise_exception:
|
||||
raise APIException(**SP_REQUEST_ERROR)
|
||||
return 'error', SP_REQUEST_ERROR
|
||||
|
||||
def speak(self, path: str, sns: list, v_num: int):
|
||||
def speak(self, path: str, sns: list, v_num: int, v_p: int=0):
|
||||
"""播放报警声
|
||||
|
||||
Args:
|
||||
path (str): 资源本地地址
|
||||
path (str): 资源本地地址或文本内容
|
||||
sns (list): 喇叭sn队列
|
||||
v_num (int): 播放次数
|
||||
"""
|
||||
uri = path
|
||||
if not uri.startswith('http'):
|
||||
is_text = False
|
||||
if '/' not in path:
|
||||
is_text = True
|
||||
if is_text:
|
||||
v_p_voice = "xiaoyan"
|
||||
if v_p != 0:
|
||||
v_p_voice = "xiaofeng"
|
||||
uri = f"{settings.SP_TTS_URL}/tts_xf.single?text={path}&voice_name={v_p_voice}&speed=50&volume=100&origin={settings.SP_TTS_URL}"
|
||||
elif not uri.startswith('http'):
|
||||
uri = settings.BASE_URL_IN + path
|
||||
urls = []
|
||||
while v_num > 0:
|
||||
|
@ -117,6 +126,33 @@ class SpClient:
|
|||
}
|
||||
self.request(**spapis['send_to_device'], json=json)
|
||||
return
|
||||
"""
|
||||
Args:
|
||||
text (str): 文本内容
|
||||
sns (list): 喇叭sn队列
|
||||
v_num (int): 播放次数
|
||||
"""
|
||||
if text:
|
||||
uri = f"{settings.SP_TTS_URL}/tts_xf.single?text=有车辆上磅35.5千克,请刷卡。&voice_name=xiaoyan&speed=50&volume=100&origin={settings.SP_TTS_URL}"
|
||||
urls = []
|
||||
while v_num > 0:
|
||||
urls.append({
|
||||
"name": "alarm.mp3",
|
||||
"uri": uri
|
||||
})
|
||||
v_num = v_num - 1
|
||||
json = {
|
||||
"sns": sns,
|
||||
"type": "req",
|
||||
"name": "songs_queue_append",
|
||||
"params": {
|
||||
"tid": ranstr(6),
|
||||
"vol": 100,
|
||||
"urls": urls
|
||||
}
|
||||
}
|
||||
self.request(**spapis['send_to_device'], json=json)
|
||||
return
|
||||
|
||||
def _get_response_ms(self):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue