File size: 506 Bytes
531b9c5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | '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
|