RTF < 1 significa mais rápido que tempo real. O modelo é ~55x mais rápido que tempo real em CPU com batch_size=4.
1import nemo.collections.asr as nemo_asr
2
3# Carrega o modelo
4model = nemo_asr.models.EncDecCTCModel.from_pretrained(
5 model_name="ottema/stt_pt_quartznet15x5_ctc_small"
6)
7
8# Transcreve um arquivo de áudio
9audio_file = "path/to/audio.wav"
10transcription = model.transcribe(audio=[audio_file])
11print(transcription[0])
1import nemo.collections.asr as nemo_asr
2
3# Restaura o modelo a partir do arquivo local
4model = nemo_asr.models.EncDecCTCModel.restore_from(
5 restore_path="stt_pt_quartznet15x5_ctc_small_v2.nemo"
6)
7
8# Transcreve
9transcription = model.transcribe(audio=["meu_audio.wav"])
10print(transcription[0])
1# Habilita confidence scores
2model.cfg.decoding.confidence_cfg.preserve_word_confidence = True
3
4hyps = model.transcribe(audio=["audio.wav"], return_hypotheses=True)
5hyp = hyps[0]
6print(f"Texto: {hyp.text}")
7print(f"Score: {hyp.score}")
1import onnxruntime as ort
2import numpy as np
3import nemo.collections.asr as nemo_asr
4import soundfile as sf
5
6# Carrega modelo ONNX
7session = ort.InferenceSession("stt_pt_quartznet15x5_ctc_small.onnx")
8
9# Carrega modelo NeMo apenas para o preprocessor
10nemo_model = nemo_asr.models.EncDecCTCModel.from_pretrained("ottema/stt_pt_quartznet15x5_ctc_small")
11nemo_model.eval()
12
13# Prepara áudio
14waveform, sr = sf.read("audio.wav")
15audio_tensor = torch.tensor(waveform).unsqueeze(0)
16
17# Extrai features
18with torch.no_grad():
19 processed, _ = nemo_model.preprocessor(input_signal=audio_tensor, length=torch.tensor([len(waveform)]))
20 spectrogram = processed.numpy()
21
22# Inferência
23outputs = session.run(["logprobs"], {"audio_signal": spectrogram})
24logits = outputs[0]
25
26# Decodificação Greedy
27vocab = nemo_model.decoder.vocabulary
28ids = np.argmax(logits[0], axis=-1)
29text = []
30prev = -1
31for idx in ids:
32 if idx != prev and idx < len(vocab):
33 text.append(vocab[idx])
34 prev = idx
35print("".join(text))
1@misc{coraa2021,
2 title={CORAA: a large corpus of spontaneous and prepared speech manually validated for speech recognition in Brazilian Portuguese},
3 author={Arnaldo Candido Junior and Edresson Casanova and Anderson Soares and Frederico Santos de Oliveira and Lucas Oliveira and Ricardo Corso Fernandes Junior and Daniel Peixoto Pinto da Silva and Fernando Gorgulho Fayet and Bruno Baldissera Carlotto and Lucas Rafael Stefanel Gris and Sandra Maria Aluísio},
4 year={2021},
5 eprint={2110.15731},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL}
8}