130 lines
5.8 KiB
PowerShell
130 lines
5.8 KiB
PowerShell
# Whisper 语音识别完整测试脚本
|
||
# 运行: powershell -ExecutionPolicy Bypass -File 测试语音识别.ps1
|
||
|
||
Write-Host "========================================" -ForegroundColor Cyan
|
||
Write-Host " Whisper 语音识别完整测试" -ForegroundColor Cyan
|
||
Write-Host "========================================" -ForegroundColor Cyan
|
||
Write-Host ""
|
||
|
||
# 测试1:检查 Whisper 服务
|
||
Write-Host "[测试 1/4] 检查 Whisper 服务状态..." -ForegroundColor Yellow
|
||
$whisperPort = Get-NetTCPConnection -LocalPort 5001 -ErrorAction SilentlyContinue
|
||
if ($whisperPort) {
|
||
Write-Host "✓ Whisper 服务正在运行" -ForegroundColor Green
|
||
Write-Host " 进程ID: $($whisperPort.OwningProcess)" -ForegroundColor Gray
|
||
} else {
|
||
Write-Host "× Whisper 服务未运行" -ForegroundColor Red
|
||
Write-Host ""
|
||
Write-Host "请先启动 Whisper 服务!" -ForegroundColor Yellow
|
||
Write-Host "查看启动说明: Whisper服务启动说明.txt" -ForegroundColor Gray
|
||
exit
|
||
}
|
||
Write-Host ""
|
||
|
||
# 测试2:健康检查
|
||
Write-Host "[测试 2/4] 测试健康检查接口..." -ForegroundColor Yellow
|
||
try {
|
||
$healthResponse = Invoke-RestMethod -Uri "http://localhost:5001/health" -Method Get -TimeoutSec 5
|
||
if ($healthResponse.status -eq "ok") {
|
||
Write-Host "✓ 健康检查通过" -ForegroundColor Green
|
||
Write-Host " 响应: $($healthResponse | ConvertTo-Json -Compress)" -ForegroundColor Gray
|
||
}
|
||
} catch {
|
||
Write-Host "× 健康检查失败: $($_.Exception.Message)" -ForegroundColor Red
|
||
exit
|
||
}
|
||
Write-Host ""
|
||
|
||
# 测试3:检查 Java 应用
|
||
Write-Host "[测试 3/4] 检查 Java 应用连接..." -ForegroundColor Yellow
|
||
try {
|
||
$javaResponse = Invoke-RestMethod -Uri "http://localhost:8080/test/whisper/check" -Method Get -TimeoutSec 5
|
||
if ($javaResponse.code -eq 200) {
|
||
Write-Host "✓ Java 应用连接成功" -ForegroundColor Green
|
||
Write-Host " 状态: $($javaResponse.data.status)" -ForegroundColor Gray
|
||
Write-Host " 可用: $($javaResponse.data.available)" -ForegroundColor Gray
|
||
} else {
|
||
Write-Host "⚠ Java 应用响应异常" -ForegroundColor Yellow
|
||
Write-Host " 响应: $($javaResponse | ConvertTo-Json)" -ForegroundColor Gray
|
||
}
|
||
} catch {
|
||
Write-Host "× Java 应用未启动或无法访问" -ForegroundColor Red
|
||
Write-Host " 错误: $($_.Exception.Message)" -ForegroundColor Gray
|
||
Write-Host ""
|
||
Write-Host "提示:请确保 Java 应用已启动在端口 8080" -ForegroundColor Yellow
|
||
}
|
||
Write-Host ""
|
||
|
||
# 测试4:测试识别接口(需要音频文件)
|
||
Write-Host "[测试 4/4] 测试语音识别接口..." -ForegroundColor Yellow
|
||
$testAudioFiles = @(
|
||
"C:\Users\Administrator\Desktop\Project\ry_study\test.mp3",
|
||
"D:\test.mp3",
|
||
"test.mp3"
|
||
)
|
||
|
||
$audioFile = $null
|
||
foreach ($file in $testAudioFiles) {
|
||
if (Test-Path $file) {
|
||
$audioFile = $file
|
||
break
|
||
}
|
||
}
|
||
|
||
if ($audioFile) {
|
||
Write-Host "找到测试音频: $audioFile" -ForegroundColor Gray
|
||
Write-Host "正在测试识别..." -ForegroundColor Gray
|
||
|
||
try {
|
||
# 使用 curl 上传文件(PowerShell 的 Invoke-RestMethod 对 multipart/form-data 支持不好)
|
||
$curlPath = (Get-Command curl.exe -ErrorAction SilentlyContinue).Source
|
||
if ($curlPath) {
|
||
$result = & curl.exe -s -X POST http://localhost:5001/recognize `
|
||
-F "file=@$audioFile" `
|
||
-F "language=zh"
|
||
|
||
$jsonResult = $result | ConvertFrom-Json
|
||
if ($jsonResult.code -eq 200) {
|
||
Write-Host "✓ 识别测试成功" -ForegroundColor Green
|
||
Write-Host " 识别结果: $($jsonResult.data.text)" -ForegroundColor Gray
|
||
} else {
|
||
Write-Host "⚠ 识别失败: $($jsonResult.msg)" -ForegroundColor Yellow
|
||
}
|
||
} else {
|
||
Write-Host "⚠ curl 命令不可用,跳过识别测试" -ForegroundColor Yellow
|
||
}
|
||
} catch {
|
||
Write-Host "× 识别测试失败: $($_.Exception.Message)" -ForegroundColor Red
|
||
}
|
||
} else {
|
||
Write-Host "⚠ 未找到测试音频文件,跳过识别测试" -ForegroundColor Yellow
|
||
Write-Host " 提示:可以在项目目录下放置 test.mp3 文件进行测试" -ForegroundColor Gray
|
||
}
|
||
Write-Host ""
|
||
|
||
# 测试总结
|
||
Write-Host "========================================" -ForegroundColor Cyan
|
||
Write-Host " 测试总结" -ForegroundColor Cyan
|
||
Write-Host "========================================" -ForegroundColor Cyan
|
||
Write-Host ""
|
||
Write-Host "Whisper 服务状态:" -ForegroundColor White
|
||
Write-Host " 服务地址: http://localhost:5001" -ForegroundColor Gray
|
||
Write-Host " 健康检查: http://localhost:5001/health" -ForegroundColor Gray
|
||
Write-Host " 识别接口: http://localhost:5001/recognize" -ForegroundColor Gray
|
||
Write-Host " 评测接口: http://localhost:5001/evaluate" -ForegroundColor Gray
|
||
Write-Host ""
|
||
Write-Host "Java 测试接口:" -ForegroundColor White
|
||
Write-Host " 状态检查: http://localhost:8080/test/whisper/check" -ForegroundColor Gray
|
||
Write-Host " 详细信息: http://localhost:8080/test/whisper/info" -ForegroundColor Gray
|
||
Write-Host " 识别测试: POST http://localhost:8080/test/whisper/recognize" -ForegroundColor Gray
|
||
Write-Host " 评测测试: POST http://localhost:8080/test/whisper/evaluate" -ForegroundColor Gray
|
||
Write-Host ""
|
||
Write-Host "【下一步】完整的语音测评测试:" -ForegroundColor Yellow
|
||
Write-Host "1. 在浏览器访问: http://localhost:8080/test/whisper/check" -ForegroundColor White
|
||
Write-Host "2. 使用 Postman 或 curl 上传音频文件测试识别" -ForegroundColor White
|
||
Write-Host "3. 在 APP 端进行完整的语音测评流程" -ForegroundColor White
|
||
Write-Host ""
|
||
Write-Host "【使用 curl 测试示例】" -ForegroundColor Yellow
|
||
Write-Host 'curl -X POST http://localhost:8080/test/whisper/recognize -F "file=@test.mp3"' -ForegroundColor Gray
|
||
Write-Host ""
|