diff --git a/docs/Deployment_all.md b/docs/Deployment_all.md index bad1c4df..c63941dc 100644 --- a/docs/Deployment_all.md +++ b/docs/Deployment_all.md @@ -355,6 +355,9 @@ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/ conda install libopus -y conda install ffmpeg -y + +# 在 Linux 环境下进行部署时,如出现类似缺失 libiconv.so.2 动态库的报错 请通过以下命令进行安装 +conda install libiconv ``` 请注意,以上命令,不是一股脑执行就成功的,你需要一步步执行,每一步执行完后,都检查一下输出的日志,查看是否成功。 diff --git a/main/xiaozhi-server/core/utils/util.py b/main/xiaozhi-server/core/utils/util.py index 27471e58..ea34d3e8 100644 --- a/main/xiaozhi-server/core/utils/util.py +++ b/main/xiaozhi-server/core/utils/util.py @@ -176,31 +176,64 @@ def parse_string_to_list(value, separator=";"): return [] -def check_ffmpeg_installed(): - ffmpeg_installed = False +def check_ffmpeg_installed() -> bool: + """ + 检查当前环境中是否已正确安装并可执行 ffmpeg。 + + Returns: + bool: 如果 ffmpeg 正常可用,返回 True;否则抛出 ValueError 异常。 + + Raises: + ValueError: 当检测到 ffmpeg 未安装或依赖缺失时,抛出详细的提示信息。 + """ try: - # 执行ffmpeg -version命令,并捕获输出 + # 尝试执行 ffmpeg 命令 result = subprocess.run( ["ffmpeg", "-version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, - check=True, # 如果返回码非零则抛出异常 + check=True, # 非零退出码会触发 CalledProcessError ) - # 检查输出中是否包含版本信息(可选) - output = result.stdout + result.stderr - if "ffmpeg version" in output.lower(): - ffmpeg_installed = True - return False - except (subprocess.CalledProcessError, FileNotFoundError): - # 命令执行失败或未找到 - ffmpeg_installed = False - if not ffmpeg_installed: - error_msg = "您的电脑还没正确安装ffmpeg\n" - error_msg += "\n建议您:\n" - error_msg += "1、按照项目的安装文档,正确进入conda环境\n" - error_msg += "2、查阅安装文档,如何在conda环境中安装ffmpeg\n" - raise ValueError(error_msg) + + output = (result.stdout + result.stderr).lower() + if "ffmpeg version" in output: + return True + + # 如果未检测到版本信息,也视为异常情况 + raise ValueError("未检测到有效的 ffmpeg 版本输出。") + + except (subprocess.CalledProcessError, FileNotFoundError) as e: + # 提取错误输出 + stderr_output = "" + if isinstance(e, subprocess.CalledProcessError): + stderr_output = (e.stderr or "").strip() + else: + stderr_output = str(e).strip() + + # 构建基础错误提示 + error_msg = [ + "❌ 检测到 ffmpeg 无法正常运行。\n", + "建议您:", + "1. 确认已正确激活 conda 环境;", + "2. 查阅项目安装文档,了解如何在 conda 环境中安装 ffmpeg。\n", + ] + + # 🎯 针对具体错误信息提供额外提示 + if "libiconv.so.2" in stderr_output: + error_msg.append("⚠️ 发现缺少依赖库:libiconv.so.2") + error_msg.append("解决方法:在当前 conda 环境中执行:") + error_msg.append(" conda install -c conda-forge libiconv\n") + elif "no such file or directory" in stderr_output and "ffmpeg" in stderr_output.lower(): + error_msg.append("⚠️ 系统未找到 ffmpeg 可执行文件。") + error_msg.append("解决方法:在当前 conda 环境中执行:") + error_msg.append(" conda install -c conda-forge ffmpeg\n") + else: + error_msg.append("错误详情:") + error_msg.append(stderr_output or "未知错误。") + + # 抛出详细异常信息 + raise ValueError("\n".join(error_msg)) from e def extract_json_from_string(input_string): diff --git a/main/xiaozhi-server/requirements.txt b/main/xiaozhi-server/requirements.txt old mode 100755 new mode 100644 index 75964ec9..bc9d6956 --- a/main/xiaozhi-server/requirements.txt +++ b/main/xiaozhi-server/requirements.txt @@ -7,25 +7,25 @@ numpy==1.26.4 pydub==0.25.1 funasr==1.2.3 torchaudio==2.2.2 -openai==1.107.0 +openai==2.5.0 google-generativeai==0.8.5 edge_tts==7.0.0 httpx==0.27.2 aiohttp==3.12.15 aiohttp_cors==0.7.0 -ormsgpack==1.7.0 +ormsgpack==1.11.0 ruamel.yaml==0.18.15 loguru==0.7.3 requests==2.32.5 cozepy==0.19.0 -mem0ai==0.1.62 +mem0ai==1.0.0 bs4==0.0.2 modelscope==1.23.2 sherpa_onnx==1.12.11 mcp==1.13.1 cnlunar==0.2.0 PySocks==1.7.1 -dashscope==1.23.1 +dashscope==1.24.6 baidu-aip==4.16.13 chardet==5.2.0 aioconsole==0.8.1 @@ -35,4 +35,4 @@ PyJWT==2.8.0 psutil==7.0.0 portalocker==3.2.0 Jinja2==3.1.6 -vosk==0.3.45 +vosk==0.3.44