-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprepis.py
More file actions
47 lines (35 loc) · 1.64 KB
/
prepis.py
File metadata and controls
47 lines (35 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import whisper
import argparse
import os
from datetime import timedelta
def format_timestamp(seconds: float) -> str:
return str(timedelta(seconds=int(seconds)))
def transcribe_file(input_file: str, model_name: str, output_file: str):
print(f"🧠 Načítám model '{model_name}'...")
model = whisper.load_model(model_name)
print(f"🎧 Přepisuji soubor: {input_file}")
result = model.transcribe(input_file, language="cs", verbose=False)
segments = result.get("segments", [])
formatted = []
for seg in segments:
start = format_timestamp(seg["start"])
end = format_timestamp(seg["end"])
text = seg["text"].strip()
line = f"[{start} - {end}] {text}"
print(line)
formatted.append(line)
with open(output_file, "w", encoding="utf-8") as f:
f.write("\n".join(formatted))
print(f"\n✅ Hotovo. Přepis uložen do souboru: {output_file}")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Přepis audio/video souboru pomocí Whisper.")
parser.add_argument("input", nargs="?", help="Cesta k audio/video souboru (např. schuzka.mp4)")
parser.add_argument("-m", "--model", default="medium", help="Název Whisper modelu (tiny, base, small, medium, large)")
parser.add_argument("-o", "--output", default="prepis.txt", help="Výstupní soubor (default: prepis.txt)")
args = parser.parse_args()
if not args.input:
args.input = input("Zadej cestu k audio/video souboru: ").strip()
if not os.path.exists(args.input):
print("❌ Soubor neexistuje.")
exit(1)
transcribe_file(args.input, args.model, args.output)