Spaces:
Sleeping
Sleeping
File size: 603 Bytes
caa019f 01c1e6f caa019f 631eb6a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
import subprocess
import whisper
import os
def extract_audio(video_path: str, audio_path: str = "temp_audio.wav") -> str:
if os.path.exists(audio_path):
os.remove(audio_path)
command = ["ffmpeg", "-i", video_path, "-q:a", "0", "-map", "a", audio_path, "-y"]
subprocess.run(command, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True)
return audio_path
def transcribe_audio(audio_path: str, model_size: str = "base") -> str:
model = whisper.load_model(model_size)
result = model.transcribe(audio_path)
transcript = result["text"]
return transcript |