==================================== Whisper 服务连接诊断结果 诊断时间: 2025-12-11 18:53 ==================================== 【诊断结果】 ❌ Whisper 服务未正常运行 【详细检测】 1. 端口检测: ❌ 失败 - 端口 5001 未被监听 - 无进程占用该端口 2. Python 进程: ❌ 未找到 - 系统中没有运行的 Python 进程 - Whisper 服务可能未启动 3. 连接测试: ❌ 失败 - TCP 连接到 localhost:5001 失败 - 连接被拒绝(端口未开放) 【问题根源】 Whisper Python 服务没有启动! 【解决方案】 方案1:启动 Whisper 服务(推荐) --------------------------------------- 1. 找到 Whisper 服务目录 例如: D:\whisper-service\ 或 /opt/whisper-service/ 2. 进入目录并启动 Windows: cd D:\whisper-service python app.py Linux: cd /opt/whisper-service python3 app.py 3. 确认启动成功 - 看到日志: "Running on http://0.0.0.0:5001" - 或访问: http://localhost:5001/health 4. 重新测试连接 运行: powershell -File test_whisper_connection.ps1 或访问: http://localhost:8080/test/whisper/check 方案2:如果没有 Whisper 服务代码 --------------------------------------- 需要先部署 Whisper 服务。创建简单的 Flask 服务: 1. 安装依赖 pip install flask openai-whisper 2. 创建 app.py 参考下面的"Whisper 服务示例代码" 3. 启动服务 python app.py 方案3:修改 Java 配置使用百度 API(临时方案) --------------------------------------- 如果暂时无法启动 Whisper,可以降级使用百度 API: 1. 在 application.yml 中配置百度 API 密钥 2. 重启 Java 应用 3. 系统会自动降级使用百度语音识别 【Whisper 服务示例代码】 --------------------------------------- 创建文件: whisper-service/app.py ```python from flask import Flask, request, jsonify import whisper import os app = Flask(__name__) # 加载 Whisper 模型(首次运行会下载,需要网络) print("正在加载 Whisper 模型...") model = whisper.load_model("base") # 可选: tiny, base, small, medium, large print("✅ Whisper 模型加载完成") @app.route('/health', methods=['GET']) def health(): return jsonify({"status": "ok"}) @app.route('/recognize', methods=['POST']) def recognize(): try: file = request.files['file'] language = request.form.get('language', 'zh') # 保存临时文件 temp_path = f"/tmp/{file.filename}" file.save(temp_path) # 识别 result = model.transcribe(temp_path, language=language) text = result['text'] # 删除临时文件 os.remove(temp_path) return jsonify({ "code": 200, "msg": "识别成功", "data": {"text": text} }) except Exception as e: return jsonify({ "code": 500, "msg": str(e) }), 500 @app.route('/evaluate', methods=['POST']) def evaluate(): try: file = request.files['file'] standard_text = request.form.get('text', '') # 保存临时文件 temp_path = f"/tmp/{file.filename}" file.save(temp_path) # 识别 result = model.transcribe(temp_path, language='zh') recognized_text = result['text'] # 删除临时文件 os.remove(temp_path) # 简单评分(基于相似度) similarity = calculate_similarity(recognized_text, standard_text) score = int(similarity * 100) return jsonify({ "code": 200, "msg": "评测成功", "data": { "text": recognized_text, "score": score, "accuracy": score, "fluency": score, "completeness": score, "pronunciation": score } }) except Exception as e: return jsonify({ "code": 500, "msg": str(e) }), 500 def calculate_similarity(text1, text2): # 简单的相似度计算 text1 = text1.replace(' ', '') text2 = text2.replace(' ', '') if len(text2) == 0: return 0 matched = sum(1 for c in text1 if c in text2) return matched / len(text2) if __name__ == '__main__': print("🚀 启动 Whisper 服务...") print("📍 监听地址: http://0.0.0.0:5001") print("✅ 服务就绪,等待请求...") app.run(host='0.0.0.0', port=5001, debug=False) ``` 启动命令: cd whisper-service python app.py 【后续步骤】 1. 启动 Whisper 服务后,运行测试: powershell -File test_whisper_connection.ps1 2. 确认连接成功后,重启 Java 应用 3. 使用测试接口验证: 访问: http://localhost:8080/test/whisper/check 4. 在 APP 中测试语音识别功能 【需要帮助?】 请提供以下信息: 1. Whisper 服务是否已部署?在哪个目录? 2. 是否有 Python 环境?版本是多少? 3. 服务器操作系统?Windows 还是 Linux? 4. 是否希望使用百度 API 替代方案? ====================================