| | |
| | | TAG = __name__ |
| | | |
| | | |
| | | async def report(conn: "ConnectionHandler", chat_type, text, audio_data, report_time): |
| | | async def report(conn: "ConnectionHandler", chat_type, text, audio_data, report_time, |
| | | task_instance_id=None, step_index=None): |
| | | """执行聊天记录上报操作 |
| | | |
| | | Args: |
| | |
| | | wav_data = None |
| | | else: |
| | | wav_data = None |
| | | if wav_data and chat_type == 2: |
| | | try: |
| | | from core.audio_archive import archive_wav |
| | | |
| | | archive_wav(conn, wav_data, kind="tts") |
| | | except Exception: |
| | | pass |
| | | # 执行异步上报 |
| | | await manage_report( |
| | | mac_address=conn.device_id, |
| | |
| | | content=text, |
| | | audio=wav_data, |
| | | report_time=report_time, |
| | | task_instance_id=task_instance_id, |
| | | step_index=step_index, |
| | | ) |
| | | except Exception as e: |
| | | conn.logger.bind(tag=TAG).error(f"聊天记录上报失败: {e}") |
| | |
| | | conn.logger.bind(tag=TAG).error(f"加入工具上报队列失败: {e}") |
| | | |
| | | |
| | | def enqueue_asr_report(conn: "ConnectionHandler", text, opus_data): |
| | | def enqueue_asr_report(conn: "ConnectionHandler", text, opus_data, task_instance_id=None, step_index=None): |
| | | """将ASR数据加入上报队列 |
| | | |
| | | Args: |
| | |
| | | try: |
| | | # 使用连接对象的队列,传入文本和二进制数据而非文件路径 |
| | | if conn.chat_history_conf == 2: |
| | | conn.report_queue.put((1, text, opus_data, int(time.time() * 1000))) |
| | | conn.report_queue.put((1, text, opus_data, int(time.time() * 1000), task_instance_id, step_index)) |
| | | conn.logger.bind(tag=TAG).debug( |
| | | f"ASR数据已加入上报队列: {conn.device_id}, 音频大小: {len(opus_data)} " |
| | | ) |
| | | else: |
| | | conn.report_queue.put((1, text, None, int(time.time() * 1000))) |
| | | conn.report_queue.put((1, text, None, int(time.time() * 1000), task_instance_id, step_index)) |
| | | conn.logger.bind(tag=TAG).debug( |
| | | f"ASR数据已加入上报队列: {conn.device_id}, 不上报音频" |
| | | ) |