Enforce local audio extraction rules in transcribe.py

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Gan, Jimmy
2026-06-03 02:56:59 +08:00
parent 86caddbeb4
commit f201ef509d
+14 -2
View File
@@ -1,13 +1,25 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import sys import sys
import whisper import whisper
import os
if len(sys.argv) < 2: 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") print("Example: python transcribe.py audio.mp3 es")
sys.exit(1) 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") model = whisper.load_model("base")
language = sys.argv[2] if len(sys.argv) > 2 else None 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"]) print(result["text"])