[Python-modules-commits] [gtts] 01/07: import gTTS_1.2.0.orig.tar.gz

Ethan Ward ethanward-guest at moszumanska.debian.org
Tue Jul 25 17:07:38 UTC 2017


This is an automated email from the git hooks/post-receive script.

ethanward-guest pushed a commit to branch master
in repository gtts.

commit d64fb298ae4d2b7ac08056a2af8dd9f9111d474f
Author: Ethan Ward <ethan.ward at mycroft.ai>
Date:   Tue Jul 25 11:24:54 2017 -0500

    import gTTS_1.2.0.orig.tar.gz
---
 CHANGELOG.md                       | 140 ++++++++++++++++++++++++++++
 MANIFEST.in                        |   2 +
 PKG-INFO                           | 162 ++++++++++++++++++++++++++++++++
 README.md                          | 138 ++++++++++++++++++++++++++++
 bin/gtts-cli                       |   4 +
 bin/gtts-cli.py                    |  52 +++++++++++
 gTTS.egg-info/PKG-INFO             | 162 ++++++++++++++++++++++++++++++++
 gTTS.egg-info/SOURCES.txt          |  14 +++
 gTTS.egg-info/dependency_links.txt |   1 +
 gTTS.egg-info/requires.txt         |   3 +
 gTTS.egg-info/top_level.txt        |   1 +
 gtts/__init__.py                   |   2 +
 gtts/tts.py                        | 183 +++++++++++++++++++++++++++++++++++++
 gtts/version.py                    |   1 +
 setup.cfg                          |   5 +
 setup.py                           |  40 ++++++++
 16 files changed, 910 insertions(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 0000000..2581a71
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,140 @@
+# Change Log
+All notable changes to this project will be documented in this file.
+This project adheres to [Semantic Versioning](http://semver.org/).
+This file adheres to [Keep a CHANGELOG](http://keepachangelog.com).
+
+## [Unreleased]
+
+## [1.2.0] - 2017-04-15
+### Added
+- Option for slower read speed (`slow=True` for `gTTS()`, `--slow` for `gtts-cli`)
+- System proxy settings are passed transparently to all http requests
+- Language: 'km', 'Khmer (Cambodian)'
+- Language: 'si', 'Sinhala'
+- Language: 'uk', 'Ukrainian'
+- More debug output
+
+### Removed
+- Language: 'pt-br' : 'Portuguese (Brazil)' (it was the same as 'pt' and not Brazilian)
+
+### Fixed
+- The text to read is now cut in proper chunks in Python 2 unicode. This broke reading for many languages such as Russian.
+- Disabled SSL verify on http requests to accommodate certain firewalls and proxies.
+- Better Python 2/3 support in general
+- Various fixes and cleanups
+
+## [1.1.8] - 2017-01-15
+### Added
+- Added stdin support (w/ `text` set to `-`) to `gtts-cli.py`/`gtts-cli` (#56 thanks @WyohKnott)
+
+## [1.1.7] - 2016-12-14
+### Changed
+- Added utf-8 support to `gtts-cli.py`/`gtts-cli` (#52 thanks @bakaiadam) 
+
+## [1.1.6] - 2016-07-20
+### Added
+- 'bn' : 'Bengali' (thanks @sakibiqbal, @mshubhankar)
+
+### Removed
+- 'ht' : 'Haitian Creole' (removed by Google)
+- 'token-script.js' (clean up)
+
+## [1.1.5] - 2016-05-13
+### Fixed
+- Fixed HTTP 403s by updating the client argument to reflect new API usage
+
+## [1.1.4] - 2016-02-22
+
+### Changed
+- Token calculation moved to now spun-off module [gTTS-Token](https://github.com/Boudewijn26/gTTS-token) maintained by @Boudewijn26
+
+## [1.1.3] - 2016-01-24
+### Added
+- Contributing section to README.md,
+
+### Changed
+- Better CHANGELOG.md replacing CHANGES.txt
+
+### Fixed
+- Made `gtts-cli` work w/ Python 3.x, from @desbma
+- Handle non-ASCII chars correctly (a wrong token would get generated resulting in a HTTP 403), from @Boudewijn26, h/t @desbma
+
+### Removed
+- Dropped Python 3.2 support and in .travis.yml
+
+## [1.1.2] - 2016-01-13
+- Packaging and Travis CI changes
+
+## 1.1.1 - 2016-01-13 [YANKED]
+### Changed
+- Packaging and Travis CI changes
+
+## [1.1.0] - 2016-01-13 [YANKED]
+### Added
+- Google Translate API token (`tk`) generation like translate.google.com to fix the constant HTTP 403 errors (for now), from @Boudewijn26
+
+## [1.0.7] - 2015-10-07
+### Changed
+- `gtts-cli` can be piped, arguments made more standard, from @Dr-Horv.
+
+## [1.0.6] - 2015-07-30
+### Added:
+- Raise an exception on bad HTTP response (4xx or 5xx).
+
+### Fixed
+- New required 'client=t' parameter for the api HTTP request, h/t @zainkhan_ on Twitter.
+
+## [1.0.5] - 2015-07-15
+### Added:
+- Option to use `write_to_fp()` to write to a file-like object instead of only to a file, from @Holzhaus.
+
+## [1.0.4] - 2015-05-11
+### Added
+- `gtts-cli` shows the version and pretty printed and sorted available languages.
+- `zh-yue` : 'Chinese (Cantonese)'.
+- `en-uk` : 'English (United Kingdom)'.
+- `pt-br` : 'Portuguese (Brazil)'.
+- `es-es` : 'Spanish (Spain)'.
+- `es-us` : 'Spanish (United StateS)'
+
+## Changed
+- Language code are now case insensitive.
+- Same voices but renamed for uniformity, better description:
+  - `zh-CN` : 'Mandarin (simplified)' is now `zh-cn` : 'Chinese (Mandarin/China)'.
+  - `zh-TW` : 'Mandarin (traditional)' is now `zh-tw` : 'Chinese (Mandarin/Taiwan)'.
+
+
+## [1.0.3] - 2014-11-21
+### Added
+- 'en-us' : 'English (United States)' from @leo-labs.
+- 'en-au' : 'English (Australia)'. from @leo-labs.
+
+## [1.0.2] - 2014-05-15
+### Changed
+- Python 3.x support.
+
+## 1.0.1 - 2014-05-15 [YANKED]
+### Added
+- Travis CI changes
+- Following [SemVer](http://semver.org/).
+
+## 1.0 - 2014-05-08
+### Added
+- Initial release
+
+[Unreleased]: https://github.com/pndurette/gTTS/compare/v1.2.0...master
+[1.2.0]: https://github.com/pndurette/gTTS/compare/v1.1.8...v1.2.0
+[1.1.8]: https://github.com/pndurette/gTTS/compare/v1.1.7...v1.1.8
+[1.1.7]: https://github.com/pndurette/gTTS/compare/v1.1.6...v1.1.7
+[1.1.6]: https://github.com/pndurette/gTTS/compare/v1.1.5...v1.1.6
+[1.1.5]: https://github.com/pndurette/gTTS/compare/v1.1.4...v1.1.5
+[1.1.4]: https://github.com/pndurette/gTTS/compare/v1.1.3...v1.1.4
+[1.1.3]: https://github.com/pndurette/gTTS/compare/v1.1.2...v1.1.3
+[1.1.2]: https://github.com/pndurette/gTTS/compare/v1.1.0...v1.1.2
+[1.1.0]: https://github.com/pndurette/gTTS/compare/v1.0.7...v1.1.0
+[1.0.7]: https://github.com/pndurette/gTTS/compare/v1.0.6...v1.0.7
+[1.0.6]: https://github.com/pndurette/gTTS/compare/v1.0.5...v1.0.6
+[1.0.5]: https://github.com/pndurette/gTTS/compare/v1.0.4...v1.0.5
+[1.0.4]: https://github.com/pndurette/gTTS/compare/v1.0.3...v1.0.4
+[1.0.3]: https://github.com/pndurette/gTTS/compare/v1.0.2...v1.0.3
+[1.0.2]: https://github.com/pndurette/gTTS/compare/v1.0...v1.0.2
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..a33db56
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,2 @@
+include README.md
+include CHANGELOG.md
diff --git a/PKG-INFO b/PKG-INFO
new file mode 100644
index 0000000..84138db
--- /dev/null
+++ b/PKG-INFO
@@ -0,0 +1,162 @@
+Metadata-Version: 1.1
+Name: gTTS
+Version: 1.2.0
+Summary: Create an mp3 file from spoken text via the Google TTS (Text-to-Speech) API
+Home-page: https://github.com/pndurette/gTTS
+Author: Pierre Nicolas Durette
+Author-email: pndurette at gmail.com
+License: MIT
+Description: # gTTS
+        
+        **gTTS** (_Google Text to Speech_): a *Python* interface for Google's _Text to Speech_ API. Create an _mp3_ file with the `gTTS` module or `gtts-cli` command line utility. It allows unlimited lengths to be spoken by tokenizing long sentences where the speech would naturally pause.
+        
+        [![Build Status](https://travis-ci.org/pndurette/gTTS.svg?branch=master)](https://travis-ci.org/pndurette/gTTS)
+        [![PyPI version](https://badge.fury.io/py/gTTS.svg)](https://badge.fury.io/py/gTTS)
+        
+        ## Install
+        
+        ```
+        pip install gTTS
+        ```
+        
+        ## Usage
+        
+        You may either use `gTTS` as a **__python module__** or as a **__command-line utility__**
+        
+        ### A. Module
+        
+        ##### 1. Import `gTTS`
+        
+        ```
+        >> from gtts import gTTS
+        ```
+        
+        ##### 2. Create an instance
+        
+        ```
+        >> tts = gTTS(text='Hello', lang='en', slow=True)
+        ```
+        
+        ###### _Parameters:_
+        *  `text` - String - Text to be spoken.
+        *  `lang` - String - [ISO 639-1 language code](#lang_list) (supported by the Google _Text to Speech_ API) to speak in.
+        *  `slow` - Boolean - Speak slowly. Default `False` (Note: only two speeds are provided by the API).
+        
+        ##### 3. Write to a file
+        
+        * _To disk_ using `save(file_name)`
+           
+        ```
+        >> tts.save("hello.mp3")
+        ```
+        
+        * _To a file pointer_ using `write_to_fp(file_object)`
+           
+        ``` 
+        >> f = TemporaryFile()
+        >> tts.write_to_fp(f)
+        >> # <Do something with f>
+        >> f.close()
+        ```
+        
+        ### B. Command line utility
+        
+        ##### Command
+        ```
+        gtts-cli.py [-h] (["text to speak"] | -f FILE) [-l LANG] [--slow] [--debug] [-o destination_file]
+        ```
+         
+        ###### _Example:_
+          
+        ```
+        $ # Read the string 'Hello' in English to hello.mp3
+        $ gtts-cli "Hello" -l 'en' -o hello.mp3
+        
+        $ # Read the string 'Hello' in English (slow speed) to hello.mp3
+        $ gtts-cli "Hello" -l 'en' -o hello.mp3 --slow
+        
+        $ # Read the contents of file 'hello.txt' in Czech to hello.mp3:
+        $ gtts-cli -f hello.txt -l 'cs' -o hello.mp3
+        
+        $ # Read the string 'Hello' from stdin in English to hello.mp3
+        $ echo "Hello" | gtts-cli -l 'en' -o hello.mp3 -
+        ```
+        
+        ## Supported Languages <a name="lang_list"></a>
+        
+          * 'af' : 'Afrikaans'
+          * 'sq' : 'Albanian'
+          * 'ar' : 'Arabic'
+          * 'hy' : 'Armenian'
+          * 'bn' : 'Bengali'
+          * 'ca' : 'Catalan'
+          * 'zh' : 'Chinese'
+          * 'zh-cn' : 'Chinese (Mandarin/China)'
+          * 'zh-tw' : 'Chinese (Mandarin/Taiwan)'
+          * 'zh-yue' : 'Chinese (Cantonese)'
+          * 'hr' : 'Croatian'
+          * 'cs' : 'Czech'
+          * 'da' : 'Danish'
+          * 'nl' : 'Dutch'
+          * 'en' : 'English'
+          * 'en-au' : 'English (Australia)'
+          * 'en-uk' : 'English (United Kingdom)'
+          * 'en-us' : 'English (United States)'
+          * 'eo' : 'Esperanto'
+          * 'fi' : 'Finnish'
+          * 'fr' : 'French'
+          * 'de' : 'German'
+          * 'el' : 'Greek'
+          * 'hi' : 'Hindi'
+          * 'hu' : 'Hungarian'
+          * 'is' : 'Icelandic'
+          * 'id' : 'Indonesian'
+          * 'it' : 'Italian'
+          * 'ja' : 'Japanese'
+          * 'km' : 'Khmer (Cambodian)'
+          * 'ko' : 'Korean'
+          * 'la' : 'Latin'
+          * 'lv' : 'Latvian'
+          * 'mk' : 'Macedonian'
+          * 'no' : 'Norwegian'
+          * 'pl' : 'Polish'
+          * 'pt' : 'Portuguese'
+          * 'ro' : 'Romanian'
+          * 'ru' : 'Russian'
+          * 'sr' : 'Serbian'
+          * 'si' : 'Sinhala'
+          * 'sk' : 'Slovak'
+          * 'es' : 'Spanish'
+          * 'es-es' : 'Spanish (Spain)'
+          * 'es-us' : 'Spanish (United States)'
+          * 'sw' : 'Swahili'
+          * 'sv' : 'Swedish'
+          * 'ta' : 'Tamil'
+          * 'th' : 'Thai'
+          * 'tr' : 'Turkish'
+          * 'uk' : 'Ukrainian'
+          * 'vi' : 'Vietnamese'
+          * 'cy' : 'Welsh'
+        
+        ## Contributing
+        
+        1. _Fork_ [pndurette/gTTS](https://github.com/pndurette/gTTS) on GitHub and clone it locally
+        2. Make sure you write tests for new features or modify the existing ones if necessary
+        3. Open a new _Pull Request_ from your feature branch to the `master` branch.
+        4. Thank you!
+        
+Platform: UNKNOWN
+Classifier: Environment :: Console
+Classifier: Intended Audience :: Developers
+Classifier: License :: OSI Approved :: MIT License
+Classifier: Operating System :: MacOS :: MacOS X
+Classifier: Operating System :: Unix
+Classifier: Operating System :: POSIX
+Classifier: Operating System :: POSIX :: Linux
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3.3
+Classifier: Programming Language :: Python :: 3.4
+Classifier: Programming Language :: Python :: 3.5
+Classifier: Programming Language :: Python :: 3.6
+Classifier: Topic :: Software Development :: Libraries
+Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..7fe702c
--- /dev/null
+++ b/README.md
@@ -0,0 +1,138 @@
+# gTTS
+
+**gTTS** (_Google Text to Speech_): a *Python* interface for Google's _Text to Speech_ API. Create an _mp3_ file with the `gTTS` module or `gtts-cli` command line utility. It allows unlimited lengths to be spoken by tokenizing long sentences where the speech would naturally pause.
+
+[![Build Status](https://travis-ci.org/pndurette/gTTS.svg?branch=master)](https://travis-ci.org/pndurette/gTTS)
+[![PyPI version](https://badge.fury.io/py/gTTS.svg)](https://badge.fury.io/py/gTTS)
+
+## Install
+
+```
+pip install gTTS
+```
+
+## Usage
+
+You may either use `gTTS` as a **__python module__** or as a **__command-line utility__**
+
+### A. Module
+
+##### 1. Import `gTTS`
+
+```
+>> from gtts import gTTS
+```
+
+##### 2. Create an instance
+
+```
+>> tts = gTTS(text='Hello', lang='en', slow=True)
+```
+
+###### _Parameters:_
+*  `text` - String - Text to be spoken.
+*  `lang` - String - [ISO 639-1 language code](#lang_list) (supported by the Google _Text to Speech_ API) to speak in.
+*  `slow` - Boolean - Speak slowly. Default `False` (Note: only two speeds are provided by the API).
+
+##### 3. Write to a file
+
+* _To disk_ using `save(file_name)`
+   
+```
+>> tts.save("hello.mp3")
+```
+
+* _To a file pointer_ using `write_to_fp(file_object)`
+   
+``` 
+>> f = TemporaryFile()
+>> tts.write_to_fp(f)
+>> # <Do something with f>
+>> f.close()
+```
+
+### B. Command line utility
+
+##### Command
+```
+gtts-cli.py [-h] (["text to speak"] | -f FILE) [-l LANG] [--slow] [--debug] [-o destination_file]
+```
+ 
+###### _Example:_
+  
+```
+$ # Read the string 'Hello' in English to hello.mp3
+$ gtts-cli "Hello" -l 'en' -o hello.mp3
+
+$ # Read the string 'Hello' in English (slow speed) to hello.mp3
+$ gtts-cli "Hello" -l 'en' -o hello.mp3 --slow
+
+$ # Read the contents of file 'hello.txt' in Czech to hello.mp3:
+$ gtts-cli -f hello.txt -l 'cs' -o hello.mp3
+
+$ # Read the string 'Hello' from stdin in English to hello.mp3
+$ echo "Hello" | gtts-cli -l 'en' -o hello.mp3 -
+```
+
+## Supported Languages <a name="lang_list"></a>
+
+  * 'af' : 'Afrikaans'
+  * 'sq' : 'Albanian'
+  * 'ar' : 'Arabic'
+  * 'hy' : 'Armenian'
+  * 'bn' : 'Bengali'
+  * 'ca' : 'Catalan'
+  * 'zh' : 'Chinese'
+  * 'zh-cn' : 'Chinese (Mandarin/China)'
+  * 'zh-tw' : 'Chinese (Mandarin/Taiwan)'
+  * 'zh-yue' : 'Chinese (Cantonese)'
+  * 'hr' : 'Croatian'
+  * 'cs' : 'Czech'
+  * 'da' : 'Danish'
+  * 'nl' : 'Dutch'
+  * 'en' : 'English'
+  * 'en-au' : 'English (Australia)'
+  * 'en-uk' : 'English (United Kingdom)'
+  * 'en-us' : 'English (United States)'
+  * 'eo' : 'Esperanto'
+  * 'fi' : 'Finnish'
+  * 'fr' : 'French'
+  * 'de' : 'German'
+  * 'el' : 'Greek'
+  * 'hi' : 'Hindi'
+  * 'hu' : 'Hungarian'
+  * 'is' : 'Icelandic'
+  * 'id' : 'Indonesian'
+  * 'it' : 'Italian'
+  * 'ja' : 'Japanese'
+  * 'km' : 'Khmer (Cambodian)'
+  * 'ko' : 'Korean'
+  * 'la' : 'Latin'
+  * 'lv' : 'Latvian'
+  * 'mk' : 'Macedonian'
+  * 'no' : 'Norwegian'
+  * 'pl' : 'Polish'
+  * 'pt' : 'Portuguese'
+  * 'ro' : 'Romanian'
+  * 'ru' : 'Russian'
+  * 'sr' : 'Serbian'
+  * 'si' : 'Sinhala'
+  * 'sk' : 'Slovak'
+  * 'es' : 'Spanish'
+  * 'es-es' : 'Spanish (Spain)'
+  * 'es-us' : 'Spanish (United States)'
+  * 'sw' : 'Swahili'
+  * 'sv' : 'Swedish'
+  * 'ta' : 'Tamil'
+  * 'th' : 'Thai'
+  * 'tr' : 'Turkish'
+  * 'uk' : 'Ukrainian'
+  * 'vi' : 'Vietnamese'
+  * 'cy' : 'Welsh'
+
+## Contributing
+
+1. _Fork_ [pndurette/gTTS](https://github.com/pndurette/gTTS) on GitHub and clone it locally
+2. Make sure you write tests for new features or modify the existing ones if necessary
+3. Open a new _Pull Request_ from your feature branch to the `master` branch.
+4. Thank you!
diff --git a/bin/gtts-cli b/bin/gtts-cli
new file mode 100755
index 0000000..dc25393
--- /dev/null
+++ b/bin/gtts-cli
@@ -0,0 +1,4 @@
+#!/bin/bash
+DIR="$( cd "$( dirname "$0" )" && pwd )"
+PYTHON=$(which python)
+exec $PYTHON $DIR/gtts-cli.py "$@" 
diff --git a/bin/gtts-cli.py b/bin/gtts-cli.py
new file mode 100755
index 0000000..f3657d0
--- /dev/null
+++ b/bin/gtts-cli.py
@@ -0,0 +1,52 @@
+#! /usr/bin/python
+
+from __future__ import print_function
+from gtts import gTTS
+from gtts import __version__
+import sys
+import argparse
+import os
+import codecs
+
+def languages():
+    """Sorted pretty printed string of supported languages"""
+    return ", ".join(sorted("{}: '{}'".format(gTTS.LANGUAGES[k], k) for k in gTTS.LANGUAGES))
+
+# Args
+desc = "Creates an mp3 file from spoken text via the Google Text-to-Speech API ({v})".format(v=__version__)
+parser = argparse.ArgumentParser(description=desc, formatter_class=argparse.RawTextHelpFormatter)
+
+text_group = parser.add_mutually_exclusive_group(required=True)
+text_group.add_argument('text', nargs='?', help="text to speak")      
+text_group.add_argument('-f', '--file', help="file to speak")
+
+parser.add_argument("-o", '--destination', help="destination mp3 file", action='store')
+parser.add_argument('-l', '--lang', default='en', help="ISO 639-1/IETF language tag to speak in:\n" + languages())
+parser.add_argument('--slow', action="store_true", help="slower read speed")
+parser.add_argument('--debug', action="store_true")
+
+args = parser.parse_args()
+
+try:
+    if args.text:
+        if args.text == "-":
+            text = sys.stdin.read()
+        else:
+            text = args.text
+    else:
+        with codecs.open(args.file, "r", "utf-8") as f:
+            text = f.read()
+
+    # TTSTF (Text to Speech to File)
+    tts = gTTS(text=text, lang=args.lang, slow=args.slow, debug=args.debug)
+
+    if args.destination:
+        tts.save(args.destination)
+    else:
+        tts.write_to_fp(os.fdopen(sys.stdout.fileno(), "wb"))
+except Exception as e:
+    if args.destination:
+        print(str(e))
+    else:
+        print("ERROR: ", e, file=sys.stderr)
+        
diff --git a/gTTS.egg-info/PKG-INFO b/gTTS.egg-info/PKG-INFO
new file mode 100644
index 0000000..84138db
--- /dev/null
+++ b/gTTS.egg-info/PKG-INFO
@@ -0,0 +1,162 @@
+Metadata-Version: 1.1
+Name: gTTS
+Version: 1.2.0
+Summary: Create an mp3 file from spoken text via the Google TTS (Text-to-Speech) API
+Home-page: https://github.com/pndurette/gTTS
+Author: Pierre Nicolas Durette
+Author-email: pndurette at gmail.com
+License: MIT
+Description: # gTTS
+        
+        **gTTS** (_Google Text to Speech_): a *Python* interface for Google's _Text to Speech_ API. Create an _mp3_ file with the `gTTS` module or `gtts-cli` command line utility. It allows unlimited lengths to be spoken by tokenizing long sentences where the speech would naturally pause.
+        
+        [![Build Status](https://travis-ci.org/pndurette/gTTS.svg?branch=master)](https://travis-ci.org/pndurette/gTTS)
+        [![PyPI version](https://badge.fury.io/py/gTTS.svg)](https://badge.fury.io/py/gTTS)
+        
+        ## Install
+        
+        ```
+        pip install gTTS
+        ```
+        
+        ## Usage
+        
+        You may either use `gTTS` as a **__python module__** or as a **__command-line utility__**
+        
+        ### A. Module
+        
+        ##### 1. Import `gTTS`
+        
+        ```
+        >> from gtts import gTTS
+        ```
+        
+        ##### 2. Create an instance
+        
+        ```
+        >> tts = gTTS(text='Hello', lang='en', slow=True)
+        ```
+        
+        ###### _Parameters:_
+        *  `text` - String - Text to be spoken.
+        *  `lang` - String - [ISO 639-1 language code](#lang_list) (supported by the Google _Text to Speech_ API) to speak in.
+        *  `slow` - Boolean - Speak slowly. Default `False` (Note: only two speeds are provided by the API).
+        
+        ##### 3. Write to a file
+        
+        * _To disk_ using `save(file_name)`
+           
+        ```
+        >> tts.save("hello.mp3")
+        ```
+        
+        * _To a file pointer_ using `write_to_fp(file_object)`
+           
+        ``` 
+        >> f = TemporaryFile()
+        >> tts.write_to_fp(f)
+        >> # <Do something with f>
+        >> f.close()
+        ```
+        
+        ### B. Command line utility
+        
+        ##### Command
+        ```
+        gtts-cli.py [-h] (["text to speak"] | -f FILE) [-l LANG] [--slow] [--debug] [-o destination_file]
+        ```
+         
+        ###### _Example:_
+          
+        ```
+        $ # Read the string 'Hello' in English to hello.mp3
+        $ gtts-cli "Hello" -l 'en' -o hello.mp3
+        
+        $ # Read the string 'Hello' in English (slow speed) to hello.mp3
+        $ gtts-cli "Hello" -l 'en' -o hello.mp3 --slow
+        
+        $ # Read the contents of file 'hello.txt' in Czech to hello.mp3:
+        $ gtts-cli -f hello.txt -l 'cs' -o hello.mp3
+        
+        $ # Read the string 'Hello' from stdin in English to hello.mp3
+        $ echo "Hello" | gtts-cli -l 'en' -o hello.mp3 -
+        ```
+        
+        ## Supported Languages <a name="lang_list"></a>
+        
+          * 'af' : 'Afrikaans'
+          * 'sq' : 'Albanian'
+          * 'ar' : 'Arabic'
+          * 'hy' : 'Armenian'
+          * 'bn' : 'Bengali'
+          * 'ca' : 'Catalan'
+          * 'zh' : 'Chinese'
+          * 'zh-cn' : 'Chinese (Mandarin/China)'
+          * 'zh-tw' : 'Chinese (Mandarin/Taiwan)'
+          * 'zh-yue' : 'Chinese (Cantonese)'
+          * 'hr' : 'Croatian'
+          * 'cs' : 'Czech'
+          * 'da' : 'Danish'
+          * 'nl' : 'Dutch'
+          * 'en' : 'English'
+          * 'en-au' : 'English (Australia)'
+          * 'en-uk' : 'English (United Kingdom)'
+          * 'en-us' : 'English (United States)'
+          * 'eo' : 'Esperanto'
+          * 'fi' : 'Finnish'
+          * 'fr' : 'French'
+          * 'de' : 'German'
+          * 'el' : 'Greek'
+          * 'hi' : 'Hindi'
+          * 'hu' : 'Hungarian'
+          * 'is' : 'Icelandic'
+          * 'id' : 'Indonesian'
+          * 'it' : 'Italian'
+          * 'ja' : 'Japanese'
+          * 'km' : 'Khmer (Cambodian)'
+          * 'ko' : 'Korean'
+          * 'la' : 'Latin'
+          * 'lv' : 'Latvian'
+          * 'mk' : 'Macedonian'
+          * 'no' : 'Norwegian'
+          * 'pl' : 'Polish'
+          * 'pt' : 'Portuguese'
+          * 'ro' : 'Romanian'
+          * 'ru' : 'Russian'
+          * 'sr' : 'Serbian'
+          * 'si' : 'Sinhala'
+          * 'sk' : 'Slovak'
+          * 'es' : 'Spanish'
+          * 'es-es' : 'Spanish (Spain)'
+          * 'es-us' : 'Spanish (United States)'
+          * 'sw' : 'Swahili'
+          * 'sv' : 'Swedish'
+          * 'ta' : 'Tamil'
+          * 'th' : 'Thai'
+          * 'tr' : 'Turkish'
+          * 'uk' : 'Ukrainian'
+          * 'vi' : 'Vietnamese'
+          * 'cy' : 'Welsh'
+        
+        ## Contributing
+        
+        1. _Fork_ [pndurette/gTTS](https://github.com/pndurette/gTTS) on GitHub and clone it locally
+        2. Make sure you write tests for new features or modify the existing ones if necessary
+        3. Open a new _Pull Request_ from your feature branch to the `master` branch.
+        4. Thank you!
+        
+Platform: UNKNOWN
+Classifier: Environment :: Console
+Classifier: Intended Audience :: Developers
+Classifier: License :: OSI Approved :: MIT License
+Classifier: Operating System :: MacOS :: MacOS X
+Classifier: Operating System :: Unix
+Classifier: Operating System :: POSIX
+Classifier: Operating System :: POSIX :: Linux
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3.3
+Classifier: Programming Language :: Python :: 3.4
+Classifier: Programming Language :: Python :: 3.5
+Classifier: Programming Language :: Python :: 3.6
+Classifier: Topic :: Software Development :: Libraries
+Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
diff --git a/gTTS.egg-info/SOURCES.txt b/gTTS.egg-info/SOURCES.txt
new file mode 100644
index 0000000..7c5758e
--- /dev/null
+++ b/gTTS.egg-info/SOURCES.txt
@@ -0,0 +1,14 @@
+CHANGELOG.md
+MANIFEST.in
+README.md
+setup.py
+bin/gtts-cli
+bin/gtts-cli.py
+gTTS.egg-info/PKG-INFO
+gTTS.egg-info/SOURCES.txt
+gTTS.egg-info/dependency_links.txt
+gTTS.egg-info/requires.txt
+gTTS.egg-info/top_level.txt
+gtts/__init__.py
+gtts/tts.py
+gtts/version.py
\ No newline at end of file
diff --git a/gTTS.egg-info/dependency_links.txt b/gTTS.egg-info/dependency_links.txt
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/gTTS.egg-info/dependency_links.txt
@@ -0,0 +1 @@
+
diff --git a/gTTS.egg-info/requires.txt b/gTTS.egg-info/requires.txt
new file mode 100644
index 0000000..0160033
--- /dev/null
+++ b/gTTS.egg-info/requires.txt
@@ -0,0 +1,3 @@
+six
+requests
+gtts_token
diff --git a/gTTS.egg-info/top_level.txt b/gTTS.egg-info/top_level.txt
new file mode 100644
index 0000000..7529d3a
--- /dev/null
+++ b/gTTS.egg-info/top_level.txt
@@ -0,0 +1 @@
+gtts
diff --git a/gtts/__init__.py b/gtts/__init__.py
new file mode 100644
index 0000000..fc0a8c1
--- /dev/null
+++ b/gtts/__init__.py
@@ -0,0 +1,2 @@
+from .version import __version__
+from .tts import gTTS
diff --git a/gtts/tts.py b/gtts/tts.py
new file mode 100644
index 0000000..1367c68
--- /dev/null
+++ b/gtts/tts.py
@@ -0,0 +1,183 @@
+# -*- coding: utf-8 -*-
+import re, requests, warnings
+from six.moves import urllib
+from requests.packages.urllib3.exceptions import InsecureRequestWarning
+from gtts_token.gtts_token import Token
+
+class gTTS:
+    """ gTTS (Google Text to Speech): an interface to Google's Text to Speech API """
+
+    # Google TTS API supports two read speeds
+    # (speed <= 0.3: slow; speed > 0.3: normal; default: 1)
+    class Speed:
+        SLOW = 0.3
+        NORMAL = 1
+
+    GOOGLE_TTS_URL = 'https://translate.google.com/translate_tts'
+    MAX_CHARS = 100 # Max characters the Google TTS API takes at a time
+    LANGUAGES = {
+        'af' : 'Afrikaans',
+        'sq' : 'Albanian',
+        'ar' : 'Arabic',
+        'hy' : 'Armenian',
+        'bn' : 'Bengali',
+        'ca' : 'Catalan',
+        'zh' : 'Chinese',
+        'zh-cn' : 'Chinese (Mandarin/China)',
+        'zh-tw' : 'Chinese (Mandarin/Taiwan)',
+        'zh-yue' : 'Chinese (Cantonese)',
+        'hr' : 'Croatian',
+        'cs' : 'Czech',
+        'da' : 'Danish',
+        'nl' : 'Dutch',
+        'en' : 'English',
+        'en-au' : 'English (Australia)',
+        'en-uk' : 'English (United Kingdom)',
+        'en-us' : 'English (United States)',
+        'eo' : 'Esperanto',
+        'fi' : 'Finnish',
+        'fr' : 'French',
+        'de' : 'German',
+        'el' : 'Greek',
+        'hi' : 'Hindi',
+        'hu' : 'Hungarian',
+        'is' : 'Icelandic',
+        'id' : 'Indonesian',
+        'it' : 'Italian',
+        'ja' : 'Japanese',
+        'km' : 'Khmer (Cambodian)',
+        'ko' : 'Korean',
+        'la' : 'Latin',
+        'lv' : 'Latvian',
+        'mk' : 'Macedonian',
+        'no' : 'Norwegian',
+        'pl' : 'Polish',
+        'pt' : 'Portuguese',
+        'ro' : 'Romanian',
+        'ru' : 'Russian',
+        'sr' : 'Serbian',
+        'si' : 'Sinhala',
+        'sk' : 'Slovak',
+        'es' : 'Spanish',
+        'es-es' : 'Spanish (Spain)',
+        'es-us' : 'Spanish (United States)',
+        'sw' : 'Swahili',
+        'sv' : 'Swedish',
+        'ta' : 'Tamil',
+        'th' : 'Thai',
+        'tr' : 'Turkish',
+        'uk' : 'Ukrainian',
+        'vi' : 'Vietnamese',
+        'cy' : 'Welsh'
+    }
+
+    def __init__(self, text, lang = 'en', slow = False, debug = False):
+        self.debug = debug
+        if lang.lower() not in self.LANGUAGES:
+            raise Exception('Language not supported: %s' % lang)
+        else:
+            self.lang = lang.lower()
+
+        if not text:
+            raise Exception('No text to speak')
+        else:
+            self.text = text
+
+        # Read speed
+        if slow:
+            self.speed = self.Speed().SLOW
+        else:
+            self.speed = self.Speed().NORMAL
+
+
+        # Split text in parts
+        if self._len(text) <= self.MAX_CHARS:
+            text_parts = [text]
+        else:
+            text_parts = self._tokenize(text, self.MAX_CHARS)           
+
+        # Clean
+        def strip(x): return x.replace('\n', '').strip()
+        text_parts = [strip(x) for x in text_parts]
+        text_parts = [x for x in text_parts if len(x) > 0]
+        self.text_parts = text_parts
+        
+        # Google Translate token
+        self.token = Token()
+
+    def save(self, savefile):
+        """ Do the Web request and save to `savefile` """
+        with open(savefile, 'wb') as f:
+            self.write_to_fp(f)
+
+    def write_to_fp(self, fp):
+        """ Do the Web request and save to a file-like object """
+        for idx, part in enumerate(self.text_parts):
+            payload = { 'ie' : 'UTF-8',
+                        'q' : part,
+                        'tl' : self.lang,
+                        'ttsspeed' : self.speed,
+                        'total' : len(self.text_parts),
+                        'idx' : idx,
+                        'client' : 'tw-ob',
+                        'textlen' : self._len(part),
+                        'tk' : self.token.calculate_token(part)}
+            headers = {
+                "Referer" : "http://translate.google.com/",
+                "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"
+            }
+            if self.debug: print(payload)
+            try:
+                # Disable requests' ssl verify to accomodate certain proxies and firewalls
+                # Filter out urllib3's insecure warnings. We can live without ssl verify here
+                with warnings.catch_warnings():
+                    warnings.filterwarnings("ignore", category=InsecureRequestWarning)
+                    r = requests.get(self.GOOGLE_TTS_URL,
+                                     params=payload,
+                                     headers=headers,
+                                     proxies=urllib.request.getproxies(),
+                                     verify=False)
+                if self.debug:
+                    print("Headers: {}".format(r.request.headers))
+                    print("Request url: {}".format(r.request.url))
+                    print("Response: {}, Redirects: {}".format(r.status_code, r.history))
+                r.raise_for_status()
+                for chunk in r.iter_content(chunk_size=1024):
+                    fp.write(chunk)
+            except Exception as e:
+                raise
+
+    def _len(self, text):
+        """ Get char len of `text`, after decoding if Python 2 """
+        try:
+            # Python 2
+            return len(text.decode('utf8'))
+        except AttributeError:
+            # Python 3
+            return len(text)
+
+    def _tokenize(self, text, max_size):
+        """ Tokenizer on basic roman punctuation """ 
+        
+        punc = "¡!()[]¿?.,;:—«»\n"
+        punc_list = [re.escape(c) for c in punc]
+        pattern = '|'.join(punc_list)
+        parts = re.split(pattern, text)
+
+        min_parts = []
+        for p in parts:
+            min_parts += self._minimize(p, " ", max_size)
+        return min_parts
+
+    def _minimize(self, thestring, delim, max_size):
+        """ Recursive function that splits `thestring` in chunks
+        of maximum `max_size` chars delimited by `delim`. Returns list. """ 
+        
+        if self._len(thestring) > max_size:
+            idx = thestring.rfind(delim, 0, max_size)
+            return [thestring[:idx]] + self._minimize(thestring[idx:], delim, max_size)
+        else:
+            return [thestring]
+
+if __name__ == "__main__":
+        pass
diff --git a/gtts/version.py b/gtts/version.py
new file mode 100644
index 0000000..58d478a
--- /dev/null
+++ b/gtts/version.py
@@ -0,0 +1 @@
+__version__ = '1.2.0'
diff --git a/setup.cfg b/setup.cfg
new file mode 100644
index 0000000..a669c45
--- /dev/null
+++ b/setup.cfg
@@ -0,0 +1,5 @@
+[egg_info]
+tag_svn_revision = 0
+tag_build = 
+tag_date = 0
+
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..533fdbb
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,40 @@
+try:
+    from setuptools import setup
+except ImportError:
+    from distutils.core import setup
+
+exec(open('gtts/version.py').read())
+
+setup(
+    name='gTTS',
... 31 lines suppressed ...

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/gtts.git



More information about the Python-modules-commits mailing list