File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ from moviepy import VideoFileClip , TextClip , CompositeVideoClip
2+ from faster_whisper import WhisperModel
3+
4+ # Load video and extract audio
5+ video = VideoFileClip ("./sales_training_awareness_src.mp4" )
6+ video .audio .write_audiofile ("sales_training_awareness.wav" ) # type: ignore
7+
8+ # Transcribe with faster-whisper
9+ model = WhisperModel ("small" ) # You can use 'small' or 'medium' if needed
10+ segments , _ = model .transcribe ("sales_training_awareness.wav" )
11+ # print(f"Segments are: {segments}")
12+
13+ # Build typewriter subtitles for all segments
14+ subtitle_clips = []
15+ with open ("subtitle.srt" , 'w' ) as fsrt :
16+ for idx , segment in enumerate (segments ):
17+ fsrt .write (f"{ segment .text } : { segment .start } , { segment .end - segment .start } " )
18+ subtitle_clips .append ([segment .text , segment .start , segment .end - segment .start ])
19+ if idx % 5 == 0 :
20+ print (f"At idx: { idx } " )
21+ break
22+
23+
24+ print ("Writing Extracted Subtitle:" )
25+ print (subtitle_clips )
You can’t perform that action at this time.
0 commit comments