最近想体验小智AI使用python实现需要用到opus的开源库。网址:Opus Codec
运行报错!在这里记录一下解决过程过程
安装python库
1 | pip3 install opuslib |
验证安装
1 | >> import opuslib |
报错了,应该是没有对应的dll文件,没有opus的库那就自己编译一个吧。
下载源码文件
https://downloads.xiph.org/releases/opus/opus-1.5.2.tar.gz
解压(使用解压工具解压即可,下列命令仅做表示)
1 | tar zxvf opus-1.5.2.tar.gz |
进入源码文件,新建build文件夹
1 | cd opus-1.5.2 |
预编译
前提是已经安装了cmake,没有安装的同学也不用着急,很简单,下载cmake压缩包,解压,将bin目录添加到环境变量,就OK了
1 | cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON |
编译
1 | cmake --build . --config Release |
编译完是这样的1
2
3
4
5
6
7
8
9
10
11
12
13
14
15G:\Users\IOTTS\Desktop\opus-1.5.2>cmake --build . --config Release
适用于 .NET Framework MSBuild 版本 17.13.19+0d9f5a35a
1>Checking Build System
Building Custom Rule G:/Users/IOTTS/Desktop/opus-1.5.2/CMakeLists.txt
opus.c
opus_decoder.c
...
pitch_avx.c
NSQ_del_dec_avx2.c
inner_product_FLP_avx2.c
正在生成代码...
正在创建库 G:/Users/IOTTS/Desktop/opus-1.5.2/Release/opus.lib 和对象 G:/Users/IOTTS/Desktop/opus-1.5.2/Release/opus.exp
opus.vcxproj -> G:\Users\IOTTS\Desktop\opus-1.5.2\Release\opus.dll
Building Custom Rule G:/Users/IOTTS/Desktop/opus-1.5.2/CMakeLists.txt
安装
这一步非必要,我们只用到了上一步生成opus.dll1
cmake --install .
最后需要修改一下opus库的init.py文件。具体的路劲会在报错处表现。一般库文件编译安装的路径为:C:\Program Files (x86)\Opus\bin\opus.dll,如果没有安装的话直接按照编译完的路径替换到程序中就可以了,比如我的是G:\Users\IOTTS\Desktop\opus-1.5.2\Release\opus.dll,替换路径时注意’\’要替换成’\\’,再次运行无报错出现