Local-Voice/test_all_audio_received.py
2025-09-22 02:06:00 +08:00

65 lines
2.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
测试 all_audio_received 修改后的逻辑
"""
import sys
import os
sys.path.append(os.path.dirname(__file__))
def test_all_audio_received_logic():
"""测试 all_audio_received 的设置逻辑"""
print("🧪 测试 all_audio_received 修改后的逻辑")
print("=" * 50)
# 模拟播放工作线程的逻辑
class MockAudioProcess:
def __init__(self):
self.currently_playing = False
self.all_audio_received = False
self.last_audio_chunk_time = 0
def simulate_audio_playback(self):
"""模拟音频播放过程"""
print("🔊 模拟音频播放开始...")
# 模拟第875行的逻辑
if not self.currently_playing:
self.currently_playing = True
import time
self.last_audio_chunk_time = time.time()
# 新增只要有音频播放就设置all_audio_received为True
if not self.all_audio_received:
self.all_audio_received = True
print(f"🎵 音频开始播放设置all_audio_received=True")
print(f"🎵 播放状态变化: currently_playing = True (开始播放)")
print(f"🎵 设置last_audio_chunk_time = {self.last_audio_chunk_time}")
# 测试1正常播放场景
print("\n📋 测试1正常播放场景")
mock1 = MockAudioProcess()
print(f"初始状态: currently_playing={mock1.currently_playing}, all_audio_received={mock1.all_audio_received}")
mock1.simulate_audio_playback()
print(f"播放后状态: currently_playing={mock1.currently_playing}, all_audio_received={mock1.all_audio_received}")
# 测试2重复播放场景不应该重复设置
print("\n📋 测试2重复播放场景")
mock2 = MockAudioProcess()
mock2.all_audio_received = True # 已经设置为True
print(f"初始状态: currently_playing={mock2.currently_playing}, all_audio_received={mock2.all_audio_received}")
mock2.simulate_audio_playback()
print(f"播放后状态: currently_playing={mock2.currently_playing}, all_audio_received={mock2.all_audio_received}")
print("\n✅ 所有测试完成")
print("\n📊 修改总结:")
print(" • 在播放工作线程中添加了 all_audio_received = True 的设置")
print(" • 移除了对 end_signal_received 的依赖")
print(" • 保留了原有逻辑作为备用机制")
print(" • 确保只要有音频播放就会设置 all_audio_received = True")
if __name__ == "__main__":
test_all_audio_received_logic()