knowledge_intro.py.backup 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. 简单商品介绍模块
  5. """
  6. from logger import logger
  7. class KnowledgeIntro:
  8. """
  9. 简单商品介绍模块
  10. """
  11. def __init__(self):
  12. self.intro_content = self._setup_intro_content()
  13. def _setup_intro_content(self) -> dict:
  14. """设置商品介绍内容"""
  15. return {
  16. "voice_content": "欢迎使用本地生活App!我们提供美食外卖、休闲娱乐、生活服务和附近团购,随时为您推荐最合适的本地服务!",
  17. "short_voice_content": "欢迎使用本地生活App!我们提供便民服务,随时为您推荐最合适的服务!"
  18. }
  19. def get_voice_content(self, short_version: bool = False) -> str:
  20. """获取语音内容"""
  21. if short_version:
  22. return self.intro_content["short_voice_content"]
  23. return self.intro_content["voice_content"]
  24. def trigger_auto_play(self, session_id: int, use_short: bool = False, during_intro: bool = False):
  25. """
  26. 触发自动播放商品介绍
  27. """
  28. voice_content = self.get_voice_content(use_short)
  29. logger.info(f"触发商品自动播报 - 会话ID: {session_id}")
  30. # 返回播放所需的JSON数据
  31. return {
  32. "text": voice_content,
  33. "type": "echo",
  34. "interrupt": True,
  35. "during_intro": during_intro,
  36. "sessionid": session_id
  37. }
  38. # 全局实例
  39. knowledge_intro = KnowledgeIntro()
  40. # 便捷函数
  41. def trigger_knowledge_auto_play(session_id: int, use_short: bool = False):
  42. """便捷函数:触发商品自动播放"""
  43. return knowledge_intro.trigger_auto_play(session_id, use_short)