本地部署AI小智:Opus 音频库没有正确安装

(xz) D:\AIoT\dayb\xiaozhi\main\xiaozhi-server>python app.py
Traceback (most recent call last):
File “D:\AIoT\dayb\xiaozhi\main\xiaozhi-server\app.py”, line 8, in
from core.utils.util import get_local_ip, validate_mcp_endpoint
File “D:\AIoT\dayb\xiaozh1\main\xiaozh1-server\core\utils\util.py”, line 10, in
import opuslib_next
File “D:\exploit\anaconda\az\envs\xz\lib\site-packages\opuslib_next_init_.py”, line 19, in
from .exceptions import OpusError # NOQA
File “D:\exploit\anaconda\az\envs\xz\lib\site-packages\opuslib_next\exceptions.py”, line 10, in
import opuslib_next.api.info
File “D:\exploit\anaconda\az\envs\xz\lib\site-packages\opuslib_next\api_init_.py”, line 44, in
raise Exception(“Could not find Opus library. Make sure it is installed.”)
Exception: Could not find Opus library. Make sure it is installed.

解决:
https://ftp.osuosl.org/pub/xiph/releases/opus/opus-1.5.2.tar.gz
在这里插入图片描述
解压文件,创建“build”文件
在这里插入图片描述
cmd用管理员打开终端输入:cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON
提示cmake为安装,那么就要安装
在这里插入图片描述
https://cmake.org/download/
在这里插入图片描述
下载好后,双击安装:
在这里插入图片描述
再运行:cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON
在这里插入图片描述
再安装:cmake --build . --config Release
在这里插入图片描述
记住这个路径:D:\AIoT/dayb\opus-1.5.2\Release\opus.dll
在这里插入图片描述
修改文件:
根据报错的信息找到文件
我的是这里:D:\exploit\anaconda\az\envs\xz\Lib\site-packages\opuslib_next\api\init.py
在这里插入图片描述
打开“init.py” (可以先备份文件)
在这里插入图片描述
修改成我这样:
#!/usr/bin/env python

“”“OpusLib Package.”“”

import ctypes # type: ignore
import os
import platform
from ctypes.util import find_library # type: ignore

author = “kalicyh kalicyh@qq.com
copyright = “Copyright © 2025, Kalicyh”
license = “BSD 3-Clause License”

custom_dll_path = r"D:\AIoT\dayb\opus-1.5.2\Release\opus.dll" #修改自己的路径

if os.path.exists(custom_dll_path):
lib_location = custom_dll_path
print(f"Using custom Opus library: {custom_dll_path}")
else:
# 如果自定义路径不存在,再尝试系统查找
lib_location = find_library(“opus”)

if lib_location is None:
# find opus library in macOS
if platform.system() == “Darwin”:
lib_paths = [
“/opt/homebrew/lib/libopus.dylib”,
“/usr/local/lib/libopus.dylib”,
]

    for path in lib_paths:
        if os.path.exists(path):
            lib_location = path
            break
# additional paths for Linux
elif platform.system() == "Linux":
    lib_paths = [
        "/usr/lib/x86_64-linux-gnu/libopus.so.0",
        "/usr/local/lib/libopus.so.0",
    ]
    for path in lib_paths:
        if os.path.exists(path):
            lib_location = path
            break
# Windows 特定路径
elif platform.system() == "Windows":
    lib_paths = [
        r"D:\AIoT\dayb\opus-1.5.2\Release\opus.dll",  # 修改自己的路径
        "opus.dll",
        "libopus.dll",
    ]
    for path in lib_paths:
        if os.path.exists(path):
            lib_location = path
            break

if lib_location is None:
raise Exception(“Could not find Opus library. Make sure it is installed.”)

print(f"Loading Opus library from: {lib_location}")
libopus = ctypes.CDLL(lib_location)

c_int_pointer = ctypes.POINTER(ctypes.c_int)
c_int16_pointer = ctypes.POINTER(ctypes.c_int16)
c_float_pointer = ctypes.POINTER(ctypes.c_float)

这样重新启动没有问题:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值