NightPrince commited on
Commit
08f36ee
·
verified ·
1 Parent(s): f407a3e

Add DiacritizedASR one-call pipeline wrapper

Browse files
Files changed (1) hide show
  1. pipeline.py +36 -0
pipeline.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """One-call Arabic speech-to-text with forced diacritization (tashkeel).
2
+
3
+ Wraps the NeMo ASR model and the CATT diacritizer as a single object so
4
+ transcription -> diacritization happens as one process, one call.
5
+ """
6
+ from __future__ import annotations
7
+
8
+ import nemo.collections.asr as nemo_asr
9
+
10
+ from diacritize import Diacritizer
11
+
12
+
13
+ class DiacritizedASR:
14
+ """Arabic speech-to-text that returns fully diacritized transcripts."""
15
+
16
+ def __init__(
17
+ self,
18
+ nemo_path: str = "stt_ar_fastconformer_hybrid_large_pcd_v1.0.nemo",
19
+ catt_ckpt: str = "best_ed_mlm_ns_epoch_178.pt",
20
+ device: str | None = None,
21
+ ) -> None:
22
+ self.asr_model = nemo_asr.models.EncDecHybridRNNTCTCBPEModel.restore_from(nemo_path)
23
+ self.asr_model.eval()
24
+ self.diacritizer = Diacritizer(ckpt=catt_ckpt, device=device)
25
+
26
+ def transcribe(self, audio_path: str) -> str:
27
+ """Audio file path -> diacritized Arabic text."""
28
+ plain = self.asr_model.transcribe([audio_path])[0].text
29
+ return self.diacritizer.diacritize_texts([plain])[0]
30
+
31
+
32
+ if __name__ == "__main__":
33
+ import sys
34
+
35
+ model = DiacritizedASR()
36
+ print(model.transcribe(sys.argv[1]))