Enforce local audio extraction rules in transcribe.py
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+14
-2
@@ -1,13 +1,25 @@
|
||||
#!/usr/bin/env python3
|
||||
import sys
|
||||
import whisper
|
||||
import os
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage: python transcribe.py <audio_or_video_file> [language]")
|
||||
print("Usage: python transcribe.py <audio_file> [language]")
|
||||
print("Example: python transcribe.py audio.mp3 es")
|
||||
sys.exit(1)
|
||||
|
||||
filename = sys.argv[1]
|
||||
ext = os.path.splitext(filename)[1].lower()
|
||||
video_exts = {'.mp4', '.avi', '.mov', '.mkv', '.flv', '.wmv', '.webm'}
|
||||
|
||||
if ext in video_exts:
|
||||
print(f"Error: Video files ({ext}) are not allowed per DEVELOPMENT_RULES.md.")
|
||||
print("Please extract audio first (e.g., using ffmpeg -i input.mp4 -vn -acodec libmp3lame output.mp3)")
|
||||
sys.exit(1)
|
||||
|
||||
print(f"Transcribing {filename}...")
|
||||
model = whisper.load_model("base")
|
||||
language = sys.argv[2] if len(sys.argv) > 2 else None
|
||||
result = model.transcribe(sys.argv[1], language=language)
|
||||
result = model.transcribe(filename, language=language)
|
||||
print("-" * 20)
|
||||
print(result["text"])
|
||||
|
||||
Reference in New Issue
Block a user