blu-assistant / src /blu /asr.py
Aravindhan11's picture
Upload 33 files
9776024 verified
import os
import subprocess
from typing import Optional
from .config import cfg
def transcribe(audio_path: str, model: Optional[str] = None) -> str:
"""Transcribe using Whisper (via whisperx CLI for speed or openai-whisper).
Requires: pip install whisperx OR openai-whisper
"""
model = model or cfg.whisper_model
try:
cmd = ["whisperx", audio_path, "--model", model, "--output_format", "txt", "--output_dir", ".config"]
subprocess.run(cmd, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out = os.path.join(".config", os.path.splitext(os.path.basename(audio_path))[0] + ".txt")
with open(out, "r") as f:
return f.read().strip()
except Exception:
try:
cmd = ["whisper", audio_path, "--model", model, "--language", "auto", "--output_format", "txt", "--output_dir", ".config"]
subprocess.run(cmd, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out = os.path.join(".config", os.path.splitext(os.path.basename(audio_path))[0] + ".txt")
with open(out, "r") as f:
return f.read().strip()
except Exception as e:
return f"ASR failed: {e}"