Add timestamps toggle and update transcription format to include/exclude timestamps
This commit is contained in:
11
app.py
11
app.py
@@ -127,6 +127,14 @@ class App:
|
||||
values=models, font=font_b)
|
||||
self.model_combobox.set('medium') # Set the default value
|
||||
self.model_combobox.pack(side=tk.LEFT, fill=tk.X, expand=True)
|
||||
# Timestamps toggle
|
||||
ts_frame = customtkinter.CTkFrame(master)
|
||||
ts_frame.pack(fill=tk.BOTH, padx=10, pady=10)
|
||||
self.timestamps_var = tk.BooleanVar(value=True)
|
||||
self.timestamps_switch = customtkinter.CTkSwitch(
|
||||
ts_frame, text="Include timestamps in transcription",
|
||||
variable=self.timestamps_var, font=font_b)
|
||||
self.timestamps_switch.pack(side=tk.LEFT, padx=5)
|
||||
# Progress Bar
|
||||
self.progress_bar = ttk.Progressbar(master, length=200, mode='indeterminate')
|
||||
# Button actions frame
|
||||
@@ -184,6 +192,7 @@ class App:
|
||||
elif language == self.default_language_text or not language.strip():
|
||||
language = None # This is the same as passing nothing
|
||||
verbose = True # always show transcription progress in the console panel
|
||||
timestamps = self.timestamps_var.get()
|
||||
# Show progress bar
|
||||
self.progress_bar.pack(fill=tk.X, padx=5, pady=5)
|
||||
self.progress_bar.start()
|
||||
@@ -192,7 +201,7 @@ class App:
|
||||
#messagebox.showinfo("Message", "Starting transcription!")
|
||||
# Start transcription
|
||||
try:
|
||||
output_text = transcribe(path, glob_file, model, language, verbose)
|
||||
output_text = transcribe(path, glob_file, model, language, verbose, timestamps)
|
||||
except UnboundLocalError:
|
||||
messagebox.showinfo("Files not found error!", 'Nothing found, choose another folder.')
|
||||
pass
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
Armstrong_Small_Step
|
||||
[0:00:00 --> 0:00:07]: That's one small step for man, one giant leap for mankind.
|
||||
────────────────────────────────────────
|
||||
|
||||
That's one small step for man, one giant leap for mankind.
|
||||
@@ -1,2 +1,4 @@
|
||||
Axel_Pettersson_röstinspelning
|
||||
[0:00:00 --> 0:00:15]: Hej, jag heter Axel Pettersson, jag föddes i Örebro 1976. Jag har varit Wikipedia sen 2008 och jag har översatt röstintroduktionsprojektet till svenska.
|
||||
────────────────────────────────────────
|
||||
|
||||
Hej, jag heter Axel Pettersson, jag föddes i Örebro 1976. Jag har varit Wikipedia sen 2008 och jag har översatt röstintroduktionsprojektet till svenska.
|
||||
@@ -91,7 +91,7 @@ def get_path(path):
|
||||
return sorted(media_files)
|
||||
|
||||
# Main function
|
||||
def transcribe(path, glob_file, model=None, language=None, verbose=False):
|
||||
def transcribe(path, glob_file, model=None, language=None, verbose=False, timestamps=True):
|
||||
"""
|
||||
Transcribes audio files in a specified folder using faster-whisper (CTranslate2).
|
||||
|
||||
@@ -182,10 +182,15 @@ def transcribe(path, glob_file, model=None, language=None, verbose=False):
|
||||
segment_list = []
|
||||
with open("{}/transcriptions/{}.txt".format(path, title), 'w', encoding='utf-8') as f:
|
||||
f.write(title)
|
||||
f.write('\n' + '─' * 40 + '\n')
|
||||
for seg in segments:
|
||||
start_ts = str(datetime.timedelta(seconds=seg.start))
|
||||
end_ts = str(datetime.timedelta(seconds=seg.end))
|
||||
f.write('\n[{} --> {}]:{}'.format(start_ts, end_ts, seg.text))
|
||||
text = seg.text.strip()
|
||||
if timestamps:
|
||||
start_ts = str(datetime.timedelta(seconds=seg.start))
|
||||
end_ts = str(datetime.timedelta(seconds=seg.end))
|
||||
f.write('\n[{} --> {}] {}'.format(start_ts, end_ts, text))
|
||||
else:
|
||||
f.write('\n{}'.format(text))
|
||||
f.flush()
|
||||
if verbose:
|
||||
print(" [%.2fs → %.2fs] %s" % (seg.start, seg.end, seg.text))
|
||||
|
||||
Reference in New Issue
Block a user