Skip to content

Commit

Permalink
refactor: transfer dashes removal from text into a separate method
Browse files Browse the repository at this point in the history
  • Loading branch information
MrPandir committed Mar 14, 2024
1 parent 0ef850f commit 766f0ff
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions tts/tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def generate(self, text: str, speaker: str, sample_rate: int) -> bytes:
if sample_rate not in self.VALID_SAMPLE_RATES:
raise InvalidSampleRateException(sample_rate)

text = self._delete_dashes(text)
return self._generate_audio(model, text, speaker, sample_rate)

def _load_model(self, model_path: Path):
Expand All @@ -61,14 +62,15 @@ def _load_speakers(self, model: "TTSModelMultiAcc_v3", language: str):
self.speakers[language] = model.speakers
for speaker in model.speakers:
self.model_by_speaker[speaker] = model

def _delete_dashes(self, text: str) -> str:
# This fixes the problem:
# https://github.com/twirapp/silero-tts-api-server/issues/8
return text.replace("-", "").replace("‑", "")

def _generate_audio(
self, model: "TTSModelMultiAcc_v3", text: str, speaker: str, sample_rate: int
) -> bytes:
# This fixes the problem:
# https://github.com/twirapp/silero-tts-api-server/issues/8
text = text.replace("-", "").replace("‑", "")

try:
audio: torch.Tensor = model.apply_tts(text=text, speaker=speaker, sample_rate=sample_rate)
except ValueError:
Expand Down

0 comments on commit 766f0ff

Please sign in to comment.