Paulhayes commited on
Commit
e1e92af
·
verified ·
1 Parent(s): 5d4b193

Create asr.py

Browse files
Files changed (1) hide show
  1. asr.py +33 -0
asr.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import subprocess
3
+ import os
4
+ from pathlib import Path
5
+
6
+ class ASR:
7
+ def __init__(self, hive_home):
8
+ self.hive_home = Path(hive_home)
9
+ self.model_path = self.hive_home / "models" / "vosk"
10
+ self.ensure_model()
11
+
12
+ def ensure_model(self):
13
+ if not self.model_path.exists():
14
+ print("Downloading Vosk model...")
15
+ os.makedirs(self.model_path.parent, exist_ok=True)
16
+ subprocess.run([
17
+ "wget", "-q", "-O", "-",
18
+ "https://alphacephei.com/vosk/models/vosk-model-small-en-us-0.15.zip"
19
+ ], check=True, stdout=subprocess.PIPE)
20
+ subprocess.run([
21
+ "unzip", "-q", "-", "-d", str(self.model_path.parent)
22
+ ], input=subprocess.Popen([
23
+ "wget", "-q", "-O", "-",
24
+ "https://alphacephei.com/vosk/models/vosk-model-small-en-us-0.15.zip"
25
+ ], stdout=subprocess.PIPE).stdout)
26
+
27
+ def transcribe(self, audio_path):
28
+ try:
29
+ # Simple mock transcription for now
30
+ # In production, integrate Vosk properly
31
+ return "Transcribed text from audio"
32
+ except:
33
+ return "Could not transcribe audio"