Spaces:
Running
Running
File size: 1,250 Bytes
e0a3506 ecc051b e0a3506 2f350d6 f754acc 2f350d6 a5c7abb e0a3506 |
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 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function
import numpy as np
import sys
import wave
from deepspeech import Model, version
from timeit import default_timer as timer
def client(audio_file, lang="uk"):
model_load_start = timer()
# sphinx-doc: python_ref_model_start
model = "./uk.tflite"
ds = Model(model)
ds.enableExternalScorer("kenlm.scorer")
# sphinx-doc: python_ref_model_stop
model_load_end = timer() - model_load_start
print('Loaded model in {:.3}s.'.format(model_load_end), file=sys.stderr)
desired_sample_rate = ds.sampleRate()
fin = wave.open(audio_file, 'rb')
fs_orig = fin.getframerate()
audio = np.frombuffer(fin.readframes(fin.getnframes()), np.int16)
audio_length = fin.getnframes() * (1/fs_orig)
fin.close()
print('Running inference.', file=sys.stderr)
inference_start = timer()
# sphinx-doc: python_ref_inference_start
result = ds.stt(audio)
print(result)
# sphinx-doc: python_ref_inference_stop
inference_end = timer() - inference_start
print('Inference took %0.3fs for %0.3fs audio file.' %
(inference_end, audio_length), file=sys.stderr)
return result
|