guoyu/log/测试远程Whisper.ps1
2025-12-11 23:28:07 +08:00

119 lines
5.4 KiB
PowerShell
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.

# 测试远程 Whisper 服务
# 使用方法:
# 1. 修改下面的 $whisperHost 和 $whisperPort
# 2. 运行powershell -ExecutionPolicy Bypass -File 测试远程Whisper.ps1
# ========== 配置区域 ==========
$whisperHost = "YOUR_SERVER_IP" # 修改为实际的服务器地址
$whisperPort = 5001
# ==============================
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " 测试远程 Whisper 服务" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# 检查配置
if ($whisperHost -eq "YOUR_SERVER_IP") {
Write-Host "[错误] 请先修改脚本中的配置!" -ForegroundColor Red
Write-Host ""
Write-Host "编辑此文件,修改以下变量:" -ForegroundColor Yellow
Write-Host ' $whisperHost = "192.168.1.100" # 你的服务器地址' -ForegroundColor Gray
Write-Host ' $whisperPort = 5001 # Whisper 端口' -ForegroundColor Gray
Write-Host ""
exit 1
}
Write-Host "当前配置:" -ForegroundColor White
Write-Host " 服务器: $whisperHost" -ForegroundColor Gray
Write-Host " 端口: $whisperPort" -ForegroundColor Gray
Write-Host ""
# 测试1网络连接
Write-Host "[测试 1/4] 测试网络连接..." -ForegroundColor Yellow
if (Test-Connection -ComputerName $whisperHost -Count 1 -Quiet) {
Write-Host "✓ 服务器 $whisperHost 可达" -ForegroundColor Green
} else {
Write-Host "× 服务器 $whisperHost 不可达" -ForegroundColor Red
Write-Host ""
Write-Host "请检查:" -ForegroundColor Yellow
Write-Host " 1. 服务器地址是否正确" -ForegroundColor Gray
Write-Host " 2. 网络连接是否正常" -ForegroundColor Gray
Write-Host " 3. 防火墙是否阻止 ICMP" -ForegroundColor Gray
exit 1
}
Write-Host ""
# 测试2端口连接
Write-Host "[测试 2/4] 测试端口连接..." -ForegroundColor Yellow
$portTest = Test-NetConnection -ComputerName $whisperHost -Port $whisperPort -InformationLevel Quiet -WarningAction SilentlyContinue
if ($portTest) {
Write-Host "✓ 端口 $whisperPort 可访问" -ForegroundColor Green
} else {
Write-Host "× 端口 $whisperPort 不可访问" -ForegroundColor Red
Write-Host ""
Write-Host "请检查:" -ForegroundColor Yellow
Write-Host " 1. Whisper 服务是否在远程服务器上运行" -ForegroundColor Gray
Write-Host " 2. 服务器防火墙是否开放端口 $whisperPort" -ForegroundColor Gray
Write-Host " 3. Whisper 配置的监听地址(应为 0.0.0.0 而非 127.0.0.1" -ForegroundColor Gray
exit 1
}
Write-Host ""
# 测试3健康检查
Write-Host "[测试 3/4] 测试 Whisper 健康检查..." -ForegroundColor Yellow
$healthUrl = "http://${whisperHost}:${whisperPort}/health"
try {
$response = Invoke-RestMethod -Uri $healthUrl -Method Get -TimeoutSec 5
if ($response.status -eq "ok") {
Write-Host "✓ 健康检查通过" -ForegroundColor Green
Write-Host " 响应: $($response | ConvertTo-Json -Compress)" -ForegroundColor Gray
} else {
Write-Host "⚠ 健康检查响应异常" -ForegroundColor Yellow
Write-Host " 响应: $($response | ConvertTo-Json)" -ForegroundColor Gray
}
} catch {
Write-Host "× 健康检查失败" -ForegroundColor Red
Write-Host " 错误: $($_.Exception.Message)" -ForegroundColor Gray
exit 1
}
Write-Host ""
# 测试4检查接口可用性
Write-Host "[测试 4/4] 检查 API 接口..." -ForegroundColor Yellow
$recognizeUrl = "http://${whisperHost}:${whisperPort}/recognize"
$evaluateUrl = "http://${whisperHost}:${whisperPort}/evaluate"
Write-Host " 识别接口: $recognizeUrl" -ForegroundColor Gray
Write-Host " 评测接口: $evaluateUrl" -ForegroundColor Gray
Write-Host "✓ 接口地址已确认" -ForegroundColor Green
Write-Host ""
# 测试总结
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " 测试成功!" -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "Whisper 服务信息:" -ForegroundColor White
Write-Host " 地址: http://${whisperHost}:${whisperPort}" -ForegroundColor Gray
Write-Host " 健康检查: ${healthUrl}" -ForegroundColor Gray
Write-Host " 识别接口: ${recognizeUrl}" -ForegroundColor Gray
Write-Host " 评测接口: ${evaluateUrl}" -ForegroundColor Gray
Write-Host ""
Write-Host "【下一步】配置 Java 应用" -ForegroundColor Yellow
Write-Host "1. 编辑文件: ry-study-system\src\main\java\com\ddnai\system\service\voice\LocalWhisperService.java" -ForegroundColor White
Write-Host ""
Write-Host "2. 修改 WHISPER_URL 变量:" -ForegroundColor White
Write-Host " private static final String WHISPER_URL = `"http://${whisperHost}:${whisperPort}`";" -ForegroundColor Gray
Write-Host ""
Write-Host "3. 重新编译并启动 Java 应用:" -ForegroundColor White
Write-Host " mvn clean package" -ForegroundColor Gray
Write-Host " java -jar ry-study-admin/target/ry-study-admin.jar" -ForegroundColor Gray
Write-Host ""
Write-Host "4. 测试 Java 应用连接:" -ForegroundColor White
Write-Host " http://localhost:8080/test/whisper/check" -ForegroundColor Gray
Write-Host ""
Write-Host "【测试语音识别】" -ForegroundColor Yellow
Write-Host "使用 curl 上传音频文件测试:" -ForegroundColor White
Write-Host " curl -X POST ${recognizeUrl} -F `"file=@test.mp3`" -F `"language=zh`"" -ForegroundColor Gray
Write-Host ""