Skip to content

Commit be928c8

Browse files
authored
Merge pull request #180 from yjg30737/hotfix/all
Refactoring, move edge-tts binary file to configuration directory for…
2 parents 77d3b09 + 0c0af84 commit be928c8

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

pyqt_openai/__init__.py

+16-14
Original file line numberDiff line numberDiff line change
@@ -76,23 +76,25 @@ def get_config_directory():
7676

7777
return config_dir
7878

79+
BIN_DIR = get_config_directory()
7980

80-
UPDATE_DIR = get_config_directory()
81+
UPDATER_NAME = "Updater.exe" if sys.platform == "win32" else "Updater"
82+
EDGE_TTS_NAME = "edge-tts.exe" if sys.platform == "win32" else "edge-tts"
8183

8284
# The default updater path (relative to the application's root directory) - For Windows
83-
UPDATER_PATH = os.path.join(UPDATE_DIR, "Updater.exe")
84-
85-
86-
# Move the Updater.exe to the config folder
87-
def move_updater():
88-
original_updater_path = os.path.join(ROOT_DIR, "Updater.exe")
89-
if os.path.exists(original_updater_path):
90-
if os.path.exists(UPDATER_PATH):
91-
os.remove(UPDATER_PATH)
92-
shutil.move(original_updater_path, UPDATER_PATH)
93-
94-
95-
move_updater()
85+
UPDATER_PATH = os.path.join(BIN_DIR, UPDATER_NAME)
86+
EDGE_TTS_PATH = os.path.join(BIN_DIR, EDGE_TTS_NAME)
87+
88+
# Move the binary file to the config folder to prevent "file not found" error
89+
def move_bin(filename, dst_dir):
90+
original_path = os.path.join(ROOT_DIR, filename)
91+
if os.path.exists(original_path):
92+
if os.path.exists(dst_dir):
93+
os.remove(dst_dir)
94+
shutil.move(original_path, dst_dir)
95+
96+
move_bin(UPDATER_NAME, UPDATER_PATH)
97+
move_bin(EDGE_TTS_NAME, EDGE_TTS_PATH)
9698

9799
CONTACT = "yjg30737@gmail.com"
98100
APP_INITIAL_WINDOW_SIZE = (1280, 768)

pyqt_openai/updateSoftwareDialog.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
__version__,
1717
OWNER,
1818
PACKAGE_NAME,
19-
UPDATE_DIR,
19+
BIN_DIR,
2020
CURRENT_FILENAME,
2121
UPDATER_PATH,
2222
is_frozen,
@@ -143,7 +143,7 @@ def update_software():
143143
def run_updater(update_url):
144144
if sys.platform == "win32":
145145
subprocess.Popen(
146-
[UPDATER_PATH, update_url, UPDATE_DIR, CURRENT_FILENAME], shell=True
146+
[UPDATER_PATH, update_url, BIN_DIR, CURRENT_FILENAME], shell=True
147147
)
148148
sys.exit(0)
149149
pass

pyqt_openai/util/script.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
OPENAI_CHAT_ENDPOINT,
6666
STT_MODEL,
6767
DEFAULT_DATETIME_FORMAT,
68-
DEFAULT_TOKEN_CHUNK_SIZE,
68+
DEFAULT_TOKEN_CHUNK_SIZE, EDGE_TTS_PATH,
6969
)
7070
from pyqt_openai.config_loader import CONFIG_MANAGER
7171
from pyqt_openai.globals import (
@@ -1158,10 +1158,12 @@ def run(self):
11581158
print(f"Media file: {mp3_fname}")
11591159
print(f"Subtitle file: {vtt_fname}\n")
11601160

1161+
_edge_tts_path = "edge-tts" if not is_frozen() else EDGE_TTS_PATH
1162+
11611163
if sys.platform == "win32":
11621164
with subprocess.Popen(
11631165
[
1164-
"edge-tts",
1166+
_edge_tts_path,
11651167
f"--write-media={mp3_fname}",
11661168
f"--write-subtitles={vtt_fname}",
11671169
f"--voice={self.input_args['voice']}",
@@ -1173,7 +1175,7 @@ def run(self):
11731175
else:
11741176
with subprocess.Popen(
11751177
[
1176-
"edge-tts",
1178+
_edge_tts_path,
11771179
f"--write-media={mp3_fname}",
11781180
f"--write-subtitles={vtt_fname}",
11791181
f"--voice={self.input_args['voice']}",

0 commit comments

Comments
 (0)