diff --git a/docs/cli.rst b/docs/cli.rst index 39745a2..e3f8cda 100644 --- a/docs/cli.rst +++ b/docs/cli.rst @@ -1,12 +1,12 @@ -Command-line (:mod:`gtts-cli`) +Command-line (:mod:`t2s-cli`) ============================== -After installing the package, the ``gtts-cli`` tool becomes available:: +After installing the package, the ``t2s-cli`` tool becomes available:: $ gtts-cli -.. click:: gtts.cli:tts_cli - :prog: gtts-cli +.. click:: t2s.cli:tts_cli + :prog: t2s-cli :show-nested: Examples @@ -14,7 +14,7 @@ Examples List available languages:: - $ gtts-cli --all + $ t2s-cli --all Read 'hello' to ``hello.mp3``:: diff --git a/scripts/.gen_langs.py.swp b/scripts/.gen_langs.py.swp deleted file mode 100644 index 05372cf..0000000 Binary files a/scripts/.gen_langs.py.swp and /dev/null differ diff --git a/setup.cfg b/setup.cfg index 7acbddd..bc6606e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,100 +1,78 @@ [metadata] name = t2s -version = attr: t2s.__version__ -url = https://quo.rtfd.io -project_urls = - Donate = https://tinyurl.com/ygaj5fwj - Documentation = https://quo.rtfd.io - Changes = https://quo.readthedocs.io/en/latest/changes.html - Source Code = https://github.com/secretum-inc/quo - Issue Tracker = https://github.com/secretum-inc/quo/issues/ - Twitter = https://twitter.com/secretum_inc - Chat = https://gitter.im/secretum-inc -license = MIT -license_files = LICENSE +description = t2s(Text-to-Speech), a Python library and CLI tool to interface with Google Translate text-to-speech API author = Gerrishon Sirere -author_email = secretum.inc@pm.me -maintainer = Secretum Inc. -maintainer_email = secretum.inc@pm.me -description = Python based toolkit for writing Command-Line Interface applications +author_email = secretum-inc@pm.me +url = https://github.com/secretum-inc/t2s +license = MIT +keywords = + t2s + text to speech + Google Translate + T2S +classifiers = + Environment :: Console + Intended Audience :: Developers + License :: OSI Approved :: MIT License + Operating System :: MacOS + Operating System :: Unix + Operating System :: POSIX + Operating System :: POSIX :: Linux + Operating System :: Microsoft :: Windows + Programming Language :: Python :: 2.7 + Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 + Topic :: Software Development :: Libraries + Topic :: Multimedia :: Sound/Audio :: Speech +license_file = LICENSE long_description = file: README.md long_description_content_type = text/markdown -classifiers = - Development Status :: 5 - Production/Stable - Intended Audience :: Developers - License :: OSI Approved :: MIT License - Operating System :: OS Independent - Programming Language :: Python [options] +python_requires = >= 3.6 +include_package_data = True packages = find: -package_dir = = src -include_package_data = true -python_requires = >= 3.6.1 -# Dependencies are in setup.py for GitHub's dependency graph. +install_requires = + six + quo + requests -[options.packages.find] -where = src +[options.extras_require] +tests = + pytest == 4.6.11 + pytest-cov + flake8 + testfixtures + mock + six +docs = + sphinx + sphinx-autobuild + sphinx_rtd_theme + sphinx-click + towncrier -[tool:pytest] -testpaths = tests -filterwarnings = - error - -[coverage:run] -branch = true -source = - quo - tests - -[coverage:paths] -source = - quo - */site-packages +[options.entry_points] +console_scripts = + t2s-cli = t2s.cli:t2s_cli [flake8] -# B = bugbear -# E = pycodestyle errors -# F = flake8 pyflakes -# W = pycodestyle warnings -# B9 = bugbear opinions, -# ISC = implicit str concat -select = B, E, F, W, B9, ISC -ignore = - # slice notation whitespace, invalid - E203 - # line length, handled by bugbear B950 - E501 - # bare except, handled by bugbear B001 - E722 - # bin op line break, invalid - W503 -# up to 88 allowed by bugbear B950 -max-line-length = 80 -per-file-ignores = - # __init__ module exports names - src/quo/__init__.py: F401 +max-line-length = 132 +exclude = .git,__pycache__,.eggs/,doc/,docs/,build/,dist/,archive/ +ignore = W605, W503, W504 -[mypy] -files = src/quo -python_version = 3.6.1 -disallow_subclassing_any = True -disallow_untyped_calls = True -disallow_untyped_defs = True -disallow_incomplete_defs = True -check_untyped_defs = True -no_implicit_optional = True -local_partial_types = True -no_implicit_reexport = True -strict_equality = True -warn_redundant_casts = True -warn_unused_configs = True -warn_unused_ignores = True -warn_return_any = True -warn_unreachable = True - -[mypy-colorama.*] -ignore_missing_imports = True +[coverage:run] +cover_pylib = false +omit = + */site-packages/* + t2s/tests/* + t2s/tokenizer/tests/* -[mypy-importlib_metadata.*] -ignore_missing_imports = True +[coverage:report] +exclude_lines = + pragma: no cover + def __repr__ + log.debug + log.warning diff --git a/src/t2s/.__init__.py.swp b/src/t2s/.__init__.py.swp deleted file mode 100644 index c6fffd0..0000000 Binary files a/src/t2s/.__init__.py.swp and /dev/null differ diff --git a/src/t2s/.tts.py.swp b/src/t2s/.tts.py.swp deleted file mode 100644 index 27c3c12..0000000 Binary files a/src/t2s/.tts.py.swp and /dev/null differ diff --git a/src/t2s/__init__.py b/src/t2s/__init__.py index de1ddbc..eac727d 100644 --- a/src/t2s/__init__.py +++ b/src/t2s/__init__.py @@ -5,4 +5,4 @@ __all__ = ['T2S', 'gTTSError'] -__version__ = "2021.1" +__version__ = "2021.2" diff --git a/src/t2s/cli.py b/src/t2s/cli.py index eabfb8c..f32a58a 100644 --- a/src/t2s/cli.py +++ b/src/t2s/cli.py @@ -1,7 +1,8 @@ # -*- coding: utf-8 -*- -from gtts import gTTS, gTTSError, __version__ +from t2s import T2S, gTTSError, __version__ from t2s.lang import tts_langs -from quo import app, command, arg, File +from quo import app, command, arg, autoversion +from quo.type import File from quo.errors import BadParameter, UsageError, Outlier import logging import logging.config @@ -112,57 +113,20 @@ def set_debug(clime, param, debug): @command(context_settings=CONTEXT_SETTINGS) @arg('text', metavar='', required=False, callback=validate_text) @app('-f', '--file', metavar='', type= File(encoding=sys_encoding()), help="Read from instead of .") -@app( - '-o', - '--output', - metavar='', - type= File(mode='wb'), - help="Write to instead of stdout.") -@app( - '-s', - '--slow', - default=False, - is_flag=True, - help="Read more slowly.") -@app( - '-l', - '--lang', - metavar='', - default='en', - show_default=True, - callback=validate_lang, - help="IETF language tag. Language to speak in. List documented tags with --all.") -@app( - '-t', - '--tld', - metavar='', - default='com', - show_default=True, - is_eager=True, # Prioritize to ensure it gets set before - help="Top-level domain for the Google host, i.e https://translate.google.") -@app( - '--nocheck', - default=False, - is_flag=True, - is_eager=True, # Prioritize to ensure it gets set before - help="Disable strict IETF language tag checking. Allow undocumented tags.") -@app( - '--all', - default=False, - is_flag=True, - is_eager=True, - expose_value=False, - callback=print_languages, - help="Print all documented available IETF language tags and exit.") -@click.option( - '--debug', - default=False, - is_flag=True, - is_eager=True, # Prioritize to see debug logs of callbacks - expose_value=False, - callback=set_debug, - help="Show debug information.") -@autoversion(version=__version__) +@app('-o', '--output', metavar='', type= File(mode='wb'), help="Write to instead of stdout.") +@app('-s', '--slow', default=False, flag=True, help="Read more slowly.") +@app('-l', '--lang', metavar='', default='en', show_default=True, callback=validate_lang, help="IETF language tag. Language to speak in. List documented tags with --all.") + +# Prioritize to ensure it gets set before +@app('-t', '--tld', metavar='', default='com', show_default=True, eager=True, help="Top-level domain for the Google host, i.e https://translate.google.") + +# Prioritize to ensure it gets set before +@app('--nocheck', default=False, flag=True, eager=True, help="Disable strict IETF language tag checking. Allow undocumented tags.") +@app('--all', default=False, flag=True, eager=True, expose_value=False, callback=print_languages, help="Print all documented available IETF language tags and exit.") + +# Pruoritize to see debug logs of callbacks +@app('--debug', default=False, flag=True, eager=True, expose_value=False, callback=set_debug, help="Show debug information.") +#@autoversion(version=__version__) def tts_cli(text, file, output, slow, tld, lang, nocheck): """ Read to mp3 format using Google Translate's Text-to-Speech API (set or --file to - for standard input) @@ -189,7 +153,7 @@ def tts_cli(text, file, output, slow, tld, lang, nocheck): # TTS try: - tts = gTTS( + tts = T2S( text=text, lang=lang, slow=slow, diff --git a/src/t2s/lang.py b/src/t2s/lang.py index 0dd00c6..bc46cf4 100644 --- a/src/t2s/lang.py +++ b/src/t2s/lang.py @@ -1,7 +1,8 @@ # -*- coding: utf-8 -*- -from t2s.langs import _main_langs +from t2s.languages import _main_langs from warnings import warn import logging +from quo import command, app __all__ = ['tts_langs'] @@ -9,7 +10,8 @@ log = logging.getLogger(__name__) log.addHandler(logging.NullHandler()) - +@command() +@app("--tts_langs") def tts_langs(): """Languages Google Text-to-Speech supports. @@ -33,7 +35,8 @@ def tts_langs(): log.debug("langs: {}".format(langs)) return langs - +@command() +@app("--_extra_langs") def _extra_langs(): """Define extra languages. @@ -51,6 +54,8 @@ def _extra_langs(): 'zh': 'Chinese (Mandarin)' } +@command() +@app("--_fallback_deprecated_lang") def _fallback_deprecated_lang(lang): """Languages Google Text-to-Speech used to support. diff --git a/src/t2s/langs.py b/src/t2s/langs.py deleted file mode 100644 index 683cbda..0000000 --- a/src/t2s/langs.py +++ /dev/null @@ -1,66 +0,0 @@ -# Note: this file is generated -_langs = { - "af": "Afrikaans", - "ar": "Arabic", - "bg": "Bulgarian", - "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", - "ks": "Kiswahili", - "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 diff --git a/src/t2s/tokenizer/pre_processors.py b/src/t2s/tokenizer/pre_processors.py index 69ef393..f8b71e5 100644 --- a/src/t2s/tokenizer/pre_processors.py +++ b/src/t2s/tokenizer/pre_processors.py @@ -1,8 +1,10 @@ # -*- coding: utf-8 -*- from t2s.tokenizer import PreProcessorRegex, PreProcessorSub, symbols import re +from quo import app, command - +@command() +@app("--tone_marks") def tone_marks(text): """Add a space after tone-modifying punctuation. @@ -16,6 +18,8 @@ def tone_marks(text): repl=' ').run(text) +@command() +@app("--end_of_line") def end_of_line(text): """Re-form words cut by end-of-line hyphens. @@ -28,6 +32,8 @@ def end_of_line(text): repl='').run(text) +@command() +@app("--abbreviations") def abbreviations(text): """Remove periods after an abbreviation from a list of known abbrevations that can be spoken the same without that period. This @@ -47,7 +53,8 @@ def abbreviations(text): search_func=lambda x: r"(?<={})(?=\.).".format(x), repl='', flags=re.IGNORECASE).run(text) - +@command() +@app("--word_sub") def word_sub(text): """Word-for-word substitutions.""" return PreProcessorSub( diff --git a/src/t2s/tokenizer/tokenizer_cases.py b/src/t2s/tokenizer/tokenizer_cases.py index 7dbcc1e..23489f9 100644 --- a/src/t2s/tokenizer/tokenizer_cases.py +++ b/src/t2s/tokenizer/tokenizer_cases.py @@ -1,7 +1,9 @@ # -*- coding: utf-8 -*- from t2s.tokenizer import RegexBuilder, symbols +from quo import app, command - +@command() +@app("--tone_marks") def tone_marks(): """Keep tone-modifying punctuation by matching following character. @@ -13,6 +15,8 @@ def tone_marks(): pattern_func=lambda x: u"(?<={}).".format(x)).regex +@command() +@app("--period_comma") def period_comma(): """Period and comma case. @@ -30,7 +34,8 @@ def period_comma(): pattern_args=symbols.PERIOD_COMMA, pattern_func=lambda x: r"(?