Views
No views yet
model.pt and tokens.txt:1import nemo.collections.asr as nemo_asr
2
3citrinet_de_1024 = nemo_asr.models.EncDecCTCModelBPE.from_pretrained('stt_de_citrinet_1024');
4citrinet_de_1024.export('model.pt')
5
6# Caution: We use 0 for blank here, while NeMo treat the last token as blank.
7# For instance, when len(citrinet_de_1024.decoder.vocabulary) is 1024. NeMo treats
8# ID 1025 as blank but we treat 0 as blank.
9with open('tokens.txt', 'w') as f:
10 f.write("<blk> 0\n")
11 for i, s in enumerate(citrinet_de_1024.decoder.vocabulary):
12 f.write(f"{s} {i+1}\n")preprocessor:import kaldifeat
opts = kaldifeat.FbankOptions()
opts.device = "cpu"
opts.frame_opts.dither = 0
opts.frame_opts.snip_edges = False
opts.frame_opts.samp_freq = 16000
opts.frame_opts.window_type = "povey"
opts.mel_opts.num_bins = 80
fbank = kaldifeat.Fbank(opts)
import torchaudio
samples, sample_rate = torchaudio.load("./test_wavs/0.wav")
assert sample_rate == 16000
features = fbank(samples[0])
mean = features.mean(dim=0, keepdims=True)
std = features.std(dim=0, keepdims=True)
features = (features - mean) / std
features = features.unsqueeze(0).permute(0, 2, 1)
# Note features is of shape (N, C, T)
model = torch.jit.load('model.pt')
logprob = model(features, torch.tensor([features.shape[2]]))