Skip to content

Commit 7bbfef4

Browse files
committed
added GUI and batch file to run GUI
1 parent acadd17 commit 7bbfef4

File tree

3 files changed

+109
-5
lines changed

3 files changed

+109
-5
lines changed

GUI.py

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import tkinter as tk
2+
from tkinter import ttk
3+
from tkinter import filedialog
4+
from tkinter import messagebox
5+
from transcribe import transcribe
6+
from ttkthemes import ThemedTk
7+
import whisper
8+
import numpy as np
9+
import glob, os
10+
11+
12+
class App:
13+
def __init__(self, master):
14+
self.master = master
15+
master.title("Local Transcribe")
16+
17+
#style = ttk.Style()
18+
#style.configure('TLabel', font=('Arial', 10), padding=10)
19+
#style.configure('TEntry', font=('Arial', 10), padding=10)
20+
#style.configure('TButton', font=('Arial', 10), padding=10)
21+
#style.configure('TCheckbutton', font=('Arial', 10), padding=10)
22+
23+
# Folder Path
24+
path_frame = ttk.Frame(master, padding=10)
25+
path_frame.pack(fill=tk.BOTH)
26+
path_label = ttk.Label(path_frame, text="Folder Path:")
27+
path_label.pack(side=tk.LEFT, padx=5)
28+
self.path_entry = ttk.Entry(path_frame, width=50)
29+
self.path_entry.insert(10, 'sample_audio/')
30+
self.path_entry.pack(side=tk.LEFT, fill=tk.X, expand=True)
31+
browse_button = ttk.Button(path_frame, text="Browse", command=self.browse)
32+
browse_button.pack(side=tk.LEFT, padx=5)
33+
34+
# File Type
35+
file_type_frame = ttk.Frame(master, padding=10)
36+
file_type_frame.pack(fill=tk.BOTH)
37+
file_type_label = ttk.Label(file_type_frame, text="File Type:")
38+
file_type_label.pack(side=tk.LEFT, padx=5)
39+
self.file_type_entry = ttk.Entry(file_type_frame, width=50)
40+
self.file_type_entry.insert(10, 'ogg')
41+
self.file_type_entry.pack(side=tk.LEFT, fill=tk.X, expand=True)
42+
43+
# Model
44+
model_frame = ttk.Frame(master, padding=10)
45+
model_frame.pack(fill=tk.BOTH)
46+
model_label = ttk.Label(model_frame, text="Model:")
47+
model_label.pack(side=tk.LEFT, padx=5)
48+
self.model_entry = ttk.Entry(model_frame, width=50)
49+
self.model_entry.insert(10, 'small')
50+
self.model_entry.pack(side=tk.LEFT, fill=tk.X, expand=True)
51+
52+
# Language (currently disabled)
53+
#language_frame = ttk.Frame(master, padding=10)
54+
#language_frame.pack(fill=tk.BOTH)
55+
#language_label = ttk.Label(language_frame, text="Language:")
56+
#language_label.pack(side=tk.LEFT, padx=5)
57+
#self.language_entry = ttk.Entry(language_frame, width=50)
58+
#self.language_entry.insert(10, np.nan)
59+
#self.language_entry.pack(side=tk.LEFT, fill=tk.X, expand=True)
60+
61+
# Verbose
62+
verbose_frame = ttk.Frame(master, padding=10)
63+
verbose_frame.pack(fill=tk.BOTH)
64+
self.verbose_var = tk.BooleanVar()
65+
verbose_checkbutton = ttk.Checkbutton(verbose_frame, text="Verbose", variable=self.verbose_var)
66+
verbose_checkbutton.pack(side=tk.LEFT, padx=5)
67+
68+
# Buttons
69+
button_frame = ttk.Frame(master, padding=10)
70+
button_frame.pack(fill=tk.BOTH)
71+
transcribe_button = ttk.Button(button_frame, text="Transcribe Audio", command=self.transcribe)
72+
transcribe_button.pack(side=tk.LEFT, padx=5, pady=10, fill=tk.X, expand=True)
73+
quit_button = ttk.Button(button_frame, text="Quit", command=master.quit)
74+
quit_button.pack(side=tk.RIGHT, padx=5, pady=10, fill=tk.X, expand=True)
75+
76+
def browse(self):
77+
folder_path = filedialog.askdirectory()
78+
self.path_entry.delete(0, tk.END)
79+
self.path_entry.insert(0, folder_path)
80+
81+
def transcribe(self):
82+
path = self.path_entry.get()
83+
file_type = self.file_type_entry.get()
84+
model = self.model_entry.get()
85+
#language = self.language_entry.get()
86+
language = None # set to auto-detect
87+
verbose = self.verbose_var.get()
88+
89+
# Call the transcribe function with the appropriate arguments
90+
result = transcribe(path, file_type, model=model, language=language, verbose=verbose)
91+
92+
# Show the result in a message box
93+
tk.messagebox.showinfo("Finished!", result)
94+
95+
if __name__ == "__main__":
96+
# root = tk.Tk()
97+
root = ThemedTk(theme="clearlooks")
98+
root.geometry("300x200")
99+
app = App(root)
100+
root.mainloop()

run_gui.bat

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@echo off
2+
call 'PATH_TO_CONDA'
3+
call 'ACTIVATE_NEEDED_ENVS'
4+
call python GUI.py
5+
PAUSE

transcribe.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ def transcribe(path, file_type, model=None, language=None, verbose=True):
55
'''Implementation of OpenAI's whisper model. Downloads model, transcribes audio files in a folder and returns the text files with transcriptions'''
66

77
try:
8-
os.mkdir('{}transcriptions'.format(path))
8+
os.mkdir('{}/transcriptions'.format(path))
99
except FileExistsError:
1010
pass
1111

1212
glob_file = glob.glob(path+'/*{}'.format(file_type))
13-
path = path
14-
13+
1514
print('Using {} model, you can change this by specifying model="medium" for example'.format(model))
1615
print('Only looking for file type {}, you can change this by specifying file_type="mp3"'.format(file_type))
1716
print('Expecting {} language, you can change this by specifying language="English". None will try to auto-detect'.format(language))
@@ -39,12 +38,12 @@ def transcribe(path, file_type, model=None, language=None, verbose=True):
3938
end.append(result['segments'][i]['end'])
4039
text.append(result['segments'][i]['text'])
4140

42-
with open("{}transcriptions/{}.txt".format(path,title), 'w', encoding='utf-8') as file:
41+
with open("{}/transcriptions/{}.txt".format(path,title), 'w', encoding='utf-8') as file:
4342
file.write(title)
4443
file.write('\nIn seconds:')
4544
for i in range(len(result['segments'])):
4645
file.writelines('\n[{:.2f} --> {:.2f}]:{}'.format(start[i], end[i], text[i]))
4746

4847
print('\nFinished file number {}.\n\n\n'.format(idx+1))
4948

50-
return 'Finished transcription, files can be found in {}transcriptions'.format(path)
49+
return 'Finished transcription, files can be found in {}/transcriptions'.format(path)

0 commit comments

Comments
 (0)