mirror of
https://gitee.com/quecpython/helios-service.git
synced 2025-05-19 06:08:22 +08:00
43 lines
1.6 KiB
Python
43 lines
1.6 KiB
Python
from usr.bin.guard import GuardContext
|
|
|
|
# 刷新容器
|
|
guard_context = GuardContext()
|
|
guard_context.refresh()
|
|
|
|
|
|
def func(*args, **kwargs):
|
|
"""
|
|
|
|
:param args: ('anonymous',) 发送人, 默认是'anonymous'无需关心
|
|
:param kwargs: 格式如下
|
|
{
|
|
'message':{
|
|
'message_id':2, # 消息ID
|
|
'sender':'anonymous', # 发送人
|
|
'message': { # 来的消息
|
|
'play_data': 'tts', # 播放音频或者tts消息
|
|
'breakin': 0, # 是否允许被打断
|
|
'mode': 2, # 只有tts存在字段, audio不存在此字段, 模式
|
|
'priority': 4 # 优先级4>3>2>1>0
|
|
},
|
|
'from_event':'MEDIA', # 从那个事件或服务来的
|
|
'msg_type':1 # 消息类型, 1是来自tts的消息, 0是来自audio的消息
|
|
}
|
|
}
|
|
:return:
|
|
"""
|
|
print(kwargs['message'])
|
|
|
|
|
|
# 获取媒体服务
|
|
media_ser = guard_context.get_server("media")
|
|
# 订阅媒体服务
|
|
media_ser.subscribe(func)
|
|
# 设置模式
|
|
media_ser.set_mode(0)
|
|
# 设置是否自动播报, 默认是True, 如果为False, 采用订阅手动播报, 一旦设置, audio_play和tts_play将不再生效, 用户可以从订阅消息通拿到并自动播报
|
|
media_ser.enable = True
|
|
# publish消息
|
|
media_ser.audio_play(play_data="usr/a.mp3")
|
|
media_ser.tts_play(play_data="这是一条tts消息")
|