Skip to content

Commit

Permalink
Fix transcriber bugs while processing folder
Browse files Browse the repository at this point in the history
  • Loading branch information
nshmyrev committed May 26, 2022
1 parent ea0568a commit 55dd29b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
4 changes: 2 additions & 2 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def get_tag(self):
cmdclass=cmdclass,
python_requires='>=3',
zip_safe=False, # Since we load so file from the filesystem, we can not run from zip file
setup_requires=['cffi>=1.0', 'requests', 'tqdm'],
install_requires=['cffi>=1.0', 'requests', 'tqdm'],
setup_requires=['cffi>=1.0', 'requests', 'tqdm', 'srt'],
install_requires=['cffi>=1.0', 'requests', 'tqdm', 'srt'],
cffi_modules=['vosk_builder.py:ffibuilder'],
)
12 changes: 4 additions & 8 deletions python/vosk/transcriber/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,18 @@ def main():
exit(1)

if not Path(args.input).exists():
logging.info('File %s does not exist, please specify an existing file/directory' % (args.input))
exit(1)

if args.output !='' and not Path(args.output).exists():
logging.info('Output %s does not exist, please specify an existing file' % (args.output))
logging.info("File/folder '%s' does not exist, please specify an existing file/directory" % (args.input))
exit(1)

transcriber = Transcriber(args)

if Path(args.input).is_dir() and Path(args.output).is_dir():
if Path(args.input).is_dir():
transcriber.process_dir(args)
return
elif Path(args.input).is_file() and (args.output=='' or Path(args.output).is_file()):
elif Path(args.input).is_file():
transcriber.process_file(args)
else:
logging.info('Wrong arguments, input and output must be same type')
logging.info('Wrong arguments')
exit(1)

if __name__ == "__main__":
Expand Down
6 changes: 3 additions & 3 deletions python/vosk/transcriber/transcriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pathlib import Path
from timeit import default_timer as timer
from vosk import KaldiRecognizer, Model
from multiprocessing.dummy import Pool

class Transcriber:

Expand Down Expand Up @@ -76,11 +77,10 @@ def process_entry(self, inputdata):
print(final_result)
return final_result, tot_samples


def process_directory(self,args):
def process_dir(self,args):
task_list = [(Path(args.input, fn), Path(args.output, Path(fn).stem).with_suffix('.' + args.output_type)) for fn in os.listdir(args.input)]
with Pool() as pool:
pool.map(self.process_entry, file_list)
pool.map(self.process_entry, task_list)

def process_file(self, args):
start_time = timer()
Expand Down
2 changes: 1 addition & 1 deletion travis/build-wheels-dockcross.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ mkdir -p /io/wheelhouse/vosk-linux-$VOSK_ARCHITECTURE
cp /opt/vosk-api/src/*.so /opt/vosk-api/src/vosk_api.h /io/wheelhouse/vosk-linux-$VOSK_ARCHITECTURE

# Build wheel
python3 -m pip install requests tqdm
python3 -m pip install requests tqdm srt
python3 -m pip wheel /opt/vosk-api/python --no-deps -w /io/wheelhouse

0 comments on commit 55dd29b

Please sign in to comment.