setup.py
3.8 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
#!/usr/bin/env python3
import os
import re
import sys
from pathlib import Path
import setuptools
from cmake.cmake_extension import (
BuildExtension,
bdist_wheel,
cmake_extension,
enable_alsa,
is_windows,
)
def read_long_description():
with open("README.md", encoding="utf8") as f:
readme = f.read()
return readme
def get_package_version():
with open("CMakeLists.txt") as f:
content = f.read()
match = re.search(r"set\(SHERPA_ONNX_VERSION (.*)\)", content)
latest_version = match.group(1).strip('"')
return latest_version
package_name = "sherpa-onnx"
with open("sherpa-onnx/python/sherpa_onnx/__init__.py", "a") as f:
f.write(f"__version__ = '{get_package_version()}'\n")
install_requires = [
"numpy",
"sentencepiece==0.1.96; python_version < '3.11'",
"sentencepiece; python_version >= '3.11'",
"click>=7.1.1",
]
def get_binaries_to_install():
bin_dir = Path("build") / "sherpa_onnx" / "bin"
bin_dir.mkdir(parents=True, exist_ok=True)
suffix = ".exe" if is_windows() else ""
# Remember to also change cmake/cmake_extension.py
binaries = ["sherpa-onnx"]
binaries += ["sherpa-onnx-keyword-spotter"]
binaries += ["sherpa-onnx-offline"]
binaries += ["sherpa-onnx-microphone"]
binaries += ["sherpa-onnx-microphone-offline"]
binaries += ["sherpa-onnx-online-websocket-server"]
binaries += ["sherpa-onnx-offline-websocket-server"]
binaries += ["sherpa-onnx-online-websocket-client"]
binaries += ["sherpa-onnx-vad-microphone"]
binaries += ["sherpa-onnx-vad-microphone-offline-asr"]
binaries += ["sherpa-onnx-offline-tts"]
binaries += ["sherpa-onnx-offline-tts-play"]
if enable_alsa():
binaries += ["sherpa-onnx-alsa"]
binaries += ["sherpa-onnx-offline-tts-play-alsa"]
if is_windows():
binaries += ["kaldi-native-fbank-core.dll"]
binaries += ["sherpa-onnx-c-api.dll"]
binaries += ["sherpa-onnx-core.dll"]
binaries += ["sherpa-onnx-portaudio.dll"]
binaries += ["onnxruntime.dll"]
binaries += ["piper_phonemize.dll"]
binaries += ["espeak-ng.dll"]
binaries += ["ucd.dll"]
binaries += ["kaldi-decoder-core.dll"]
binaries += ["sherpa-onnx-fst.lib"]
binaries += ["sherpa-onnx-kaldifst-core.lib"]
exe = []
for f in binaries:
suffix = "" if (".dll" in f or ".lib" in f) else suffix
t = bin_dir / (f + suffix)
exe.append(str(t))
return exe
setuptools.setup(
name=package_name,
python_requires=">=3.6",
install_requires=install_requires,
version=get_package_version(),
author="The sherpa-onnx development team",
author_email="dpovey@gmail.com",
package_dir={
"sherpa_onnx": "sherpa-onnx/python/sherpa_onnx",
},
packages=["sherpa_onnx"],
data_files=[("bin", get_binaries_to_install())],
url="https://github.com/k2-fsa/sherpa-onnx",
long_description=read_long_description(),
long_description_content_type="text/markdown",
ext_modules=[cmake_extension("_sherpa_onnx")],
cmdclass={"build_ext": BuildExtension, "bdist_wheel": bdist_wheel},
zip_safe=False,
classifiers=[
"Programming Language :: C++",
"Programming Language :: Python",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
],
entry_points={
"console_scripts": [
"sherpa-onnx-cli=sherpa_onnx.cli:cli",
],
},
license="Apache licensed, as found in the LICENSE file",
)
with open("sherpa-onnx/python/sherpa_onnx/__init__.py", "r") as f:
lines = f.readlines()
with open("sherpa-onnx/python/sherpa_onnx/__init__.py", "w") as f:
for line in lines:
if "__version__" in line:
# skip __version__ = "x.x.x"
continue
f.write(line)