113 lines
3.5 KiB
Python
113 lines
3.5 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
|
||
"""
|
||
豆包音频处理模块 - 验证脚本
|
||
验证完整的音频处理流程
|
||
"""
|
||
|
||
import asyncio
|
||
import subprocess
|
||
import os
|
||
from doubao_simple import DoubaoClient
|
||
|
||
async def test_complete_workflow():
|
||
"""测试完整的工作流程"""
|
||
print("=== 豆包音频处理模块验证 ===")
|
||
|
||
# 检查输入文件
|
||
input_file = "recording_20250920_135137.wav"
|
||
if not os.path.exists(input_file):
|
||
print(f"❌ 输入文件不存在: {input_file}")
|
||
return False
|
||
|
||
print(f"✅ 输入文件存在: {input_file}")
|
||
|
||
# 检查文件信息
|
||
try:
|
||
result = subprocess.run(['file', input_file], capture_output=True, text=True)
|
||
print(f"📁 输入文件格式: {result.stdout.strip()}")
|
||
except:
|
||
pass
|
||
|
||
# 初始化客户端
|
||
client = DoubaoClient()
|
||
|
||
try:
|
||
# 连接服务器
|
||
print("🔌 连接豆包服务器...")
|
||
await client.connect()
|
||
print("✅ 连接成功")
|
||
|
||
# 处理音频文件
|
||
output_file = "tts_output.wav"
|
||
print(f"🎵 处理音频文件: {input_file} -> {output_file}")
|
||
|
||
success = await client.process_audio_file(input_file, output_file)
|
||
|
||
if success:
|
||
print("✅ 音频处理成功!")
|
||
|
||
# 检查输出文件
|
||
if os.path.exists(output_file):
|
||
result = subprocess.run(['file', output_file], capture_output=True, text=True)
|
||
print(f"📁 输出文件格式: {result.stdout.strip()}")
|
||
|
||
# 获取文件大小
|
||
file_size = os.path.getsize(output_file)
|
||
print(f"📊 输出文件大小: {file_size:,} 字节")
|
||
|
||
# 测试播放
|
||
print("🔊 测试播放输出文件...")
|
||
try:
|
||
subprocess.run(['aplay', output_file], timeout=10, check=True)
|
||
print("✅ 播放成功")
|
||
except subprocess.TimeoutExpired:
|
||
print("✅ 播放完成(超时是正常的)")
|
||
except subprocess.CalledProcessError as e:
|
||
print(f"⚠️ 播放出现问题: {e}")
|
||
except FileNotFoundError:
|
||
print("⚠️ aplay命令不存在,跳过播放测试")
|
||
|
||
return True
|
||
else:
|
||
print("❌ 输出文件未生成")
|
||
return False
|
||
else:
|
||
print("❌ 音频处理失败")
|
||
return False
|
||
|
||
except Exception as e:
|
||
print(f"❌ 测试失败: {e}")
|
||
import traceback
|
||
traceback.print_exc()
|
||
return False
|
||
finally:
|
||
try:
|
||
await client.close()
|
||
except:
|
||
pass
|
||
|
||
def main():
|
||
"""主函数"""
|
||
print("开始验证豆包音频处理模块...")
|
||
|
||
success = asyncio.run(test_complete_workflow())
|
||
|
||
if success:
|
||
print("\n🎉 验证完成!豆包音频处理模块工作正常。")
|
||
print("\n📋 功能总结:")
|
||
print(" ✅ WebSocket连接建立")
|
||
print(" ✅ 音频文件上传")
|
||
print(" ✅ 语音识别")
|
||
print(" ✅ TTS音频生成")
|
||
print(" ✅ 音频格式转换(Float32 -> Int16)")
|
||
print(" ✅ WAV文件生成")
|
||
print(" ✅ 树莓派兼容播放")
|
||
else:
|
||
print("\n❌ 验证失败,请检查错误信息。")
|
||
|
||
return success
|
||
|
||
if __name__ == "__main__":
|
||
main() |