123 lines
3.0 KiB
Python
123 lines
3.0 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
快速测试脚本
|
|
用于验证多进程录音系统的基础功能
|
|
"""
|
|
|
|
import time
|
|
import multiprocessing as mp
|
|
from audio_processes import InputProcess, OutputProcess
|
|
|
|
def test_audio_processes():
|
|
"""测试音频进程类"""
|
|
print("🧪 测试音频进程类...")
|
|
|
|
# 创建测试队列
|
|
command_queue = mp.Queue()
|
|
event_queue = mp.Queue()
|
|
audio_queue = mp.Queue()
|
|
|
|
# 创建进程配置
|
|
config = {
|
|
'zcr_min': 3000,
|
|
'zcr_max': 10000,
|
|
'min_recording_time': 3.0,
|
|
'max_recording_time': 10.0, # 缩短测试时间
|
|
'silence_threshold': 3.0,
|
|
'pre_record_duration': 2.0,
|
|
'voice_activation_threshold': 5, # 降低阈值便于测试
|
|
'calibration_samples': 50, # 减少校准时间
|
|
'adaptive_threshold': True
|
|
}
|
|
|
|
# 创建输入进程
|
|
input_process = InputProcess(command_queue, event_queue, config)
|
|
|
|
# 创建输出进程
|
|
output_process = OutputProcess(audio_queue)
|
|
|
|
print("✅ 音频进程类创建成功")
|
|
|
|
# 测试配置加载
|
|
print("📋 测试配置:")
|
|
print(f" ZCR范围: {config['zcr_min']} - {config['zcr_max']}")
|
|
print(f" 校准样本数: {config['calibration_samples']}")
|
|
print(f" 语音激活阈值: {config['voice_activation_threshold']}")
|
|
|
|
return True
|
|
|
|
def test_dependencies():
|
|
"""测试依赖库"""
|
|
print("🔍 检查依赖库...")
|
|
|
|
dependencies = {
|
|
'numpy': False,
|
|
'pyaudio': False,
|
|
'requests': False,
|
|
'websockets': False
|
|
}
|
|
|
|
try:
|
|
import numpy
|
|
dependencies['numpy'] = True
|
|
print("✅ numpy")
|
|
except ImportError:
|
|
print("❌ numpy")
|
|
|
|
try:
|
|
import pyaudio
|
|
dependencies['pyaudio'] = True
|
|
print("✅ pyaudio")
|
|
except ImportError:
|
|
print("❌ pyaudio")
|
|
|
|
try:
|
|
import requests
|
|
dependencies['requests'] = True
|
|
print("✅ requests")
|
|
except ImportError:
|
|
print("❌ requests")
|
|
|
|
try:
|
|
import websockets
|
|
dependencies['websockets'] = True
|
|
print("✅ websockets")
|
|
except ImportError:
|
|
print("❌ websockets")
|
|
|
|
missing = [dep for dep, installed in dependencies.items() if not installed]
|
|
if missing:
|
|
print(f"❌ 缺少依赖: {', '.join(missing)}")
|
|
return False
|
|
else:
|
|
print("✅ 所有依赖都已安装")
|
|
return True
|
|
|
|
def main():
|
|
"""主测试函数"""
|
|
print("🚀 多进程录音系统快速测试")
|
|
print("=" * 50)
|
|
|
|
# 测试依赖
|
|
if not test_dependencies():
|
|
print("❌ 依赖检查失败")
|
|
return False
|
|
|
|
print()
|
|
|
|
# 测试音频进程
|
|
if not test_audio_processes():
|
|
print("❌ 音频进程测试失败")
|
|
return False
|
|
|
|
print()
|
|
print("✅ 所有测试通过!")
|
|
print("💡 现在可以运行主程序:")
|
|
print(" python multiprocess_recorder.py")
|
|
|
|
return True
|
|
|
|
if __name__ == "__main__":
|
|
main() |