Shami96 commited on
Commit
1bf0ddc
·
verified ·
1 Parent(s): 8ab8202

Create transcribe.py

Browse files
Files changed (1) hide show
  1. transcribe.py +19 -0
transcribe.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+ from transformers import pipeline
3
+ from config import ASR_MODEL
4
+
5
+ _asr_pipe = None
6
+
7
+ def get_asr():
8
+ global _asr_pipe
9
+ if _asr_pipe is None:
10
+ _asr_pipe = pipeline(
11
+ "automatic-speech-recognition",
12
+ model=ASR_MODEL
13
+ )
14
+ return _asr_pipe
15
+
16
+ def transcribe(wav_path: Path) -> str:
17
+ pipe = get_asr()
18
+ out = pipe(str(wav_path))
19
+ return out["text"] if isinstance(out, dict) else str(out)