speaker_helper.eardrum.ear module
The ear: a phoneme recogniser that writes what it hears, not what it expects.
Module summary
A speech-to-text model is the wrong ear for this job. Whisper has a language model inside: a badly pronounced “GitHub” comes back spelled “GitHub”, because that is the likeliest word, and the loop would believe the engine got it right. A phoneme recogniser has no dictionary to fall back on: it writes the sounds.
The default ear is facebook/wav2vec2-xlsr-53-espeak-cv-ft — wav2vec2
XLSR-53 (pretrained on 53 languages) fine-tuned on Common Voice to output
espeak-style IPA, which is the very alphabet the targets are written in.
Greedy CTC decoding gives each phone a 20 ms frame span, which is what lets
the report cut the word’s own clip out of the carrier sentence.
Where the weights come from, first match wins:
SPEAKER_HELPER_PHONEME_MODEL— a directory holding the model;$SPEAKER_ENGINES_DIR/metrics/phonemes/wav2vec2-xlsr-53-espeak-cv-ft(the self-hosted bundle);~/.cache/speaker-helper/eardrum/wav2vec2-xlsr-53-espeak-cv-ft— whatspeaker-helper install-voice --engine eardrumfills;the Hugging Face cache, read with
local_files_only(never a download at run time).
Usage example
>>> from speaker_helper.eardrum.ear import collapse_ctc
>>> collapse_ctc([0, 5, 5, 0, 7, 7, 7, 0], blank=0)
[(5, 1, 3), (7, 4, 7)]
- class speaker_helper.eardrum.ear.Ear(*args, **kwargs)[source]
Bases:
ProtocolAnything that turns audio into heard phones.
- hear(wav_bytes)[source]
Recognise the phones in an encoded audio payload.
- Parameters:
wav_bytes (bytes) – WAV (or anything
soundfilereads).- Returns:
The phones, in order.
- Return type:
list of HeardPhone
- class speaker_helper.eardrum.ear.HeardPhone(phone, start_s, end_s)[source]
Bases:
objectOne phone the ear heard, with when it was heard.
- phone
The phone (already through
tokenize()).- Type:
- start_s, end_s
Its span in the audio, in seconds.
- Type:
- speaker_helper.eardrum.ear.PHONEME_CACHE: Path = PosixPath('~/.cache/speaker-helper/eardrum/wav2vec2-xlsr-53-espeak-cv-ft')
The local directory
install-voice --engine eardrumfills.
- speaker_helper.eardrum.ear.PHONEME_MODEL = 'facebook/wav2vec2-xlsr-53-espeak-cv-ft'
The recogniser’s name, on the hub and as the local directory name.
- speaker_helper.eardrum.ear.PHONEME_REVISION = '2c733782da5604684829819a5eb744c193fe9398'
The exact revision the loop was measured with (pinned, so two machines installing a month apart hear with the same ear).
- class speaker_helper.eardrum.ear.PhonemeEar(source=None)[source]
Bases:
objectThe wav2vec2 espeak-phoneme recogniser, loaded once and reused.
- Parameters:
source (str or None) – Model directory or hub id;
model_dir()whenNone.
- speaker_helper.eardrum.ear.SAMPLE_RATE = 16000
wav2vec2 reads 16 kHz audio and emits one frame every 320 samples.
- speaker_helper.eardrum.ear.check_install()[source]
0when the ear can load,1otherwise (forhealth-style checks).- Returns:
A process exit code.
- Return type: