RvcPyInfer 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. rvcpyinfer-0.1.0/.github/workflows/release.yml +59 -0
  2. rvcpyinfer-0.1.0/.gitignore +20 -0
  3. rvcpyinfer-0.1.0/.python-version +1 -0
  4. rvcpyinfer-0.1.0/PKG-INFO +158 -0
  5. rvcpyinfer-0.1.0/README.md +130 -0
  6. rvcpyinfer-0.1.0/license +7 -0
  7. rvcpyinfer-0.1.0/pyproject.toml +126 -0
  8. rvcpyinfer-0.1.0/src/RvcPyInfer/InferProviders.py +108 -0
  9. rvcpyinfer-0.1.0/src/RvcPyInfer/InferTask.py +210 -0
  10. rvcpyinfer-0.1.0/src/RvcPyInfer/RvcContext.py +125 -0
  11. rvcpyinfer-0.1.0/src/RvcPyInfer/__init__.py +42 -0
  12. rvcpyinfer-0.1.0/src/RvcPyInfer/__main__.py +4 -0
  13. rvcpyinfer-0.1.0/src/RvcPyInfer/_version.py +1 -0
  14. rvcpyinfer-0.1.0/src/RvcPyInfer/audio/audio_utils.py +346 -0
  15. rvcpyinfer-0.1.0/src/RvcPyInfer/cli.py +112 -0
  16. rvcpyinfer-0.1.0/src/RvcPyInfer/error/InferEnvError.py +2 -0
  17. rvcpyinfer-0.1.0/src/RvcPyInfer/error/NotSupportedAlgorithmError.py +2 -0
  18. rvcpyinfer-0.1.0/src/RvcPyInfer/f0_utils.py +125 -0
  19. rvcpyinfer-0.1.0/src/RvcPyInfer/index/RvcFeatIndex.py +19 -0
  20. rvcpyinfer-0.1.0/src/RvcPyInfer/infer_env.py +28 -0
  21. rvcpyinfer-0.1.0/src/RvcPyInfer/onnx/ContentVec.py +38 -0
  22. rvcpyinfer-0.1.0/src/RvcPyInfer/onnx/ModelSimplePool.py +26 -0
  23. rvcpyinfer-0.1.0/src/RvcPyInfer/onnx/RvcGen.py +51 -0
  24. rvcpyinfer-0.1.0/src/RvcPyInfer/onnx/export/Exporter.py +130 -0
  25. rvcpyinfer-0.1.0/src/RvcPyInfer/onnx/export/cli.py +104 -0
  26. rvcpyinfer-0.1.0/src/RvcPyInfer/onnx/export/direct_read_sr.py +109 -0
  27. rvcpyinfer-0.1.0/src/RvcPyInfer/onnx/model_loader.py +41 -0
  28. rvcpyinfer-0.1.0/src/RvcPyInfer/ov/OVCoreSingleton.py +3 -0
  29. rvcpyinfer-0.1.0/src/RvcPyInfer/path_utils.py +10 -0
  30. rvcpyinfer-0.1.0/src/RvcPyInfer/resource/template/export_onnx.py +249 -0
  31. rvcpyinfer-0.1.0/src/RvcPyInfer/type_alist.py +13 -0
  32. rvcpyinfer-0.1.0/src/RvcPyInfer/warn/InferEnvWarn.py +5 -0
  33. rvcpyinfer-0.1.0/src/RvcPyInfer/warn/InferModelWarn.py +5 -0
  34. rvcpyinfer-0.1.0/src/RvcPyInfer/warn/InferWarn.py +2 -0
  35. rvcpyinfer-0.1.0/uv.lock +465 -0
@@ -0,0 +1,59 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v*.*.*"
7
+
8
+ jobs:
9
+ check:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - name: Checkout code
13
+ uses: actions/checkout@v4
14
+
15
+ - name: Setup uv
16
+ uses: astral-sh/setup-uv@v6
17
+ with:
18
+ enable-cache: true
19
+
20
+ - name: Install dependencies
21
+ run: uv sync --extra dev
22
+
23
+ - name: Run ruff lint
24
+ run: uv run ruff check
25
+
26
+ - name: Run pyright type check
27
+ run: uv run pyright
28
+
29
+ release:
30
+ needs: check
31
+ runs-on: ubuntu-latest
32
+ environment: pypi
33
+ permissions:
34
+ id-token: write
35
+ contents: write
36
+ steps:
37
+ - name: Checkout code
38
+ uses: actions/checkout@v4
39
+
40
+ - name: Setup uv
41
+ uses: astral-sh/setup-uv@v6
42
+ with:
43
+ enable-cache: true
44
+
45
+ - name: Set SOURCE_DATE_EPOCH
46
+ run: echo "SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct)" >>$GITHUB_ENV
47
+
48
+ - name: Build package
49
+ run: uv build
50
+
51
+ - name: Publish to PyPI
52
+ uses: pypa/gh-action-pypi-publish@release/v1
53
+
54
+ - name: Create GitHub Release
55
+ uses: softprops/action-gh-release@v2
56
+ with:
57
+ name: ${{ github.ref_name }}
58
+ generate_release_notes: true
59
+ files: dist/*
@@ -0,0 +1,20 @@
1
+ # Python-generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+
9
+ # ruff
10
+ .ruff_cache/
11
+
12
+ # Virtual environments
13
+ .venv
14
+
15
+ # 模型文件
16
+ models/
17
+
18
+ # 音频
19
+ input/
20
+ output/
@@ -0,0 +1 @@
1
+ 3.13
@@ -0,0 +1,158 @@
1
+ Metadata-Version: 2.4
2
+ Name: RvcPyInfer
3
+ Version: 0.1.0
4
+ Summary: Rvc 的 ONNX 模型导出格式推理实现
5
+ Project-URL: Homepage, https://github.com/TwoCreepers/RvcPyInfer
6
+ Project-URL: Repository, https://github.com/TwoCreepers/RvcPyInfer
7
+ Author: 观赏鱼
8
+ License-Expression: MIT
9
+ Requires-Python: >=3.13
10
+ Requires-Dist: numpy>=2.3
11
+ Requires-Dist: pyworld>=0.3.5
12
+ Requires-Dist: samplerate>=0.2.4
13
+ Requires-Dist: soundfile>=0.14.0
14
+ Provides-Extra: cpu
15
+ Requires-Dist: onnxruntime>=1.27.0; extra == 'cpu'
16
+ Provides-Extra: cuda
17
+ Requires-Dist: onnxruntime-gpu>=1.27.0; extra == 'cuda'
18
+ Provides-Extra: dev
19
+ Requires-Dist: pyright>=1.1.411; extra == 'dev'
20
+ Requires-Dist: ruff>=0.15.21; extra == 'dev'
21
+ Provides-Extra: dml
22
+ Requires-Dist: onnxruntime-directml>=1.24.4; extra == 'dml'
23
+ Provides-Extra: index
24
+ Requires-Dist: faiss-cpu>=1.14.3; extra == 'index'
25
+ Provides-Extra: openvino
26
+ Requires-Dist: openvino>=2026.2.1; extra == 'openvino'
27
+ Description-Content-Type: text/markdown
28
+
29
+ # [RvcPyInfer](https://github.com/TwoCreepers/RvcPyInfer)
30
+
31
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://mit-license.org/)
32
+ [![Python 3.13+](https://img.shields.io/badge/python-3.13+-blue.svg)](https://www.python.org/downloads/)
33
+ ![ONNX](https://img.shields.io/badge/ONNX-supported-blue)
34
+
35
+ [RVC](https://github.com/RVC-Project/Retrieval-based-Voice-Conversion-WebUI) 的 ONNX 模型导出格式推理实现。
36
+
37
+ - 支持原 RVC 项目的 ONNX 模型推理。
38
+ - 跨平台支持多种推理引擎(CPU, CUDA, DirectML, OpenVINO)。
39
+ - 提供 Windows 下一键导出 ONNX 模型的 CLI 工具。
40
+ - 兼容原项目的 `.index` 特征索引文件。
41
+
42
+ ## Python 版本需求
43
+ 本项目要求 Python 版本 `>= 3.13`。由于项目代码中使用了 `Python 3.12+` 引入的 `TypeParam` 等现代语法特性,因此无法向下兼容更低版本的 Python。
44
+ ~~并且推理真的很难测试欸。~~
45
+
46
+ ## 安装
47
+ 本库尚未上传至 [PyPI](https://pypi.org) ,我们还在筹备这方面的工作。
48
+ 你可以直接 clone 该仓库然后使用如下命令构建 `.whl` 文件。
49
+ ```shell
50
+ # 克隆该仓库
51
+ git clone https://github.com/TwoCreepers/RvcPyInfer.git
52
+ # 进入该仓库目录
53
+ cd RvcPyInfer
54
+ # 使用 uv 构建
55
+ uv build
56
+ # 安装生成的 wheel 包 (以实际文件名为准)
57
+ pip install ./dist/rvcpyinfer-0.1.0-py3-none-any.whl
58
+ ```
59
+ 不出意外的话,现在你需要的轮子文件应该出现在 `dist/` 下面了。
60
+ 这里出现的 [`uv`](https://github.com/astral-sh/uv) 是一个使用 `Rust` 编写的 `Python` 项目管理工具。
61
+ 它可以为你剩下非常多在依赖管理方面的麻烦,就比如上面的 `uv build` 它会自动为你生成虚拟环境并安装好依赖。
62
+ 当然了, [`uv`](https://github.com/astral-sh/uv) 不是必须的,我们使用 [`hatchling`](https://pypi.org/project/hatchling) 作为构建后端,你可以自己研究一下如何构建。
63
+
64
+ 或者你也可以直接把当前项目作为库安装,例如:
65
+ ```shell
66
+ # 假设你已经在仓库目录里了
67
+ pip install .
68
+ # 如果需要安装 CPU 引擎和特征索引支持的话是
69
+ pip install ".[cpu,index]"
70
+ ```
71
+
72
+
73
+ ## 关于特征模型
74
+ 你可以在[这里](https://huggingface.co/NaruseMioShirakana/MoeSS-SUBModel/tree/main)找到 `MoeSS` 使用的 `onnx` 特征模型。它们是通用的。
75
+ **通常情况下最常见的 `v2` 版本的生成器模型使用的是 `vec-768-layer-12.onnx`**
76
+
77
+ ## 关于推理引擎
78
+ 你可能已经看到了那个未安装任何推理引擎的警告或者错误。
79
+ 请在安装命令后面添加 `[xxx]` 来安装可选依赖。
80
+ 例如:
81
+ ```shell
82
+ # 假设你已经在 dist/ 目录下构建好了 whl 文件
83
+ pip install "./dist/rvcpyinfer-0.1.0-py3-none-any[cpu]"
84
+ ```
85
+ 目前我们支持以下推理引擎:
86
+
87
+ - `onnxruntime`
88
+ - `[cpu]`:ONNX Runtime (CPU),通用
89
+ - `[cuda]`:ONNX Runtime (CUDA),Nvidia GPU 加速
90
+ - `[dml]`:ONNX Runtime (DML),Windows DirectML 加速
91
+ - `openvino`
92
+ - `[openvino]`:OpenVINO,Intel 硬件加速
93
+
94
+ 请注意 `onnxruntime` 的三个可选依赖是互斥的,你只能选择其中的一个。
95
+ 关于 `openvino` 的 `IR` 格式,本库会转换 `IR` 格式并存档在 `.onnx` 同目录下的同名文件中,以便在下一次加载时加速,该行为目前无法被禁用。
96
+
97
+ ## 关于特征索引
98
+ 原项目的 `.index` 文件可直接使用,无需转换。
99
+ 但你需要使用 `[index]` 来安装我们需要用于读取特征索引的依赖—— `faiss`。
100
+
101
+ ## 快速使用
102
+ 一个简单的示例:
103
+ ```python
104
+ import RvcPyInfer
105
+
106
+ context = RvcPyInfer.RvcContext() # 创建一个上下文
107
+
108
+ task = context.build_task(
109
+ "./你的特征模型.onnx",
110
+ "./你的 Rvc 生成器模型.onnx",
111
+ 48000, # 你的 Rvc 生成器模型的生成采样率
112
+ "./你要推理的源文件.wav", # 可以填多个源文件
113
+ # 后续可选参数需显式写明名称,例如:
114
+ sid=1, # 说话者 id,一般情况下就是 0
115
+ seed=4321 # 噪声种子,默认 1234
116
+ )
117
+ task.run_and_save(
118
+ "./你要保存的结果.wav" # 请注意,它不会自动创建目录
119
+ )
120
+ ```
121
+
122
+ ## CLI
123
+ 我们已经预制了一些 `CLI` 在库中了,并随库一并打包。
124
+ 以下是库内置的命令:
125
+ - `rvc-infer`:用以快速推理模型而无需编写代码
126
+ - `rvc-model`:与原项目模型相关的命令
127
+
128
+ ### rvc-infer
129
+ 最简格式: `rvc-infer --vec-model <你的特征模型路径> --gen-model <你的生成器模型路径> --gen-model-sr <你的生成器模型的输出采样率> -i <输入音频文件路径> -o <输出音频文件路径>`
130
+ **Tips:可出现多个 -i 和 -o,只要它们的数量一致,多个 -i 和 -o 按出现顺序一一对应。**
131
+
132
+ ### rvc-model
133
+ 该命令用于查看原项目的 `.pth` 模型的生成采样率,以及在 `Windows` 上快速导出 onnx 模型。
134
+
135
+ #### rvc-model show-sr
136
+ 格式: `rvc-model show-sr -m <你的pth模型路径>`
137
+
138
+ #### rvc-model export
139
+ **⚠️注意:你必须安装源项目的整合包或至少有一个能运行源项目的环境以便 `PyTorch` 导出 `.onnx` 模型。**
140
+ 它并不依赖项目内置的 `tools/export_onnx.py` 我们有自己的方法。
141
+ ~~事实上原项目的 export_onnx.py 甚至没有做 v2 版本的支持~~
142
+ 格式: `rvc-model export -m <你的pth模型路径> -t <你希望输出到哪> -r <rvc 原项目的根路径> --runtime <可选的导出用的 python 解释器路径,默认使用 rvc 原项目整合包自带的解释器>`
143
+
144
+ ## 未来的计划
145
+ - [ ] Github Action 可重现性构建流水线
146
+ - [ ] 发布至 PyPI
147
+
148
+ ## 许可证
149
+ 在文件头部或文件所在目录未有额外说明的情况下,本项目代码部分使用 [`MIT`](https://mit-license.org/) 许可证授权与你,非代码部分使用 `CC BY 4.0` 授权与你。
150
+
151
+ ## 🎉鸣谢
152
+
153
+ - [原项目组的所有成员](https://github.com/RVC-Project)
154
+ 没有TA们的付出就没有 RVC 模型,该项目也不会出现
155
+ - [提前打好特征模型 ONNX 的 MoeSS](https://github.com/Miuzarte/MoeSS)
156
+ 省去了诸多导出特征模型的麻烦
157
+ - [帮了作者很多的 GLM AI](https://chatglm.cn)
158
+ 省去了很多查资料和写 CLI 的时间
@@ -0,0 +1,130 @@
1
+ # [RvcPyInfer](https://github.com/TwoCreepers/RvcPyInfer)
2
+
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://mit-license.org/)
4
+ [![Python 3.13+](https://img.shields.io/badge/python-3.13+-blue.svg)](https://www.python.org/downloads/)
5
+ ![ONNX](https://img.shields.io/badge/ONNX-supported-blue)
6
+
7
+ [RVC](https://github.com/RVC-Project/Retrieval-based-Voice-Conversion-WebUI) 的 ONNX 模型导出格式推理实现。
8
+
9
+ - 支持原 RVC 项目的 ONNX 模型推理。
10
+ - 跨平台支持多种推理引擎(CPU, CUDA, DirectML, OpenVINO)。
11
+ - 提供 Windows 下一键导出 ONNX 模型的 CLI 工具。
12
+ - 兼容原项目的 `.index` 特征索引文件。
13
+
14
+ ## Python 版本需求
15
+ 本项目要求 Python 版本 `>= 3.13`。由于项目代码中使用了 `Python 3.12+` 引入的 `TypeParam` 等现代语法特性,因此无法向下兼容更低版本的 Python。
16
+ ~~并且推理真的很难测试欸。~~
17
+
18
+ ## 安装
19
+ 本库尚未上传至 [PyPI](https://pypi.org) ,我们还在筹备这方面的工作。
20
+ 你可以直接 clone 该仓库然后使用如下命令构建 `.whl` 文件。
21
+ ```shell
22
+ # 克隆该仓库
23
+ git clone https://github.com/TwoCreepers/RvcPyInfer.git
24
+ # 进入该仓库目录
25
+ cd RvcPyInfer
26
+ # 使用 uv 构建
27
+ uv build
28
+ # 安装生成的 wheel 包 (以实际文件名为准)
29
+ pip install ./dist/rvcpyinfer-0.1.0-py3-none-any.whl
30
+ ```
31
+ 不出意外的话,现在你需要的轮子文件应该出现在 `dist/` 下面了。
32
+ 这里出现的 [`uv`](https://github.com/astral-sh/uv) 是一个使用 `Rust` 编写的 `Python` 项目管理工具。
33
+ 它可以为你剩下非常多在依赖管理方面的麻烦,就比如上面的 `uv build` 它会自动为你生成虚拟环境并安装好依赖。
34
+ 当然了, [`uv`](https://github.com/astral-sh/uv) 不是必须的,我们使用 [`hatchling`](https://pypi.org/project/hatchling) 作为构建后端,你可以自己研究一下如何构建。
35
+
36
+ 或者你也可以直接把当前项目作为库安装,例如:
37
+ ```shell
38
+ # 假设你已经在仓库目录里了
39
+ pip install .
40
+ # 如果需要安装 CPU 引擎和特征索引支持的话是
41
+ pip install ".[cpu,index]"
42
+ ```
43
+
44
+
45
+ ## 关于特征模型
46
+ 你可以在[这里](https://huggingface.co/NaruseMioShirakana/MoeSS-SUBModel/tree/main)找到 `MoeSS` 使用的 `onnx` 特征模型。它们是通用的。
47
+ **通常情况下最常见的 `v2` 版本的生成器模型使用的是 `vec-768-layer-12.onnx`**
48
+
49
+ ## 关于推理引擎
50
+ 你可能已经看到了那个未安装任何推理引擎的警告或者错误。
51
+ 请在安装命令后面添加 `[xxx]` 来安装可选依赖。
52
+ 例如:
53
+ ```shell
54
+ # 假设你已经在 dist/ 目录下构建好了 whl 文件
55
+ pip install "./dist/rvcpyinfer-0.1.0-py3-none-any[cpu]"
56
+ ```
57
+ 目前我们支持以下推理引擎:
58
+
59
+ - `onnxruntime`
60
+ - `[cpu]`:ONNX Runtime (CPU),通用
61
+ - `[cuda]`:ONNX Runtime (CUDA),Nvidia GPU 加速
62
+ - `[dml]`:ONNX Runtime (DML),Windows DirectML 加速
63
+ - `openvino`
64
+ - `[openvino]`:OpenVINO,Intel 硬件加速
65
+
66
+ 请注意 `onnxruntime` 的三个可选依赖是互斥的,你只能选择其中的一个。
67
+ 关于 `openvino` 的 `IR` 格式,本库会转换 `IR` 格式并存档在 `.onnx` 同目录下的同名文件中,以便在下一次加载时加速,该行为目前无法被禁用。
68
+
69
+ ## 关于特征索引
70
+ 原项目的 `.index` 文件可直接使用,无需转换。
71
+ 但你需要使用 `[index]` 来安装我们需要用于读取特征索引的依赖—— `faiss`。
72
+
73
+ ## 快速使用
74
+ 一个简单的示例:
75
+ ```python
76
+ import RvcPyInfer
77
+
78
+ context = RvcPyInfer.RvcContext() # 创建一个上下文
79
+
80
+ task = context.build_task(
81
+ "./你的特征模型.onnx",
82
+ "./你的 Rvc 生成器模型.onnx",
83
+ 48000, # 你的 Rvc 生成器模型的生成采样率
84
+ "./你要推理的源文件.wav", # 可以填多个源文件
85
+ # 后续可选参数需显式写明名称,例如:
86
+ sid=1, # 说话者 id,一般情况下就是 0
87
+ seed=4321 # 噪声种子,默认 1234
88
+ )
89
+ task.run_and_save(
90
+ "./你要保存的结果.wav" # 请注意,它不会自动创建目录
91
+ )
92
+ ```
93
+
94
+ ## CLI
95
+ 我们已经预制了一些 `CLI` 在库中了,并随库一并打包。
96
+ 以下是库内置的命令:
97
+ - `rvc-infer`:用以快速推理模型而无需编写代码
98
+ - `rvc-model`:与原项目模型相关的命令
99
+
100
+ ### rvc-infer
101
+ 最简格式: `rvc-infer --vec-model <你的特征模型路径> --gen-model <你的生成器模型路径> --gen-model-sr <你的生成器模型的输出采样率> -i <输入音频文件路径> -o <输出音频文件路径>`
102
+ **Tips:可出现多个 -i 和 -o,只要它们的数量一致,多个 -i 和 -o 按出现顺序一一对应。**
103
+
104
+ ### rvc-model
105
+ 该命令用于查看原项目的 `.pth` 模型的生成采样率,以及在 `Windows` 上快速导出 onnx 模型。
106
+
107
+ #### rvc-model show-sr
108
+ 格式: `rvc-model show-sr -m <你的pth模型路径>`
109
+
110
+ #### rvc-model export
111
+ **⚠️注意:你必须安装源项目的整合包或至少有一个能运行源项目的环境以便 `PyTorch` 导出 `.onnx` 模型。**
112
+ 它并不依赖项目内置的 `tools/export_onnx.py` 我们有自己的方法。
113
+ ~~事实上原项目的 export_onnx.py 甚至没有做 v2 版本的支持~~
114
+ 格式: `rvc-model export -m <你的pth模型路径> -t <你希望输出到哪> -r <rvc 原项目的根路径> --runtime <可选的导出用的 python 解释器路径,默认使用 rvc 原项目整合包自带的解释器>`
115
+
116
+ ## 未来的计划
117
+ - [ ] Github Action 可重现性构建流水线
118
+ - [ ] 发布至 PyPI
119
+
120
+ ## 许可证
121
+ 在文件头部或文件所在目录未有额外说明的情况下,本项目代码部分使用 [`MIT`](https://mit-license.org/) 许可证授权与你,非代码部分使用 `CC BY 4.0` 授权与你。
122
+
123
+ ## 🎉鸣谢
124
+
125
+ - [原项目组的所有成员](https://github.com/RVC-Project)
126
+ 没有TA们的付出就没有 RVC 模型,该项目也不会出现
127
+ - [提前打好特征模型 ONNX 的 MoeSS](https://github.com/Miuzarte/MoeSS)
128
+ 省去了诸多导出特征模型的麻烦
129
+ - [帮了作者很多的 GLM AI](https://chatglm.cn)
130
+ 省去了很多查资料和写 CLI 的时间
@@ -0,0 +1,7 @@
1
+ Copyright © 2026 TwoCreepers
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,126 @@
1
+ [project]
2
+ name = "RvcPyInfer"
3
+ description = "Rvc 的 ONNX 模型导出格式推理实现"
4
+ readme = "README.md"
5
+ license = "MIT"
6
+ requires-python = ">=3.13"
7
+ dependencies = [
8
+ "numpy>=2.3",
9
+ "pyworld>=0.3.5",
10
+ "samplerate>=0.2.4",
11
+ "soundfile>=0.14.0",
12
+ ]
13
+ authors = [
14
+ { name = "观赏鱼" }
15
+ ]
16
+
17
+ dynamic = ["version"]
18
+
19
+ # 读取版本号
20
+ [tool.hatch.version]
21
+ path = "src/RvcPyInfer/_version.py"
22
+
23
+ classifiers = [
24
+ "Development Status :: 4 - Beta",
25
+ "License :: OSI Approved :: MIT License",
26
+ "Intended Audience :: Developers",
27
+ "Programming Language :: Python :: 3.13",
28
+ ]
29
+ keywords = [
30
+ "rvc",
31
+ "onnx",
32
+ "voice-conversion",
33
+ ]
34
+
35
+ [project.urls]
36
+ Homepage = "https://github.com/TwoCreepers/RvcPyInfer"
37
+ Repository = "https://github.com/TwoCreepers/RvcPyInfer"
38
+
39
+ [project.scripts]
40
+ rvc-model = "RvcPyInfer.onnx.export.cli:main"
41
+ rvc-infer = "RvcPyInfer.__main__:infer_main"
42
+
43
+ # 构建系统
44
+ [build-system]
45
+ requires = ["hatchling"]
46
+ build-backend = "hatchling.build"
47
+
48
+ # 可选模块,方便调用
49
+ [project.optional-dependencies]
50
+ cpu = [
51
+ "onnxruntime>=1.27.0",
52
+ ]
53
+ dml = [
54
+ "onnxruntime-directml>=1.24.4",
55
+ ]
56
+ cuda = [
57
+ "onnxruntime-gpu>=1.27.0",
58
+ ]
59
+ openvino = [
60
+ "openvino>=2026.2.1",
61
+ ]
62
+ index = [
63
+ "faiss-cpu>=1.14.3",
64
+ ]
65
+ dev = [
66
+ "pyright>=1.1.411",
67
+ "ruff>=0.15.21",
68
+ ]
69
+
70
+ [tool.uv]
71
+ conflicts = [ # 这几个是互斥的,防止 uv 傻乎乎地全装上了
72
+ [
73
+ { extra = "cpu" },
74
+ { extra = "cuda" },
75
+ { extra = "dml" }
76
+ ],
77
+ ]
78
+
79
+ [tool.uv.workspace]
80
+ members = [
81
+ "testEnv",
82
+ ]
83
+
84
+ [tool.pyright]
85
+ include = ["src"]
86
+ exclude = ["**/node_modules", "**/__pycache__", ".venv", "**/.*", "src/RvcPyInfer/resource/**/.*"]
87
+ venvPath = "."
88
+ venv = ".venv"
89
+ typeCheckingMode = "basic"
90
+ reportMissingTypeStubs = "none"
91
+ reportUnknownMemberType = "none"
92
+ reportUnusedImport = "warning"
93
+ reportMissingImports = "error"
94
+
95
+ [tool.ruff]
96
+ line-length = 180
97
+ target-version = "py313"
98
+ exclude = [
99
+ ".git",
100
+ ".venv",
101
+ "__pycache__",
102
+ "build",
103
+ "dist",
104
+ "src/RvcPyInfer/resource/"
105
+ ]
106
+
107
+ [tool.ruff.lint]
108
+ # 启用的规则集
109
+ select = [
110
+ "E", # pycodestyle 错误
111
+ "F", # pyflakes
112
+ "I", # isort
113
+ "UP", # pyupgrade
114
+ ]
115
+
116
+ ignore = [
117
+
118
+ ]
119
+ fixable = ["ALL"]
120
+ unfixable = []
121
+
122
+ [tool.ruff.format]
123
+ quote-style = "double"
124
+ indent-style = "space"
125
+ skip-magic-trailing-comma = false
126
+ line-ending = "auto"
@@ -0,0 +1,108 @@
1
+ from enum import Flag, auto
2
+
3
+ from .error.InferEnvError import InferEnvError
4
+
5
+
6
+ class InferProviders(Flag):
7
+ NONE = auto() # 仅用于内部方便处理
8
+
9
+ # ort
10
+ ORT_CPU = auto()
11
+ FORCE_CUDA = auto()
12
+ FORCE_DML = auto()
13
+ CUDA = ORT_CPU | FORCE_CUDA
14
+ DML = ORT_CPU | FORCE_DML
15
+
16
+ # openvino
17
+ OPENVINO_AUTO = auto()
18
+ OPENVINO_CPU = auto()
19
+ OPENVINO_GPU = auto()
20
+ OPENVINO_NPU = auto()
21
+ OPENVINO_OPTIONAL_MULTI = auto()
22
+ OPENVINO_OPTIONAL_HETERO = auto()
23
+ OPENVINO_ALL = OPENVINO_CPU | OPENVINO_GPU | OPENVINO_NPU | OPENVINO_OPTIONAL_MULTI
24
+
25
+ def is_ort(self) -> bool:
26
+ return bool((InferProviders.ORT_CPU | InferProviders.CUDA | InferProviders.DML) & self)
27
+ def is_ov(self) -> bool:
28
+ return bool((InferProviders.OPENVINO_CPU | InferProviders.OPENVINO_GPU | InferProviders.OPENVINO_NPU | InferProviders.OPENVINO_AUTO) & self)
29
+
30
+ def get_onnx_provider(self) -> list[str]:
31
+ res = []
32
+ if self.FORCE_CUDA in self:
33
+ res.append("CUDAExecutionProvider")
34
+ if self.FORCE_DML in self:
35
+ res.append("DmlExecutionProvider")
36
+ if self.ORT_CPU in self:
37
+ res.append("CPUExecutionProvider")
38
+ return res
39
+
40
+ def get_openvino_device(self) -> str:
41
+ devices: list[str] = []
42
+ if self.OPENVINO_GPU in self:
43
+ # 现场找全
44
+ from openvino import Core # pyright: ignore[reportMissingImports]
45
+ devices.extend(filter(lambda name: name.startswith("GPU"), Core().available_devices))
46
+ if self.OPENVINO_NPU in self:
47
+ devices.append("NPU")
48
+ if self.OPENVINO_CPU in self:
49
+ devices.append("CPU")
50
+ devices_str = ",".join(devices)
51
+ if self.OPENVINO_AUTO in self:
52
+ if len(devices) != 0:
53
+ return f"AUTO:{devices_str}"
54
+ else:
55
+ return "AUTO"
56
+ elif self.OPENVINO_OPTIONAL_MULTI in self:
57
+ return f"MULTI:{devices_str}"
58
+ elif self.OPENVINO_OPTIONAL_HETERO in self:
59
+ return f"HETERO:{devices_str}"
60
+ else:
61
+ return devices[0]
62
+
63
+ @staticmethod
64
+ def default() -> "InferProviders":
65
+ available = InferProviders.currently_available()
66
+
67
+ if InferProviders.FORCE_CUDA in available:
68
+ return InferProviders.CUDA
69
+ elif InferProviders.FORCE_DML in available:
70
+ return InferProviders.DML
71
+ elif InferProviders.OPENVINO_CPU in available:
72
+ # 有时候自动的异构并行反而比纯 CPU 还慢,这里保守点
73
+ return InferProviders.OPENVINO_CPU
74
+ elif InferProviders.ORT_CPU in available:
75
+ return InferProviders.ORT_CPU
76
+ else:
77
+ raise InferEnvError("没有任意一个支持的推理引擎,请至少安装一个可选模块")
78
+
79
+ @staticmethod
80
+ def currently_available() -> "InferProviders":
81
+ from .infer_env import HAS_ONE, HAS_OPENVINO, HAS_ORT
82
+ res = InferProviders.NONE
83
+
84
+ if HAS_ORT:
85
+ import onnxruntime as ort # pyright: ignore[reportMissingImports]
86
+ available_providers = ort.get_available_providers()
87
+ if "CPUExecutionProvider" in available_providers:
88
+ res = res | InferProviders.ORT_CPU
89
+ if "CUDAExecutionProvider" in available_providers:
90
+ res = res | InferProviders.FORCE_CUDA
91
+ if "DmlExecutionProvider" in available_providers:
92
+ res = res | InferProviders.FORCE_DML
93
+ if HAS_OPENVINO:
94
+ from openvino import Core # pyright: ignore[reportMissingImports]
95
+ devices = Core().available_devices
96
+ res = res | InferProviders.OPENVINO_AUTO | InferProviders.OPENVINO_OPTIONAL_MULTI | InferProviders.OPENVINO_OPTIONAL_HETERO
97
+ if "CPU" in devices:
98
+ res = res | InferProviders.OPENVINO_CPU
99
+ if any(i.startswith("GPU") for i in devices):
100
+ res = res | InferProviders.OPENVINO_GPU
101
+ if "NPU" in devices:
102
+ res = res | InferProviders.OPENVINO_NPU
103
+ if not HAS_ONE:
104
+ raise InferEnvError("没有任意一个支持的推理引擎,请至少安装一个可选模块")
105
+
106
+ assert res != InferProviders.NONE, "我算是知道了,你们各个都身怀绝技"
107
+ res = res & ~InferProviders.NONE
108
+ return res