| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- """
- 简单商品介绍模块
- """
- from logger import logger
- class KnowledgeIntro:
- """
- 简单商品介绍模块
- """
-
- def __init__(self):
- self.intro_content = self._setup_intro_content()
-
- def _setup_intro_content(self) -> dict:
- """设置商品介绍内容"""
- return {
- "voice_content": "欢迎使用本地生活App!我们提供美食外卖、休闲娱乐、生活服务和附近团购,随时为您推荐最合适的本地服务!",
- "short_voice_content": "欢迎使用本地生活App!我们提供便民服务,随时为您推荐最合适的服务!"
- }
-
- def get_voice_content(self, short_version: bool = False) -> str:
- """获取语音内容"""
- if short_version:
- return self.intro_content["short_voice_content"]
- return self.intro_content["voice_content"]
-
- def trigger_auto_play(self, session_id: int, use_short: bool = False, during_intro: bool = False):
- """
- 触发自动播放商品介绍
- """
- voice_content = self.get_voice_content(use_short)
-
- logger.info(f"触发商品自动播报 - 会话ID: {session_id}")
-
- # 返回播放所需的JSON数据
- return {
- "text": voice_content,
- "type": "echo",
- "interrupt": True,
- "during_intro": during_intro,
- "sessionid": session_id
- }
- # 全局实例
- knowledge_intro = KnowledgeIntro()
- # 便捷函数
- def trigger_knowledge_auto_play(session_id: int, use_short: bool = False):
- """便捷函数:触发商品自动播放"""
- return knowledge_intro.trigger_auto_play(session_id, use_short)
|