qwenasr-qwen36-voxcmp2 base model. -2026/05/14 night
This commit is contained in:
commit
110fe78016
80 files changed
+6057
No files matched your search
@@ -0,0 +1,148 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
语音服务功能测试:ASR 识别 + TTS 合成
|
||||
"""
|
||||
import requests
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
|
||||
HOST = "http://127.0.0.1:8100"
|
||||
|
||||
def test_health():
|
||||
"""1. 健康检查"""
|
||||
print("=" * 50)
|
||||
print("📋 健康检查")
|
||||
print("=" * 50)
|
||||
resp = requests.get(f"{HOST}/health")
|
||||
print(f"状态码: {resp.status_code}")
|
||||
print(f"模型列表: {resp.json()}")
|
||||
assert resp.status_code == 200
|
||||
assert "asr" in resp.json()["models"]
|
||||
assert "tts" in resp.json()["models"]
|
||||
print("✅ 健康检查通过\n")
|
||||
|
||||
def test_asr(audio_path=None):
|
||||
"""2. 测试语音识别"""
|
||||
print("=" * 50)
|
||||
print("🎤 语音识别测试")
|
||||
print("=" * 50)
|
||||
|
||||
if audio_path is None:
|
||||
# 如果没有本地音频,下载一个公开示例
|
||||
import tempfile
|
||||
audio_path = tempfile.mktemp(suffix=".wav")
|
||||
url = "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen3-ASR-Repo/asr_zh.wav"
|
||||
print(f"下载测试音频: {url}")
|
||||
import subprocess
|
||||
subprocess.run(["wget", "-q", url, "-O", audio_path], check=True)
|
||||
|
||||
print(f"音频文件: {audio_path}")
|
||||
with open(audio_path, "rb") as f:
|
||||
resp = requests.post(f"{HOST}/asr", files={"file": f})
|
||||
|
||||
print(f"状态码: {resp.status_code}")
|
||||
result = resp.json()
|
||||
print(f"识别结果: {result.get('text', 'N/A')}")
|
||||
assert resp.status_code == 200
|
||||
assert len(result.get("text", "")) > 0
|
||||
print("✅ 语音识别通过\n")
|
||||
return result["text"]
|
||||
|
||||
def test_tts(text="(激动地说)你好世界,这是一段测试语音", output="test_output.wav"):
|
||||
"""3. 测试语音合成"""
|
||||
print("=" * 50)
|
||||
print("🔊 语音合成测试")
|
||||
print("=" * 50)
|
||||
print(f"合成文本: {text}")
|
||||
|
||||
start_time = time.time()
|
||||
resp = requests.get(f"{HOST}/tts", params={"text": text})
|
||||
elapsed = time.time() - start_time
|
||||
|
||||
print(f"状态码: {resp.status_code}")
|
||||
print(f"耗时: {elapsed:.2f}秒")
|
||||
|
||||
if resp.status_code == 200:
|
||||
with open(output, "wb") as f:
|
||||
f.write(resp.content)
|
||||
file_size = os.path.getsize(output) / 1024 # KB
|
||||
print(f"音频已保存: {output} ({file_size:.1f} KB)")
|
||||
else:
|
||||
print(f"错误: {resp.text}")
|
||||
|
||||
assert resp.status_code == 200
|
||||
assert os.path.exists(output)
|
||||
print("✅ 语音合成通过\n")
|
||||
|
||||
def test_asr_english():
|
||||
"""4. 测试英文识别"""
|
||||
print("=" * 50)
|
||||
print("🌍 英文识别测试")
|
||||
print("=" * 50)
|
||||
|
||||
import tempfile
|
||||
audio_path = tempfile.mktemp(suffix=".wav")
|
||||
url = "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen3-ASR-Repo/asr_en.wav"
|
||||
print(f"下载英文测试音频: {url}")
|
||||
import subprocess
|
||||
subprocess.run(["wget", "-q", url, "-O", audio_path], check=True)
|
||||
|
||||
with open(audio_path, "rb") as f:
|
||||
resp = requests.post(f"{HOST}/asr", files={"file": f})
|
||||
|
||||
print(f"状态码: {resp.status_code}")
|
||||
result = resp.json()
|
||||
print(f"识别结果: {result.get('text', 'N/A')}")
|
||||
assert resp.status_code == 200
|
||||
assert len(result.get("text", "")) > 0
|
||||
print("✅ 英文识别通过\n")
|
||||
|
||||
def test_tts_long_text():
|
||||
"""5. 测试长文本合成"""
|
||||
print("=" * 50)
|
||||
print("📜 长文本合成测试")
|
||||
print("=" * 50)
|
||||
|
||||
long_text = """人工智能是计算机科学的一个分支,它企图了解智能的实质,
|
||||
并生产出一种新的能以人类智能相似的方式做出反应的智能机器,
|
||||
该领域的研究包括机器人、语言识别、图像识别、自然语言处理和专家系统等。"""
|
||||
|
||||
print(f"文本长度: {len(long_text)} 字")
|
||||
start_time = time.time()
|
||||
resp = requests.get(f"{HOST}/tts", params={"text": long_text})
|
||||
elapsed = time.time() - start_time
|
||||
|
||||
print(f"状态码: {resp.status_code}")
|
||||
print(f"耗时: {elapsed:.2f}秒")
|
||||
|
||||
if resp.status_code == 200:
|
||||
output = "test_long_output.wav"
|
||||
with open(output, "wb") as f:
|
||||
f.write(resp.content)
|
||||
file_size = os.path.getsize(output) / 1024
|
||||
print(f"音频已保存: {output} ({file_size:.1f} KB)")
|
||||
|
||||
assert resp.status_code == 200
|
||||
print("✅ 长文本合成通过\n")
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("\n" + "🚀 开始测试语音服务".center(50, "="))
|
||||
print(f"服务地址: {HOST}\n")
|
||||
|
||||
try:
|
||||
test_health()
|
||||
|
||||
# 可选:用自己的音频文件测试
|
||||
# test_asr("/path/to/your/audio.wav")
|
||||
test_asr()
|
||||
test_asr_english()
|
||||
|
||||
test_tts()
|
||||
test_tts_long_text()
|
||||
|
||||
print("\n" + "🎉 所有测试通过!".center(50, "="))
|
||||
except Exception as e:
|
||||
print(f"\n❌ 测试失败: {e}")
|
||||
sys.exit(1)
|
||||
Reference in new issue
Block a user