4
4
from PySide6 .QtCore import QThread , Qt
5
5
import ctranslate2
6
6
import yaml
7
- # Import the TranscribeFile class from the transcribe_module.py script
8
7
from transcribe_module import TranscribeFile
9
8
10
9
class TranscriptionThread (QThread ):
@@ -26,7 +25,7 @@ class TranscriberToolSettingsTab(QWidget):
26
25
27
26
def __init__ (self ):
28
27
super ().__init__ ()
29
- self .selected_audio_file = None # Keep track of the selected audio file
28
+ self .selected_audio_file = None
30
29
self .create_layout ()
31
30
self .load_config ()
32
31
@@ -71,60 +70,48 @@ def update_quantization(self, device_combo, quantization_combo):
71
70
def create_layout (self ):
72
71
layout = QGridLayout ()
73
72
73
+ def add_widget (widget_class , text , row , column , colspan = 1 , signal_slot = None , items = None ):
74
+ widget = widget_class ()
75
+ if widget_class in [QLabel , QPushButton ]:
76
+ widget .setText (text )
77
+ if signal_slot :
78
+ widget .clicked .connect (signal_slot )
79
+ if widget_class is QComboBox and items :
80
+ widget .addItems (items )
81
+ layout .addWidget (widget , row , column , 1 , colspan )
82
+ return widget
83
+
74
84
# Model
75
- model_label = QLabel ("Model" )
76
- layout .addWidget (model_label , 0 , 0 )
77
- self .model_combo = QComboBox ()
78
- self .model_combo .addItems (["tiny" , "tiny.en" , "base" , "base.en" , "small" , "small.en" , "medium" , "medium.en" , "large-v2" ])
79
- layout .addWidget (self .model_combo , 0 , 1 )
85
+ add_widget (QLabel , "Model" , 0 , 0 )
86
+ self .model_combo = add_widget (QComboBox , None , 0 , 1 , items = ["tiny" , "tiny.en" , "base" , "base.en" , "small" , "small.en" , "medium" , "medium.en" , "large-v2" ])
80
87
81
88
# Quantization
82
- quantization_label = QLabel ("Quant" )
83
- layout .addWidget (quantization_label , 0 , 2 )
84
- self .quantization_combo = QComboBox ()
85
- layout .addWidget (self .quantization_combo , 0 , 3 )
89
+ add_widget (QLabel , "Quant" , 0 , 2 )
90
+ self .quantization_combo = add_widget (QComboBox , None , 0 , 3 )
86
91
87
92
# Device
88
- device_label = QLabel ("Device" )
89
- layout .addWidget (device_label , 0 , 4 )
90
- self .device_combo = QComboBox ()
91
- device_options = ["cpu" ]
92
- if self .has_cuda_device ():
93
- device_options .append ("cuda" )
94
- self .device_combo .addItems (device_options )
95
- layout .addWidget (self .device_combo , 0 , 5 )
93
+ add_widget (QLabel , "Device" , 0 , 4 )
94
+ device_options = ["cpu" ] + ["cuda" ] if self .has_cuda_device () else []
95
+ self .device_combo = add_widget (QComboBox , None , 0 , 5 , items = device_options )
96
96
97
97
# Timestamp and Translate Labels with Checkboxes
98
- timestamp_label = QLabel ("Timestamps" )
99
- layout .addWidget (timestamp_label , 1 , 0 )
100
- self .timestamp_checkbox = QCheckBox ()
101
- layout .addWidget (self .timestamp_checkbox , 1 , 1 )
102
- translate_label = QLabel ("Translate" )
103
- layout .addWidget (translate_label , 1 , 2 )
104
- self .translate_checkbox = QCheckBox ()
105
- layout .addWidget (self .translate_checkbox , 1 , 3 )
98
+ add_widget (QLabel , "Timestamps" , 1 , 0 )
99
+ self .timestamp_checkbox = add_widget (QCheckBox , None , 1 , 1 )
100
+ add_widget (QLabel , "Translate" , 1 , 2 )
101
+ self .translate_checkbox = add_widget (QCheckBox , None , 1 , 3 )
106
102
107
103
# Language Label and ComboBox
108
- language_label = QLabel ("Language" )
109
- layout .addWidget (language_label , 1 , 4 )
110
- self .language_combo = QComboBox ()
111
- self .language_combo .addItems (["Option 1" , "Option 2" , "Option 3" ])
112
- layout .addWidget (self .language_combo , 1 , 5 )
104
+ add_widget (QLabel , "Language" , 1 , 4 )
105
+ self .language_combo = add_widget (QComboBox , None , 1 , 5 , items = ["Option 1" , "Option 2" , "Option 3" ])
113
106
114
107
# Select Audio File Button
115
- self .select_file_button = QPushButton ("Select Audio File" )
116
- self .select_file_button .clicked .connect (self .select_audio_file )
117
- layout .addWidget (self .select_file_button , 2 , 0 , 1 , 3 )
108
+ self .select_file_button = add_widget (QPushButton , "Select Audio File" , 2 , 0 , 3 , signal_slot = self .select_audio_file )
118
109
119
- # Transcribe/Translate Button (with functionality)
120
- self .transcribe_translate_button = QPushButton ("Transcribe/Translate" )
121
- self .transcribe_translate_button .clicked .connect (self .start_transcription )
122
- layout .addWidget (self .transcribe_translate_button , 2 , 3 , 1 , 3 )
110
+ # Transcribe/Translate Button
111
+ self .transcribe_translate_button = add_widget (QPushButton , "Transcribe/Translate" , 2 , 3 , 3 , signal_slot = self .start_transcription )
123
112
124
113
# Update Settings Button
125
- self .update_settings_button = QPushButton ("Update Settings" )
126
- self .update_settings_button .clicked .connect (self .save_settings )
127
- layout .addWidget (self .update_settings_button , 3 , 0 , 1 , 6 )
114
+ self .update_settings_button = add_widget (QPushButton , "Update Settings" , 3 , 0 , 6 , signal_slot = self .save_settings )
128
115
129
116
self .device_combo .currentTextChanged .connect (lambda : self .update_quantization (self .device_combo , self .quantization_combo ))
130
117
self .update_quantization (self .device_combo , self .quantization_combo )
@@ -166,11 +153,8 @@ def update_config(self, file_to_transcribe=None, **kwargs):
166
153
167
154
def start_transcription (self ):
168
155
if self .selected_audio_file :
169
- # Create an instance of the TranscribeFile class
170
156
transcriber = TranscribeFile ()
171
- # Create a QThread object and move the transcriber to it
172
157
self .transcription_thread = TranscriptionThread (transcriber )
173
- # Start the thread which will call the run method
174
158
self .transcription_thread .start ()
175
159
else :
176
160
print ("Please select an audio file first." )
0 commit comments