Skip to content

Commit

Permalink
Add improved language mapping for the UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Darwinkel committed Mar 16, 2024
1 parent b9ae3e7 commit f8c2a6e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
26 changes: 4 additions & 22 deletions shepardtts/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from . import settings
from .app_helpers import description, examples, links
from .utils import load_checkpoint, normalize_line
from .utils import language2id, load_checkpoint, normalize_line

MODEL = load_checkpoint()

Expand Down Expand Up @@ -51,7 +51,7 @@ def get_speaker_embeddings() -> tuple[dict[str, torch.Tensor], dict[str, torch.T
def predict(
prompt: str,
character: str,
language: str = "en",
language: str = "English",
codec_format: str = "ogg",
top_k: float = 30.0,
top_p: float = 0.5,
Expand Down Expand Up @@ -88,7 +88,7 @@ def predict(

out = MODEL.inference(
text=normalize_line(prompt),
language=language,
language=language2id()[language],
gpt_cond_latent=character_gpt_cond_latent,
speaker_embedding=character_speaker_embedding,
top_k=int(top_k),
Expand Down Expand Up @@ -170,25 +170,7 @@ def main() -> None:
language_gr = gr.Dropdown(
label="Language",
info="Select the language to be used by the model.",
choices=[
"en",
"es",
"fr",
"de",
"it",
"pt",
"pl",
"tr",
"ru",
"nl",
"cs",
"ar",
"zh-cn",
"ja",
"ko",
"hu",
"hi",
],
choices=language2id().keys(),
multiselect=False,
value="en",
)
Expand Down
23 changes: 23 additions & 0 deletions shepardtts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,26 @@ def normalize_numbers(string: str) -> str:
"""Normalize numbers in a string."""
# Required for when a comma is used inside a digit (one occurence in dataset)
return str(num2words(string.replace(",", "")))


def language2id() -> dict[str, str]:
"""Convert language choice to its Xttsv2 code."""
return {
"English": "en",
"Spanish": "es",
"French": "fr",
"German": "de",
"Italian": "it",
"Portugese": "pt",
"Polish": "pl",
"Turkish": "tr",
"Russian": "ru",
"Dutch": "nl",
"Czech": "cs",
"Arabic": "ar",
"Chinese": "zh-cn",
"Japanese": "ja",
"Korean": "ko",
"Hungarian": "hu",
"Hindi": "hi",
}

0 comments on commit f8c2a6e

Please sign in to comment.