Skip to content

Commit

Permalink
add split/limit segment for file import #44
Browse files Browse the repository at this point in the history
- fix tsv saving
- move the export format to its own page
- move the hacky unicode to constant variable
- separate setting to show audio visualizer for record and setting
- translated words now match the way its supposed to be originally (the spacing should be in front not in the back)
  • Loading branch information
Dadangdut33 committed Nov 27, 2023
1 parent 84c69f6 commit bad46b0
Show file tree
Hide file tree
Showing 14 changed files with 740 additions and 488 deletions.
1 change: 1 addition & 0 deletions speech_translate/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
MIN_THRESHOLD = -61
MAX_THRESHOLD = 1
LOG_FORMAT = '<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green> | <level>{level: <7}</level> | <cyan>{file}</cyan>:<cyan>{line}</cyan> [{thread.name}] - <level>{message}</level>'
HACKY_SPACE = "‎" # a empty character that is not empty # can be used when needing to replace a character with a space or something alike
2 changes: 2 additions & 0 deletions speech_translate/ui/custom/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ def cbtn_task_change(self):
pass

def add_data(self):
self.disable_interactions()
files = filedialog.askopenfilenames(
title="Select a file",
filetypes=(
Expand All @@ -366,6 +367,7 @@ def add_data(self):
("All files", "*.*"),
),
)
self.enable_interactions()

if len(files) == 0:
return
Expand Down
509 changes: 509 additions & 0 deletions speech_translate/ui/frame/setting/export.py

Large diffs are not rendered by default.

27 changes: 20 additions & 7 deletions speech_translate/ui/frame/setting/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,30 @@ def __init__(self, root: Toplevel, master_frame: Union[ttk.Frame, Frame]):
self.cbtn_update_on_start.pack(side="left", padx=5, pady=5)
tk_tooltip(self.cbtn_update_on_start, "Check for app update on start.")

self.cbtn_show_audio_visualizer = CustomCheckButton(
self.cbtn_show_audio_visualizer_in_record = CustomCheckButton(
self.f_application_1,
sj.cache["show_audio_visualizer"],
lambda x: sj.save_key("show_audio_visualizer", x),
text="Show audio visualizer",
sj.cache["show_audio_visualizer_in_record"],
lambda x: sj.save_key("show_audio_visualizer_in_record", x),
text="Show audio visualizer (record)",
style="Switch.TCheckbutton"
)
self.cbtn_show_audio_visualizer.pack(side="left", padx=5, pady=5)
self.cbtn_show_audio_visualizer_in_record.pack(side="left", padx=5, pady=5)
tk_tooltip(
self.cbtn_show_audio_visualizer,
"Show audio visualizer when recording and in the record setting window.\n\nDisabling could improve performance."
self.cbtn_show_audio_visualizer_in_record,
"Show audio visualizer when recording in the recording modal window.\n\nDisabling could improve performance."
)

self.cbtn_show_audio_visualizer_in_setting = CustomCheckButton(
self.f_application_1,
sj.cache["show_audio_visualizer_in_setting"],
lambda x: sj.save_key("show_audio_visualizer_in_setting", x),
text="Show audio visualizer (setting)",
style="Switch.TCheckbutton"
)
self.cbtn_show_audio_visualizer_in_setting.pack(side="left", padx=5, pady=5)
tk_tooltip(
self.cbtn_show_audio_visualizer_in_setting,
"Show audio visualizer in the setting -> record page.\n\nDisabling could improve performance."
)

self.cbtn_supress_hidden_to_tray = CustomCheckButton(
Expand Down
60 changes: 41 additions & 19 deletions speech_translate/ui/frame/setting/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def __init__(self, root: Toplevel, master_frame: Union[ttk.Frame, Frame]):
self.f_mic_recording_2.pack(side="top", fill="x", pady=5, padx=5)

self.f_mic_recording_3 = ttk.Frame(self.lf_mic_recording)
self.f_mic_recording_3.pack(side="top", fill="x", pady=(5, 0), padx=5)
self.f_mic_recording_3.pack(side="top", fill="x", pady=(5, 3), padx=5)

self.f_mic_recording_4 = ttk.Frame(self.lf_mic_recording)
self.f_mic_recording_4.pack(side="top", fill="x", pady=(10, 5), padx=5)
Expand Down Expand Up @@ -432,6 +432,11 @@ def __init__(self, root: Toplevel, master_frame: Union[ttk.Frame, Frame]):
style="Switch.TCheckbutton"
)
self.cbtn_threshold_enable_mic.pack(side="left", padx=5)
tk_tooltip(
self.cbtn_threshold_enable_mic,
"If checked, input will need to reach the threshold before it is considered as an input."
"\n\nDefault is checked",
)

self.cbtn_threshold_auto_mic = CustomCheckButton(
self.f_mic_recording_3,
Expand All @@ -441,7 +446,10 @@ def __init__(self, root: Toplevel, master_frame: Union[ttk.Frame, Frame]):
style="Switch.TCheckbutton"
)
self.cbtn_threshold_auto_mic.pack(side="left", padx=5)
tk_tooltip(self.cbtn_threshold_auto_mic, "Default is checked")
tk_tooltip(
self.cbtn_threshold_auto_mic,
"Wether to use VAD or manual threshold for the speaker input.\n\nDefault is checked"
)

self.cbtn_auto_break_buffer_mic = CustomCheckButton(
self.f_mic_recording_3,
Expand All @@ -453,7 +461,7 @@ def __init__(self, root: Toplevel, master_frame: Union[ttk.Frame, Frame]):
self.cbtn_auto_break_buffer_mic.pack(side="left", padx=5)
tk_tooltip(
self.cbtn_auto_break_buffer_mic,
"If checked, the buffer will be stopped and considered as 1 full sentence when there is silence detected. "
"If checked, the buffer will be stopped and considered as 1 full sentence when there is silence detected for more than 1 second. "
"This could help in reducing the background noise."
"\n\nDefault is checked",
)
Expand Down Expand Up @@ -530,7 +538,7 @@ def __init__(self, root: Toplevel, master_frame: Union[ttk.Frame, Frame]):
self.f_speaker_recording_2.pack(side="top", fill="x", pady=5, padx=5)

self.f_speaker_recording_3 = ttk.Frame(self.lf_speaker_recording)
self.f_speaker_recording_3.pack(side="top", fill="x", pady=(5, 0), padx=5)
self.f_speaker_recording_3.pack(side="top", fill="x", pady=(5, 3), padx=5)

self.f_speaker_recording_4 = ttk.Frame(self.lf_speaker_recording)
self.f_speaker_recording_4.pack(side="top", fill="x", pady=(10, 5), padx=5)
Expand Down Expand Up @@ -595,6 +603,11 @@ def __init__(self, root: Toplevel, master_frame: Union[ttk.Frame, Frame]):
style="Switch.TCheckbutton"
)
self.cbtn_threshold_enable_speaker.pack(side="left", padx=5)
tk_tooltip(
self.cbtn_threshold_enable_speaker,
"If checked, input will need to reach the threshold before it is considered as an input."
"\n\nDefault is checked",
)

self.cbtn_threshold_auto_speaker = CustomCheckButton(
self.f_speaker_recording_3,
Expand All @@ -606,7 +619,7 @@ def __init__(self, root: Toplevel, master_frame: Union[ttk.Frame, Frame]):
self.cbtn_threshold_auto_speaker.pack(side="left", padx=5)
tk_tooltip(
self.cbtn_threshold_auto_speaker,
"Default is checked",
"Wether to use VAD or manual threshold for the speaker input.\n\nDefault is checked"
)

self.cbtn_auto_break_buffer_speaker = CustomCheckButton(
Expand All @@ -617,6 +630,12 @@ def __init__(self, root: Toplevel, master_frame: Union[ttk.Frame, Frame]):
style="Switch.TCheckbutton"
)
self.cbtn_auto_break_buffer_speaker.pack(side="left", padx=5)
tk_tooltip(
self.cbtn_auto_break_buffer_speaker,
"If checked, the buffer will be stopped and considered as 1 full sentence when there is silence detected for more than 1 second. "
"This could help in reducing the background noise."
"\n\nDefault is checked",
)

self.lbl_hint_threshold_speaker = ttk.Label(self.f_speaker_recording_3, image=bc.help_emoji, compound="left")
self.lbl_hint_threshold_speaker.pack(side="left", padx=5)
Expand Down Expand Up @@ -783,22 +802,25 @@ def call_both_with_wait(self, open=True):
if self.on_start:
return

if not sj.cache["show_audio_visualizer"]:
return

mic = Thread(target=self.call_set_meter_mic, daemon=True, args=[open])
mic.start()
mic.join()
if not sj.cache["show_audio_visualizer_in_setting"]:
self.close_meter_mic()
else:
mic = Thread(target=self.call_set_meter_mic, daemon=True, args=[open])
mic.start()
mic.join()

if system() == "Windows":
# wait for 1 second to prevent error
sleep(1)

# for some reason, if the speaker is called right after the mic, it will not work properly
# it will fail to catch any loopback and will crash the program completely
speaker = Thread(target=self.call_set_meter_speaker, daemon=True, args=[open])
speaker.start()
speaker.join()
# so we wait for 1 second to prevent error
sleep(1)

if not sj.cache["show_audio_visualizer_in_setting"]:
self.close_meter_speaker()
else:
speaker = Thread(target=self.call_set_meter_speaker, daemon=True, args=[open])
speaker.start()
speaker.join()

# ---- Mic & Speaker ----
def slider_mic_move(self, event):
Expand Down Expand Up @@ -866,7 +888,7 @@ def call_set_meter_mic(self, open=True):
if self.on_start:
return

if not sj.cache["show_audio_visualizer"]:
if not sj.cache["show_audio_visualizer_in_setting"]:
self.close_meter_mic()
return

Expand Down Expand Up @@ -943,7 +965,7 @@ def set_meter_mic(self, open=True):

def call_set_meter_speaker(self, open=True):
if system() == "Windows" and not self.on_start:
if not sj.cache["show_audio_visualizer"]:
if not sj.cache["show_audio_visualizer_in_setting"]:
self.close_meter_speaker()
return

Expand Down
Loading

0 comments on commit bad46b0

Please sign in to comment.