自定义智能处理过程(2)-字符串匹配、机器人API
on_command_stage2
函数
参数:
speech_in
: 语音命令字符串
va_config
: voice_assistant配置内容
'''
缺省配置中,on_command_stage2指向的process_none.py文件中的的on_react函数
'''
def on_react( speech_in, va_config ):
"""获得语音命令文本后的处理函数"""
speech_out = f"你对我说,{speech_in}。但是我还没有想好怎么处理它。"
ha_api.play_tts( speech_out, va_config["tts_service"], va_config["media_player"] )
字符串匹配
-
字符串严格匹配
if speech_in in ["命令A1","命令A2","命令A3","命令A4",...]: 执行动作A elif speech_in in ["命令B1","命令B2","命令B3","命令B4",...]: 执行动作B elif speech_in in ["命令C1","命令C2","命令C3","命令C4",...]: 执行动作C else: 执行动作Z
-
正则表达式
https://github.com/zhujisheng/learn_python/blob/master/02.%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%A4%84%E7%90%86/4.%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%93%8D%E4%BD%9C%E4%B8%8E%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F.md
- 模糊匹配