Skip to content
This repository has been archived by the owner on Nov 30, 2023. It is now read-only.

Commit

Permalink
Update gTTS; fix failing unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jdlorimer committed Mar 29, 2021
1 parent 94d0eb7 commit cb3846d
Show file tree
Hide file tree
Showing 21 changed files with 840 additions and 134 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

PROJECT_SHORT = chinese
PROJECT_LONG = chinese-support-redux
VERSION = 0.14.0
VERSION = 0.14.2
XDG_DATA_HOME ?= $(HOME)/.local/share
ADDON_PATH = "$(XDG_DATA_HOME)/Anki2/addons21/$(PROJECT_LONG)"
ZIP_NAME = $(PROJECT_LONG)-v$(VERSION).zip
Expand Down
2 changes: 1 addition & 1 deletion chinese/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.14.0'
__version__ = '0.14.2'
1 change: 1 addition & 0 deletions chinese/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def showAbout():
contributors = [
'Alex Griffin',
'Chris Hatch',
'Joe Minicucci',
'Roland Sieker',
'Thomas TEMPÉ',
]
Expand Down
4 changes: 2 additions & 2 deletions chinese/config.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"firstRun": true,
"version": "0.14.0",
"version": "0.14.2",
"enabledModels": [],
"speech": "google|zh-cn",
"speech": "google|zh-CN",
"target": "pinyin",
"max_examples": -1,
"fields": {
Expand Down
4 changes: 2 additions & 2 deletions chinese/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@

SPEECH_ENGINES = {
'Baidu Translate': 'baidu|zh',
'Google Mandarin (PRC)': 'google|zh-cn',
'Google Mandarin (Taiwan)': 'google|zh-tw',
'Google Mandarin (PRC)': 'google|zh-CN',
'Google Mandarin (Taiwan)': 'google|zh-TW',
'Amazon Polly' : 'aws|Zhiyu',
'Disabled': None,
}
Expand Down
151 changes: 53 additions & 98 deletions chinese/lib/gtts/lang.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
from gtts.langs import _main_langs
from warnings import warn
import logging

__all__ = ['tts_langs']
Expand All @@ -14,13 +16,13 @@ def tts_langs():
Returns:
dict: A dictionary of the type `{ '<lang>': '<name>'}`
Where `<lang>` is an IETF language tag such as `en` or `pt-br`,
Where `<lang>` is an IETF language tag such as `en` or `zh-TW`,
and `<name>` is the full English name of the language, such as
`English` or `Portuguese (Brazil)`.
`English` or `Chinese (Mandarin/Taiwan)`.
The dictionary returned combines languages from two origins:
- Languages fetched from Google Translate
- Languages fetched from Google Translate (pre-generated in :mod:`gtts.langs`)
- Languages that are undocumented variations that were observed to work and
present different dialects or accents.
Expand All @@ -32,112 +34,65 @@ def tts_langs():
return langs


def _main_langs():
"""Define the main languages.
def _extra_langs():
"""Define extra languages.
Returns:
dict: A dictionnary of the main languages extracted from
Google Translate.
dict: A dictionnary of extra languages manually defined.
Variations of the ones generated in `_main_langs`,
observed to provide different dialects or accents or
just simply accepted by the Google Translate Text-to-Speech API.
"""
return {
'af': 'Afrikaans',
'ar': 'Arabic',
'bn': 'Bengali',
'bs': 'Bosnian',
'ca': 'Catalan',
'cs': 'Czech',
'cy': 'Welsh',
'da': 'Danish',
'de': 'German',
'el': 'Greek',
'en': 'English',
'eo': 'Esperanto',
'es': 'Spanish',
'et': 'Estonian',
'fi': 'Finnish',
'fr': 'French',
'gu': 'Gujarati',
'hi': 'Hindi',
'hr': 'Croatian',
'hu': 'Hungarian',
'hy': 'Armenian',
'id': 'Indonesian',
'is': 'Icelandic',
'it': 'Italian',
'ja': 'Japanese',
'jw': 'Javanese',
'km': 'Khmer',
'kn': 'Kannada',
'ko': 'Korean',
'la': 'Latin',
'lv': 'Latvian',
'mk': 'Macedonian',
'ml': 'Malayalam',
'mr': 'Marathi',
'my': 'Myanmar (Burmese)',
'ne': 'Nepali',
'nl': 'Dutch',
'no': 'Norwegian',
'pl': 'Polish',
'pt': 'Portuguese',
'ro': 'Romanian',
'ru': 'Russian',
'si': 'Sinhala',
'sk': 'Slovak',
'sq': 'Albanian',
'sr': 'Serbian',
'su': 'Sundanese',
'sv': 'Swedish',
'sw': 'Swahili',
'ta': 'Tamil',
'te': 'Telugu',
'th': 'Thai',
'tl': 'Filipino',
'tr': 'Turkish',
'uk': 'Ukrainian',
'ur': 'Urdu',
'vi': 'Vietnamese',
'zh-CN': 'Chinese'
# Chinese
'zh-TW': 'Chinese (Mandarin/Taiwan)',
'zh': 'Chinese (Mandarin)'
}


def _extra_langs():
"""Define extra languages.
def _fallback_deprecated_lang(lang):
"""Languages Google Text-to-Speech used to support.
Language tags that don't work anymore, but that can
fallback to a more general language code to maintain
compatibility.
Args:
lang (string): The language tag.
Returns:
dict: A dictionnary of extra languages manually defined.
string: The language tag, as-is if not deprecated,
or a fallack if it exits.
Variations of the ones fetched by `_main_langs`,
observed to provide different dialects or accents or
just simply accepted by the Google Translate Text-to-Speech API.
Example:
``en-GB`` returns ``en``.
``en-gb`` returns ``en``.
"""
return {
# Chinese
'zh-cn': 'Chinese (Mandarin/China)',
'zh-tw': 'Chinese (Mandarin/Taiwan)',
# English
'en-us': 'English (US)',
'en-ca': 'English (Canada)',
'en-uk': 'English (UK)',
'en-gb': 'English (UK)',
'en-au': 'English (Australia)',
'en-gh': 'English (Ghana)',
'en-in': 'English (India)',
'en-ie': 'English (Ireland)',
'en-nz': 'English (New Zealand)',
'en-ng': 'English (Nigeria)',
'en-ph': 'English (Philippines)',
'en-za': 'English (South Africa)',
'en-tz': 'English (Tanzania)',
# French
'fr-ca': 'French (Canada)',
'fr-fr': 'French (France)',
# Portuguese
'pt-br': 'Portuguese (Brazil)',
'pt-pt': 'Portuguese (Portugal)',
# Spanish
'es-es': 'Spanish (Spain)',
'es-us': 'Spanish (United States)'

deprecated = {
# '<fallback>': [<list of deprecated langs>]
'en': ['en-us', 'en-ca', 'en-uk', 'en-gb', 'en-au', 'en-gh', 'en-in',
'en-ie', 'en-nz', 'en-ng', 'en-ph', 'en-za', 'en-tz'],
'fr': ['fr-ca', 'fr-fr'],
'pt': ['pt-br', 'pt-pt'],
'es': ['es-es', 'es-us'],
'zh-CN': ['zh-cn'],
'zh-TW': ['zh-tw'],
}

for fallback_lang, deprecated_langs in deprecated.items():
if lang.lower() in deprecated_langs:
msg = (
"'{}' has been deprecated, falling back to '{}'. "
"This fallback will be removed in a future version."
).format(lang, fallback_lang)

warn(msg, DeprecationWarning)
log.warning(msg)

return fallback_lang

return lang
64 changes: 64 additions & 0 deletions chinese/lib/gtts/langs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Note: this file is generated
_langs = {
"af": "Afrikaans",
"ar": "Arabic",
"bn": "Bengali",
"bs": "Bosnian",
"ca": "Catalan",
"cs": "Czech",
"cy": "Welsh",
"da": "Danish",
"de": "German",
"el": "Greek",
"en": "English",
"eo": "Esperanto",
"es": "Spanish",
"et": "Estonian",
"fi": "Finnish",
"fr": "French",
"gu": "Gujarati",
"hi": "Hindi",
"hr": "Croatian",
"hu": "Hungarian",
"hy": "Armenian",
"id": "Indonesian",
"is": "Icelandic",
"it": "Italian",
"ja": "Japanese",
"jw": "Javanese",
"km": "Khmer",
"kn": "Kannada",
"ko": "Korean",
"la": "Latin",
"lv": "Latvian",
"mk": "Macedonian",
"ml": "Malayalam",
"mr": "Marathi",
"my": "Myanmar (Burmese)",
"ne": "Nepali",
"nl": "Dutch",
"no": "Norwegian",
"pl": "Polish",
"pt": "Portuguese",
"ro": "Romanian",
"ru": "Russian",
"si": "Sinhala",
"sk": "Slovak",
"sq": "Albanian",
"sr": "Serbian",
"su": "Sundanese",
"sv": "Swedish",
"sw": "Swahili",
"ta": "Tamil",
"te": "Telugu",
"th": "Thai",
"tl": "Filipino",
"tr": "Turkish",
"uk": "Ukrainian",
"ur": "Urdu",
"vi": "Vietnamese",
"zh-CN": "Chinese"
}

def _main_langs():
return _langs
Empty file.
2 changes: 2 additions & 0 deletions chinese/lib/gtts/tests/input_files/test_cli_test_ascii.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Can you make pink a little more pinkish can you make pink a little more pinkish, nor can you make the font bigger?
How much will it cost the website doesn't have the theme i was going for.
5 changes: 5 additions & 0 deletions chinese/lib/gtts/tests/input_files/test_cli_test_utf8.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
这是一个三岁的小孩
在讲述她从一系列照片里看到的东西。
对这个世界, 她也许还有很多要学的东西,
但在一个重要的任务上, 她已经是专家了:
去理解她所看到的东西。
Loading

0 comments on commit cb3846d

Please sign in to comment.