-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
39 lines (28 loc) · 1.33 KB
/
cli.py
File metadata and controls
39 lines (28 loc) · 1.33 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
import argparse
import os
from speech_segmenter import SpeechSegmenter, TenVadSpeechSegmenter
from speech_to_text import SpeechToText, UtterSpeech
from subtitle_saver import SubtitleSaver
def main():
parser = argparse.ArgumentParser(description="Generate subtitles for a video/audio file.")
parser.add_argument("input", help="Path to the input file")
parser.add_argument("-o", "--output", default="", help="Output file path (default: empty - so it uses the same name as the input file)")
args = parser.parse_args()
# Demonstration of access
print(f"--- Configuration ---")
print(f"Input: {args.input}")
print(f"Output: {args.output}")
speech_segmenter: SpeechSegmenter = TenVadSpeechSegmenter()
speech_to_text: SpeechToText = UtterSpeech(0)
subtitle_saver: SubtitleSaver = SubtitleSaver()
# Detect all speech segments.
speech_segments = speech_segmenter.detect(args.input)
# Transcribe all speech segments.
transcribed_segments = speech_to_text.transcribe(speech_segments, audio_file_path=args.input)
# Convert to subtitle file.
subtitle_file_path = args.output
if args.output == "":
subtitle_file_path = os.path.basename(os.path.splitext(args.input)[0]) + ".srt"
subtitle_saver.save(transcribed_segments, subtitle_file_path)
if __name__ == "__main__":
main()