-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
194 lines (167 loc) · 6.77 KB
/
setup.py
File metadata and controls
194 lines (167 loc) · 6.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
"""
Setup configuration for ffvoice Python package
"""
import os
import sys
import subprocess
import platform
from pathlib import Path
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
try:
from wheel.bdist_wheel import bdist_wheel as _bdist_wheel
class bdist_wheel(_bdist_wheel):
"""Custom bdist_wheel to set correct platform tag for macOS"""
def finalize_options(self):
super().finalize_options()
# Override platform tag on macOS to reflect actual architecture
if platform.system() == "Darwin":
arch = platform.machine()
deployment_target = "11.0" if arch == "arm64" else "10.9"
# Set platform tag: macosx_11_0_arm64 or macosx_10_9_x86_64
self.plat_name = f"macosx-{deployment_target.replace('.', '_')}-{arch}"
self.plat_name_supplied = True
except ImportError:
bdist_wheel = None
class CMakeExtension(Extension):
"""Custom Extension class for CMake-based builds"""
def __init__(self, name, sourcedir=""):
Extension.__init__(self, name, sources=[])
self.sourcedir = os.path.abspath(sourcedir)
class CMakeBuild(build_ext):
"""Custom build command that uses CMake"""
def build_extension(self, ext):
if not isinstance(ext, CMakeExtension):
super().build_extension(ext)
return
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
# Create build directory
if not os.path.exists(self.build_temp):
os.makedirs(self.build_temp)
# CMake configuration arguments
cmake_args = [
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}",
f"-DPYTHON_EXECUTABLE={sys.executable}",
"-DBUILD_PYTHON=ON",
"-DBUILD_TESTS=OFF",
"-DBUILD_EXAMPLES=OFF",
"-DENABLE_RNNOISE=ON",
"-DENABLE_WHISPER=ON",
]
# Add vcpkg toolchain file if available (for Windows vcpkg builds)
toolchain_file = os.environ.get("CMAKE_TOOLCHAIN_FILE")
if toolchain_file:
cmake_args.append(f"-DCMAKE_TOOLCHAIN_FILE={toolchain_file}")
# Build type (Release or Debug)
cfg = "Debug" if self.debug else "Release"
cmake_args.append(f"-DCMAKE_BUILD_TYPE={cfg}")
# Platform-specific configuration
if platform.system() == "Darwin": # macOS
# Build for native architecture (arm64 on Apple Silicon, x86_64 on Intel)
# Note: Universal2 builds require universal2 dependencies which adds complexity
arch = platform.machine()
cmake_args.append(f"-DCMAKE_OSX_ARCHITECTURES={arch}")
# Use macOS 11.0 for ARM64 (Big Sur+), 10.9 for x86_64
deployment_target = "11.0" if arch == "arm64" else "10.9"
cmake_args.append(f"-DCMAKE_OSX_DEPLOYMENT_TARGET={deployment_target}")
elif platform.system() == "Windows": # Windows
# Use multi-threaded DLL runtime
cmake_args.append("-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON")
# Build arguments
build_args = ["--config", cfg]
# Parallel build (platform-specific)
if platform.system() == "Windows":
# MSBuild uses /m for parallel builds
build_args.extend(["--", "/m:4"])
else:
# Unix Makefiles use -j for parallel builds
if hasattr(self, "parallel") and self.parallel:
build_args.extend(["--", f"-j{self.parallel}"])
else:
build_args.extend(["--", "-j4"])
env = os.environ.copy()
env["CXXFLAGS"] = f'{env.get("CXXFLAGS", "")} -DVERSION_INFO=\\"{self.distribution.get_version()}\\"'
# Run CMake configuration
print(f"Running CMake in {self.build_temp}...")
subprocess.check_call(
["cmake", ext.sourcedir] + cmake_args,
cwd=self.build_temp,
env=env,
)
# Run CMake build
print(f"Building extension {ext.name}...")
subprocess.check_call(
["cmake", "--build", ".", "--target", "_ffvoice"] + build_args,
cwd=self.build_temp,
)
# Read README for long description
readme_path = Path(__file__).parent / "README.md"
long_description = ""
if readme_path.exists():
with open(readme_path, encoding="utf-8") as f:
long_description = f.read()
# Read version from __init__.py
version = "0.4.0"
init_path = Path(__file__).parent / "python" / "ffvoice" / "__init__.py"
if init_path.exists():
with open(init_path, encoding="utf-8") as f:
for line in f:
if line.startswith("__version__"):
version = line.split("=")[1].strip().strip('"').strip("'")
break
setup(
name="ffvoice",
version=version,
author="ffvoice-engine contributors",
author_email="",
description="High-performance offline speech recognition library for Python",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/chicogong/ffvoice-engine",
project_urls={
"Bug Reports": "https://github.com/chicogong/ffvoice-engine/issues",
"Source": "https://github.com/chicogong/ffvoice-engine",
},
packages=["ffvoice"],
package_dir={"": "python"},
ext_modules=[CMakeExtension("ffvoice._ffvoice")],
cmdclass={
"build_ext": CMakeBuild,
"bdist_wheel": bdist_wheel,
} if bdist_wheel else {"build_ext": CMakeBuild},
zip_safe=False,
python_requires=">=3.9",
classifiers=[
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"Topic :: Multimedia :: Sound/Audio :: Speech",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: C++",
"Operating System :: MacOS :: MacOS X",
"Operating System :: POSIX :: Linux",
"Operating System :: Microsoft :: Windows",
],
keywords="speech-recognition asr whisper voice-activity-detection noise-reduction rnnoise offline-transcription real-time-audio",
install_requires=[
# No Python dependencies required for the native module
# Users can optionally install numpy for advanced features
],
extras_require={
"dev": [
"pytest>=7.0",
"pytest-cov>=4.0",
"black>=23.0",
"flake8>=6.0",
"mypy>=1.0",
],
"numpy": [
"numpy>=1.20",
],
},
)