Download runtime/dictation.py from Hansda/tiny-dictation-en: direct link, hf CLI and curl.
- Browser
- Download file 506 Bytes
-
https://huggingface.co/Hansda/tiny-dictation-en/resolve/main/runtime/dictation.py
- Command line
-
hf download hf://Hansda/tiny-dictation-en/runtime/dictation.py
-
curl -L -o dictation.py https://huggingface.co/Hansda/tiny-dictation-en/resolve/main/runtime/dictation.py
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 | |