Skip to content

Commit

Permalink
Merge pull request #180 from yjg30737/hotfix/all
Browse files Browse the repository at this point in the history
Refactoring, move edge-tts binary file to configuration directory for…
  • Loading branch information
yjg30737 authored Nov 1, 2024
2 parents 77d3b09 + 0c0af84 commit be928c8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
30 changes: 16 additions & 14 deletions pyqt_openai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,25 @@ def get_config_directory():

return config_dir

BIN_DIR = get_config_directory()

UPDATE_DIR = get_config_directory()
UPDATER_NAME = "Updater.exe" if sys.platform == "win32" else "Updater"
EDGE_TTS_NAME = "edge-tts.exe" if sys.platform == "win32" else "edge-tts"

# The default updater path (relative to the application's root directory) - For Windows
UPDATER_PATH = os.path.join(UPDATE_DIR, "Updater.exe")


# Move the Updater.exe to the config folder
def move_updater():
original_updater_path = os.path.join(ROOT_DIR, "Updater.exe")
if os.path.exists(original_updater_path):
if os.path.exists(UPDATER_PATH):
os.remove(UPDATER_PATH)
shutil.move(original_updater_path, UPDATER_PATH)


move_updater()
UPDATER_PATH = os.path.join(BIN_DIR, UPDATER_NAME)
EDGE_TTS_PATH = os.path.join(BIN_DIR, EDGE_TTS_NAME)

# Move the binary file to the config folder to prevent "file not found" error
def move_bin(filename, dst_dir):
original_path = os.path.join(ROOT_DIR, filename)
if os.path.exists(original_path):
if os.path.exists(dst_dir):
os.remove(dst_dir)
shutil.move(original_path, dst_dir)

move_bin(UPDATER_NAME, UPDATER_PATH)
move_bin(EDGE_TTS_NAME, EDGE_TTS_PATH)

CONTACT = "[email protected]"
APP_INITIAL_WINDOW_SIZE = (1280, 768)
Expand Down
4 changes: 2 additions & 2 deletions pyqt_openai/updateSoftwareDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
__version__,
OWNER,
PACKAGE_NAME,
UPDATE_DIR,
BIN_DIR,
CURRENT_FILENAME,
UPDATER_PATH,
is_frozen,
Expand Down Expand Up @@ -143,7 +143,7 @@ def update_software():
def run_updater(update_url):
if sys.platform == "win32":
subprocess.Popen(
[UPDATER_PATH, update_url, UPDATE_DIR, CURRENT_FILENAME], shell=True
[UPDATER_PATH, update_url, BIN_DIR, CURRENT_FILENAME], shell=True
)
sys.exit(0)
pass
8 changes: 5 additions & 3 deletions pyqt_openai/util/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
OPENAI_CHAT_ENDPOINT,
STT_MODEL,
DEFAULT_DATETIME_FORMAT,
DEFAULT_TOKEN_CHUNK_SIZE,
DEFAULT_TOKEN_CHUNK_SIZE, EDGE_TTS_PATH,
)
from pyqt_openai.config_loader import CONFIG_MANAGER
from pyqt_openai.globals import (
Expand Down Expand Up @@ -1158,10 +1158,12 @@ def run(self):
print(f"Media file: {mp3_fname}")
print(f"Subtitle file: {vtt_fname}\n")

_edge_tts_path = "edge-tts" if not is_frozen() else EDGE_TTS_PATH

if sys.platform == "win32":
with subprocess.Popen(
[
"edge-tts",
_edge_tts_path,
f"--write-media={mp3_fname}",
f"--write-subtitles={vtt_fname}",
f"--voice={self.input_args['voice']}",
Expand All @@ -1173,7 +1175,7 @@ def run(self):
else:
with subprocess.Popen(
[
"edge-tts",
_edge_tts_path,
f"--write-media={mp3_fname}",
f"--write-subtitles={vtt_fname}",
f"--voice={self.input_args['voice']}",
Expand Down

0 comments on commit be928c8

Please sign in to comment.