Skip to content

Commit

Permalink
add the languages support
Browse files Browse the repository at this point in the history
bump to 0.0.6
  • Loading branch information
neurlang authored and Your Name committed Oct 1, 2024
1 parent d0101c7 commit ccc6633
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 4 deletions.
3 changes: 3 additions & 0 deletions pygoruut/pygoruut.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from dataclasses import dataclass
from typing import List
from pygoruut.executable import MyPlatformExecutable
from pygoruut.pygoruut_languages import PygoruutLanguages
from pygoruut.config import Config
import tempfile

Expand Down Expand Up @@ -61,6 +62,8 @@ def __del__(self):
self.process.wait()

def phonemize(self, language="Greek", sentence="Σήμερα...") -> PhonemeResponse:
# handle ISO here
language = PygoruutLanguages()[language]
url = self.config.url("tts/phonemize/sentence")
payload = {"Language": language, "Sentence": sentence}

Expand Down
72 changes: 72 additions & 0 deletions pygoruut/pygoruut_languages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
class PygoruutLanguages:
def __init__(self):
# ISO 639 language codes and their corresponding languages
self.languagesISO639 = {
"ar": "Arabic",
"bn": "Bengali",
"zh": "ChineseMandarin",
"cs": "Czech",
"nl": "Dutch",
"en": "English",
"eo": "Esperanto",
"fa": "Farsi",
"fi": "Finnish",
"fr": "French",
"de": "German",
"el": "Greek",
"gu": "Gujarati",
"hi": "Hindi",
"hu": "Hungarian",
"is": "Icelandic",
"it": "Italian",
"jam": "Jamaican",
"ja": "Japanese",
"lb": "Luxembourgish",
"ms": "MalayLatin",
"mr": "Marathi",
"no": "Norwegian",
"pl": "Polish",
"pt": "Portuguese",
"pa": "Punjabi",
"ro": "Romanian",
"ru": "Russian",
"sk": "Slovak",
"es": "Spanish",
"sw": "Swahili",
"sv": "Swedish",
"ta": "Tamil",
"te": "Telugu",
"tr": "Turkish",
"uk": "Ukrainian",
"ur": "Urdu",
"vi": "VietnameseNorthern"
}

# Non-ISO 639 language or dialect names
self.languagesNonISO639 = [
"BengaliDhaka",
"BengaliRahr",
"Isan",
"MalayArab",
"VietnameseCentral",
"VietnameseSouthern"
]

def get_supported_languages(self):
# Concatenate the keys of languagesISO639 with the values of languagesNonISO639
return list(self.languagesISO639.keys()) + self.languagesNonISO639

def get_all_supported_languages(self):
# Concatenate the keys and values of languagesISO639 with the values of languagesNonISO639
return list(self.languagesISO639.keys()) + list(self.languagesISO639.values()) + self.languagesNonISO639

def __getitem__(self, value):
if len(value) == 2 or len(value) == 3:
value = self.languagesISO639[value] or value
return value

# Example usage:
if __name__ == '__main__':
pygoruut = PygoruutLanguages()
print(pygoruut.get_supported_languages())
print(pygoruut["vi"])
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "pygoruut"
version = "0.0.5"
version = "0.0.6"
description = "A Python wrapper for the goruut phonemization tool"
readme = "README.md"
authors = [{ name = "Neurlang Project", email = "[email protected]" }]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="pygoruut",
version="0.0.5",
version="0.0.6",
packages=find_packages(),
install_requires=[
"requests",
Expand Down
4 changes: 2 additions & 2 deletions tests/test_pygoruut_sanity.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def tearDown(self):

def test_languages_and_word_pairs(self):
test_cases = [
("Greek", [
("el", [
("Σήμερα", "sime̞ɾɐ"),
("καλημέρα", "kalime̞ɾa"),
("ευχαριστώ", "e̞fxaɾisto")
Expand All @@ -26,7 +26,7 @@ def test_languages_and_word_pairs(self):
("mundo", "mundo"),
("gracias", "gɾakias")
]),
("French", [
("fr", [
("bonjour", "bonʒuʁ"),
("monde", "mod"),
("merci", "mɛʁki")
Expand Down

0 comments on commit ccc6633

Please sign in to comment.