Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize silero_tts func and solve the dependencyes issue #104

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ pytchat
requests
torch
unidic
tensorboard==2.17.0
tensorboard-data-server==0.7.2
tensorflow==2.17.0
tensorflow-intel==2.17.0
tensorflow-io-gcs-filesystem==0.31.0
27 changes: 20 additions & 7 deletions utils/TTS.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,29 @@
import urllib.parse
from utils.katakana import *

num_threads = os.cpu_count()
device = torch.device('cpu')
torch.set_num_threads(num_threads)
local_file = 'model.pt'
print(f"Using {num_threads} threads for silero_tts")

cache_model = None
if os.path.isfile(local_file):
print("Loading model.pt with cache...")
cache_model = torch.package.PackageImporter(local_file).load_pickle("tts_models", "model")
cache_model.to(device)


# https://github.com/snakers4/silero-models#text-to-speech
def silero_tts(tts, language, model, speaker):
device = torch.device('cpu')
torch.set_num_threads(4)
local_file = 'model.pt'

if not os.path.isfile(local_file):
print("Downloading model.pt...")
torch.hub.download_url_to_file(f'https://models.silero.ai/models/tts/{language}/{model}.pt',
local_file)

model = torch.package.PackageImporter(local_file).load_pickle("tts_models", "model")
print("Loading model.pt...")
model = torch.package.PackageImporter(local_file).load_pickle("tts_models", "model")
else:
model = cache_model
model.to(device)

example_text = "i'm fine thank you and you?"
Expand All @@ -23,7 +35,8 @@ def silero_tts(tts, language, model, speaker):
audio_paths = model.save_wav(text=tts,
speaker=speaker,
sample_rate=sample_rate)



def voicevox_tts(tts):
# You need to run VoicevoxEngine.exe first before running this script

Expand Down