diff --git a/gentle/standard_kaldi.py b/gentle/standard_kaldi.py index 109fa370..4b7d7edc 100644 --- a/gentle/standard_kaldi.py +++ b/gentle/standard_kaldi.py @@ -7,9 +7,9 @@ class Kaldi: def __init__(self, nnet_dir=None, hclg_path=None, proto_langdir=None): devnull = open(os.devnull, 'w') - + cmd = [EXECUTABLE_PATH] - + if nnet_dir is not None: cmd.append(nnet_dir) cmd.append(hclg_path) @@ -26,7 +26,7 @@ def _cmd(self, c): def push_chunk(self, buf): # Wait until we're ready self._cmd("push-chunk") - + cnt = len(buf)/2 self._cmd(str(cnt)) self._p.stdin.write(buf) #arr.tostring()) @@ -73,12 +73,12 @@ def __del__(self): import sys infile = sys.argv[1] - + k = Kaldi() buf = numm3.sound2np(infile, nchannels=1, R=8000) print 'loaded_buf', len(buf) - + idx=0 while idx < len(buf): k.push_chunk(buf[idx:idx+160000].tostring()) diff --git a/gentle/transcriber.py b/gentle/transcriber.py index 98980af3..e7ae759f 100644 --- a/gentle/transcriber.py +++ b/gentle/transcriber.py @@ -11,7 +11,7 @@ def __init__(self, kaldi_queue, chunk_len=20, overlap_t=2, nthreads=4): self.chunk_len = chunk_len self.overlap_t = overlap_t self.nthreads = nthreads - + self.kaldi_queue = kaldi_queue def transcribe(self, wavfile, progress_cb=None): @@ -41,11 +41,10 @@ def transcribe_chunk(idx): progress_cb({"message": ' '.join([X['word'] for X in ret]), "percent": len(chunks) / float(n_chunks)}) - pool = Pool(min(n_chunks, self.nthreads)) pool.map(transcribe_chunk, range(n_chunks)) pool.close() - + chunks.sort(key=lambda x: x['start']) # Combine chunks @@ -99,7 +98,6 @@ def transcribe_chunk(idx): resources = gentle.Resources() - k_queue = Queue() for i in range(3): k_queue.put(standard_kaldi.Kaldi(resources.nnet_gpu_path, resources.full_hclg_path, resources.proto_langdir)) diff --git a/gentle/util/paths.py b/gentle/util/paths.py index 8205dc2c..fbd6353a 100644 --- a/gentle/util/paths.py +++ b/gentle/util/paths.py @@ -8,7 +8,11 @@ class SourceResolver: def __init__(self): - self.project_root = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir, os.pardir)) + root = os.environ.get(ENV_VAR) + if root: + self.project_root = root + else: + self.project_root = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir, os.pardir)) def get_binary(self, name): path_in_project = os.path.join(self.project_root, name) @@ -18,8 +22,7 @@ def get_binary(self, name): return name def get_resource(self, name): - root = os.environ.get(ENV_VAR) or self.project_root - return os.path.join(root, name) + return os.path.join(self.project_root, name) def get_datadir(self, name): return self.get_resource(name) diff --git a/setup.py b/setup.py index 743b5cb1..13c3bc15 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -from setuptools import setup +from setuptools import setup, find_packages from gentle import __version__ setup( @@ -14,6 +14,6 @@ url='http://lowerquality.com/gentle', author='Robert M Ochshorn', license='MIT', - packages=['gentle'], + packages=find_packages(), install_requires=['twisted'], )