forked from gooofy/py-kaldi-asr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
169 lines (136 loc) · 5.64 KB
/
setup.py
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
from __future__ import print_function
from setuptools import setup, Extension
import numpy
import subprocess
import sys
import os
try:
from Cython.Distutils import build_ext
except ImportError:
raise Exception("*** cython is needed to build this extension.")
cmdclass = {}
ext_modules = []
def getstatusoutput(command):
process = subprocess.Popen(command, stdout=subprocess.PIPE)
out, _ = process.communicate()
return (process.returncode, out)
def find_dependencies():
kw = {}
flag_map = {'-I': 'include_dirs', '-L': 'library_dirs', '-l': 'libraries'}
#
# find atlas library (try pkgconfig, if that fails look at usual places)
#
print("looking for atlas library, trying pkg-config first...")
# Try pky-config values for atlas
status, output = getstatusoutput(
["pkg-config", "--libs", "--cflags", "blas-atlas"])
# Try pkg-config values for atlas
if status != 0:
status, output = getstatusoutput(
["pkg-config", "--libs", "--cflags", "atlas"])
if status != 0:
print("looking for atlas library, trying hard-coded paths...")
found = False
for libdir in ['/usr/lib', '/usr/lib64', '/usr/lib/x86_64-linux-gnu',
'/usr/lib/i386-linux-gnu']:
if os.path.isfile('%s/libatlas.so.3' % libdir):
found = True
break
if not found:
raise Exception('Failed to find libatlas.so.3 on your system.')
kw.setdefault('libraries', []).append('%s/atlas.so.3' % libdir)
kw.setdefault('libraries', []).append('%s/cblas.so.3' % libdir)
kw.setdefault('libraries', []).append('%s/f77blas.so.3' % libdir)
kw.setdefault('libraries', []).append('%s/lapack_atlas.so.3' % libdir)
include_path = None
include_found = False
for include_dir in ['/usr/include/atlas',
'/usr/include/x86_64-linux-gnu/atlas']:
if os.path.isdir(include_dir):
include_found = True
include_path = include_dir
if not include_found:
raise Exception('Failed to find atlas includes your system.')
kw.setdefault('include_dirs', []).append(include_path)
print("looking for atlas library, found it.")
else:
print("looking for atlas library, pkg-config found it")
for token in output.split():
token = token.decode('utf8')
kw.setdefault(flag_map.get(token[:2]), []).append(token[2:])
#
# pkgconfig: kaldi-asr
#
status, output = getstatusoutput(
["pkg-config", "--libs", "--cflags", "kaldi-asr"])
if status != 0:
raise Exception("*** failed to find pkgconfig for kaldi-asr")
for token in output.split():
token = token.decode('utf8')
prefix = token[:2]
arg = token[2:]
# print(repr(token))
# print(repr(prefix))
kw.setdefault(flag_map.get(prefix), []).append(arg)
# print (repr(kw))
return kw
# CFLAGS = -Wall -pthread -std=c++11 -DKALDI_DOUBLEPRECISION=0 -Wno-sign-compare \
# -Wno-unused-local-typedefs -Winit-self -DHAVE_EXECINFO_H=1 -DHAVE_CXXABI_H -DHAVE_ATLAS \
# `pkg-config --cflags kaldi-asr` -g
ext_modules += [
Extension("kaldiasr.nnet3",
sources=["kaldiasr/nnet3.pyx", "kaldiasr/nnet3_wrappers.cpp"],
language="c++",
extra_compile_args=['-Wall', '-pthread', '-std=c++11',
'-DKALDI_DOUBLEPRECISION=0',
'-Wno-sign-compare',
'-Wno-unused-local-typedefs', '-Winit-self',
'-DHAVE_EXECINFO_H=1', '-DHAVE_CXXABI_H',
'-DHAVE_ATLAS', '-g'],
**find_dependencies()),
Extension("kaldiasr.gmm",
sources=["kaldiasr/gmm.pyx", "kaldiasr/gmm_wrappers.cpp"],
language="c++",
extra_compile_args=['-Wall', '-pthread', '-std=c++11',
'-DKALDI_DOUBLEPRECISION=0',
'-Wno-sign-compare',
'-Wno-unused-local-typedefs', '-Winit-self',
'-DHAVE_EXECINFO_H=1', '-DHAVE_CXXABI_H',
'-DHAVE_ATLAS', '-g'],
**find_dependencies()),
]
cmdclass.update({'build_ext': build_ext})
for e in ext_modules:
e.cython_directives = {'language_level': "3"}
setup(
name='py-kaldi-asr',
version='0.5.2',
description='Simple Python/Cython interface to kaldi-asr nnet3/chain and gmm decoders',
long_description=open('README.md').read(),
author='Guenter Bartsch',
author_email='guenter@zamia.org',
maintainer='Guenter Bartsch',
maintainer_email='guenter@zamia.org',
url='https://github.com/gooofy/py-kaldi-asr',
packages=['kaldiasr'],
cmdclass=cmdclass,
ext_modules=ext_modules,
include_dirs=[numpy.get_include()],
classifiers=[
'Operating System :: POSIX :: Linux',
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Cython',
'Programming Language :: C++',
'Intended Audience :: Developers',
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: Multimedia :: Sound/Audio :: Speech'
],
license='Apache',
keywords='kaldi asr',
include_package_data=True,
install_requires=['numpy', 'cython', ],
)