|
|
@ -49,17 +49,30 @@ class Tts:
|
|
|
|
PIPER_ASSETNAME = f"piper_{OS}_{ARCH}.tar.gz"
|
|
|
|
PIPER_ASSETNAME = f"piper_{OS}_{ARCH}.tar.gz"
|
|
|
|
PIPER_URL = "https://github.com/rhasspy/piper/releases/latest/download/"
|
|
|
|
PIPER_URL = "https://github.com/rhasspy/piper/releases/latest/download/"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if OS == "windows":
|
|
|
|
|
|
|
|
asset_url = f"{PIPER_URL}{PIPER_ASSETNAME}".replace(".tar.gz", ".zip")
|
|
|
|
|
|
|
|
|
|
|
|
# Download and extract Piper
|
|
|
|
# Download and extract Piper
|
|
|
|
urllib.request.urlretrieve(f"{PIPER_URL}{PIPER_ASSETNAME}", os.path.join(PIPER_FOLDER_PATH, PIPER_ASSETNAME))
|
|
|
|
urllib.request.urlretrieve(asset_url, os.path.join(PIPER_FOLDER_PATH, PIPER_ASSETNAME))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Extract the downloaded file
|
|
|
|
|
|
|
|
if OS == "windows":
|
|
|
|
|
|
|
|
import zipfile
|
|
|
|
|
|
|
|
with zipfile.ZipFile(os.path.join(PIPER_FOLDER_PATH, PIPER_ASSETNAME), 'r') as zip_ref:
|
|
|
|
|
|
|
|
zip_ref.extractall(path=PIPER_FOLDER_PATH)
|
|
|
|
|
|
|
|
else:
|
|
|
|
with tarfile.open(os.path.join(PIPER_FOLDER_PATH, PIPER_ASSETNAME), 'r:gz') as tar:
|
|
|
|
with tarfile.open(os.path.join(PIPER_FOLDER_PATH, PIPER_ASSETNAME), 'r:gz') as tar:
|
|
|
|
tar.extractall(path=PIPER_FOLDER_PATH)
|
|
|
|
tar.extractall(path=PIPER_FOLDER_PATH)
|
|
|
|
|
|
|
|
|
|
|
|
PIPER_VOICE_URL = os.getenv('PIPER_VOICE_URL', 'https://huggingface.co/rhasspy/piper-voices/resolve/main/en/en_US/lessac/medium/')
|
|
|
|
PIPER_VOICE_URL = os.getenv('PIPER_VOICE_URL',
|
|
|
|
|
|
|
|
'https://huggingface.co/rhasspy/piper-voices/resolve/main/en/en_US/lessac/medium/')
|
|
|
|
PIPER_VOICE_NAME = os.getenv('PIPER_VOICE_NAME', 'en_US-lessac-medium.onnx')
|
|
|
|
PIPER_VOICE_NAME = os.getenv('PIPER_VOICE_NAME', 'en_US-lessac-medium.onnx')
|
|
|
|
|
|
|
|
|
|
|
|
# Download voice model and its json file
|
|
|
|
# Download voice model and its json file
|
|
|
|
urllib.request.urlretrieve(f"{PIPER_VOICE_URL}{PIPER_VOICE_NAME}", os.path.join(self.piper_directory, PIPER_VOICE_NAME))
|
|
|
|
urllib.request.urlretrieve(f"{PIPER_VOICE_URL}{PIPER_VOICE_NAME}",
|
|
|
|
urllib.request.urlretrieve(f"{PIPER_VOICE_URL}{PIPER_VOICE_NAME}.json", os.path.join(self.piper_directory, f"{PIPER_VOICE_NAME}.json"))
|
|
|
|
os.path.join(self.piper_directory, PIPER_VOICE_NAME))
|
|
|
|
|
|
|
|
urllib.request.urlretrieve(f"{PIPER_VOICE_URL}{PIPER_VOICE_NAME}.json",
|
|
|
|
|
|
|
|
os.path.join(self.piper_directory, f"{PIPER_VOICE_NAME}.json"))
|
|
|
|
|
|
|
|
|
|
|
|
# Additional setup for macOS
|
|
|
|
# Additional setup for macOS
|
|
|
|
if OS == "macos":
|
|
|
|
if OS == "macos":
|
|
|
@ -68,15 +81,19 @@ class Tts:
|
|
|
|
|
|
|
|
|
|
|
|
PIPER_PHONEMIZE_ASSETNAME = f"piper-phonemize_{OS}_{ARCH}.tar.gz"
|
|
|
|
PIPER_PHONEMIZE_ASSETNAME = f"piper-phonemize_{OS}_{ARCH}.tar.gz"
|
|
|
|
PIPER_PHONEMIZE_URL = "https://github.com/rhasspy/piper-phonemize/releases/latest/download/"
|
|
|
|
PIPER_PHONEMIZE_URL = "https://github.com/rhasspy/piper-phonemize/releases/latest/download/"
|
|
|
|
urllib.request.urlretrieve(f"{PIPER_PHONEMIZE_URL}{PIPER_PHONEMIZE_ASSETNAME}", os.path.join(self.piper_directory, PIPER_PHONEMIZE_ASSETNAME))
|
|
|
|
urllib.request.urlretrieve(f"{PIPER_PHONEMIZE_URL}{PIPER_PHONEMIZE_ASSETNAME}",
|
|
|
|
|
|
|
|
os.path.join(self.piper_directory, PIPER_PHONEMIZE_ASSETNAME))
|
|
|
|
|
|
|
|
|
|
|
|
with tarfile.open(os.path.join(self.piper_directory, PIPER_PHONEMIZE_ASSETNAME), 'r:gz') as tar:
|
|
|
|
with tarfile.open(os.path.join(self.piper_directory, PIPER_PHONEMIZE_ASSETNAME), 'r:gz') as tar:
|
|
|
|
tar.extractall(path=self.piper_directory)
|
|
|
|
tar.extractall(path=self.piper_directory)
|
|
|
|
|
|
|
|
|
|
|
|
PIPER_DIR = self.piper_directory
|
|
|
|
PIPER_DIR = self.piper_directory
|
|
|
|
subprocess.run(['install_name_tool', '-change', '@rpath/libespeak-ng.1.dylib', f"{PIPER_DIR}/piper-phonemize/lib/libespeak-ng.1.dylib", f"{PIPER_DIR}/piper"])
|
|
|
|
subprocess.run(['install_name_tool', '-change', '@rpath/libespeak-ng.1.dylib',
|
|
|
|
subprocess.run(['install_name_tool', '-change', '@rpath/libonnxruntime.1.14.1.dylib', f"{PIPER_DIR}/piper-phonemize/lib/libonnxruntime.1.14.1.dylib", f"{PIPER_DIR}/piper"])
|
|
|
|
f"{PIPER_DIR}/piper-phonemize/lib/libespeak-ng.1.dylib", f"{PIPER_DIR}/piper"])
|
|
|
|
subprocess.run(['install_name_tool', '-change', '@rpath/libpiper_phonemize.1.dylib', f"{PIPER_DIR}/piper-phonemize/lib/libpiper_phonemize.1.dylib", f"{PIPER_DIR}/piper"])
|
|
|
|
subprocess.run(['install_name_tool', '-change', '@rpath/libonnxruntime.1.14.1.dylib',
|
|
|
|
|
|
|
|
f"{PIPER_DIR}/piper-phonemize/lib/libonnxruntime.1.14.1.dylib", f"{PIPER_DIR}/piper"])
|
|
|
|
|
|
|
|
subprocess.run(['install_name_tool', '-change', '@rpath/libpiper_phonemize.1.dylib',
|
|
|
|
|
|
|
|
f"{PIPER_DIR}/piper-phonemize/lib/libpiper_phonemize.1.dylib", f"{PIPER_DIR}/piper"])
|
|
|
|
|
|
|
|
|
|
|
|
print("Piper setup completed.")
|
|
|
|
print("Piper setup completed.")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|