tiny-dictation-en / runtime /dictation.py
Hansda's picture
Release Tiny Dictation English and complete benchmarks
531b9c5 verified
Raw History Blame Contribute Delete
506 Bytes
'Run offline English dictation using a compact acoustic model and greedy CTC.'
import math
import soundfile as sf
from scipy.signal import resample_poly
SAMPLE_RATE = 16_000
def read_audio(source):
waveform, rate = sf.read(source, dtype="float32", always_2d=True)
waveform = waveform.mean(axis=1)
if rate != SAMPLE_RATE and len(waveform):
divisor = math.gcd(rate, SAMPLE_RATE)
waveform = resample_poly(waveform, SAMPLE_RATE // divisor, rate // divisor)
return waveform