<h1 align='center'>Flask-gTTS</h1>
<p align='center'>
<a href='https://pypi.org/project/Flask-gTTS/'>
<img src='https://img.shields.io/github/v/tag/mrf345/flask_gtts' alt='Latest Release' />
</a>
<a href='https://github.com/mrf345/flask_gtts/actions/workflows/ci.yml'>
<img src='https://github.com/mrf345/flask_gtts/actions/workflows/ci.yml/badge.svg'>
</a>
<a href='https://github.com/mrf345/flask_gtts/actions/workflows/ci.yml'>
<img src='https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/mrf345/bc746d7bfe356b54fbb93b2ea5d0d2a4/raw/flask_gtts__heads_master.json' alt='Coverage Percentage' />
</a>
<br />
<img src='https://img.shields.io/pypi/pyversions/flask_gtts' alt='Supported versions' />
<br />
</p>
<h3 align='center'>A Flask extension to add support for Google Text-To-Speech (TTS).</h3>
## Install:
#### - With pip
- `pip install Flask-gTTS` <br />
#### - From the source:
- `git clone https://github.com/mrf345/flask_gtts.git`<br />
- `cd flask_gtts` <br />
- `python setup.py install`
## Setup:
#### - Inside the Flask app:
```python
from flask import Flask, render_template
from flask_gtts import gtts
app = Flask(__name__)
gtts(app)
```
#### - Inside the jinja template:
```jinja
{% block content %}
<audio src="{{ sayit(text='Hello from Flask !')}}"></audio>
{% endblock %}
```
#### - Dynamic read TTS example:
```jinja
<head>
{{ read(id='.readIt') }}
</head>
<body>
<h1 class='readIt'>Say something</h1>
<h1 class='readIT' language='it'>qualcosa da dire</h1>
</body>
```
#### - Dynamic route example:
```python
from flask import Flask
from flask_gtts import gtts
# If we want to allow only logged in users for example.
from flask_login import login_required
app = Flask(__name__)
gtts(app,
route=True,
route_decorator=login_required,
route_path='/gtts')
```
And now you can test the endpoint by accessing `http://localhost:5000/gtts/en-us/some text to test`. It will return `JSON` response:
```json
{
"mp3": "Generated audio file path."
}
```
## Settings:
- **`gtts()`** options:
```python
def __init__(self, app=None, temporary=True, tempdir='flask_gtts', route=False,
route_path='/gtts', route_decorator=None):
'''Extension to help in generating Google Text-To-Speech files.
Parameters
----------
app : Flask Application, optional
Flask application instance, by default None
temporary : bool, optional
Remove the audio files before existing, by default True
tempdir : str, optional
Name of the static directory to store audio files in, by default 'flask_gtts'
route : bool, optional
Enable endpoint to generate TTS file dynamically, by default False
route_path : str, optional
Endpoint route path, by default '/gtts'
route_decorator : callable, optional
Decorator to wrap route endpoint, by default None
failsafe : bool, optional
Failsafe or throw exceptions, by default False
'''
```
- **`sayit()`** options:
```python
def say(self, lang='en-us', text='Flask says Hi!'):
'''Generate a TTS audio file.
Parameters
----------
lang : str, optional
Language to produce the TTS in, by default 'en-us'
text : str, optional
Text to convert into audio, by default 'Flask says Hi!'
Returns
-------
str
Relative url of the generated TTS audio file.
'''
```
- **`read()`** options:
```python
def read(self, id='.toRead', mouseover=False):
'''Read an HTML element inner text.
Parameters
----------
id : str, optional
HTML element css selector, by default '.toRead'
mouseover : bool, optional
Read text on `mouseover` event instead of `click`, by default False
Returns
-------
str
Safe JavaScript to read an HTML element content.
'''
```
- **List of supported 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'
`
## Credit:
- [gTTS][2c6d97b1]: Python Google text-to-speech
[2c6d97b1]: https://github.com/pndurette/gTTS "gTTs repo"
Raw data
{
"_id": null,
"home_page": "https://github.com/mrf345/flask_gtts/",
"name": "Flask-gTTS",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "flask, extension, google, text, speech, gTTS, TTS, text-to-speech",
"author": "Mohamed Feddad",
"author_email": "mrf345@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/d3/5c/107de11e74d2258ae80cf45cf765e96e172a0c0109a1403927bae6514888/flask_gtts-0.19.tar.gz",
"platform": "any",
"description": "<h1 align='center'>Flask-gTTS</h1>\n<p align='center'>\n<a href='https://pypi.org/project/Flask-gTTS/'>\n <img src='https://img.shields.io/github/v/tag/mrf345/flask_gtts' alt='Latest Release' />\n</a>\n<a href='https://github.com/mrf345/flask_gtts/actions/workflows/ci.yml'>\n <img src='https://github.com/mrf345/flask_gtts/actions/workflows/ci.yml/badge.svg'>\n</a>\n<a href='https://github.com/mrf345/flask_gtts/actions/workflows/ci.yml'>\n <img src='https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/mrf345/bc746d7bfe356b54fbb93b2ea5d0d2a4/raw/flask_gtts__heads_master.json' alt='Coverage Percentage' />\n</a>\n<br />\n<img src='https://img.shields.io/pypi/pyversions/flask_gtts' alt='Supported versions' />\n<br />\n</p>\n\n<h3 align='center'>A Flask extension to add support for Google Text-To-Speech (TTS).</h3>\n\n## Install:\n#### - With pip\n- `pip install Flask-gTTS` <br />\n\n#### - From the source:\n- `git clone https://github.com/mrf345/flask_gtts.git`<br />\n- `cd flask_gtts` <br />\n- `python setup.py install`\n\n## Setup:\n\n#### - Inside the Flask app:\n```python\nfrom flask import Flask, render_template\nfrom flask_gtts import gtts\napp = Flask(__name__)\ngtts(app)\n```\n\n#### - Inside the jinja template:\n```jinja\n{% block content %}\n <audio src=\"{{ sayit(text='Hello from Flask !')}}\"></audio>\n{% endblock %}\n```\n\n#### - Dynamic read TTS example:\n```jinja\n<head>\n {{ read(id='.readIt') }}\n</head>\n<body>\n <h1 class='readIt'>Say something</h1>\n <h1 class='readIT' language='it'>qualcosa da dire</h1>\n</body>\n```\n\n#### - Dynamic route example:\n```python\nfrom flask import Flask\nfrom flask_gtts import gtts\n\n# If we want to allow only logged in users for example.\nfrom flask_login import login_required\n\napp = Flask(__name__)\ngtts(app,\n route=True,\n route_decorator=login_required,\n route_path='/gtts')\n```\n\nAnd now you can test the endpoint by accessing `http://localhost:5000/gtts/en-us/some text to test`. It will return `JSON` response:\n\n```json\n{\n \"mp3\": \"Generated audio file path.\"\n}\n```\n\n## Settings:\n- **`gtts()`** options:\n\n```python\ndef __init__(self, app=None, temporary=True, tempdir='flask_gtts', route=False,\n route_path='/gtts', route_decorator=None):\n '''Extension to help in generating Google Text-To-Speech files.\n\n Parameters\n ----------\n app : Flask Application, optional\n Flask application instance, by default None\n temporary : bool, optional\n Remove the audio files before existing, by default True\n tempdir : str, optional\n Name of the static directory to store audio files in, by default 'flask_gtts'\n route : bool, optional\n Enable endpoint to generate TTS file dynamically, by default False\n route_path : str, optional\n Endpoint route path, by default '/gtts'\n route_decorator : callable, optional\n Decorator to wrap route endpoint, by default None\n failsafe : bool, optional\n Failsafe or throw exceptions, by default False\n '''\n```\n\n- **`sayit()`** options:\n\n```python\ndef say(self, lang='en-us', text='Flask says Hi!'):\n '''Generate a TTS audio file.\n\n Parameters\n ----------\n lang : str, optional\n Language to produce the TTS in, by default 'en-us'\n text : str, optional\n Text to convert into audio, by default 'Flask says Hi!'\n\n Returns\n -------\n str\n Relative url of the generated TTS audio file.\n '''\n```\n\n- **`read()`** options:\n```python\ndef read(self, id='.toRead', mouseover=False):\n '''Read an HTML element inner text.\n\n Parameters\n ----------\n id : str, optional\n HTML element css selector, by default '.toRead'\n mouseover : bool, optional\n Read text on `mouseover` event instead of `click`, by default False\n\n Returns\n -------\n str\n Safe JavaScript to read an HTML element content.\n '''\n```\n\n- **List of supported languages**:\n\n`\n 'af' : 'Afrikaans'\n 'sq' : 'Albanian'\n 'ar' : 'Arabic'\n 'hy' : 'Armenian'\n 'bn' : 'Bengali'\n 'ca' : 'Catalan'\n 'zh' : 'Chinese'\n 'zh-cn' : 'Chinese (Mandarin/China)'\n 'zh-tw' : 'Chinese (Mandarin/Taiwan)'\n 'zh-yue' : 'Chinese (Cantonese)'\n 'hr' : 'Croatian'\n 'cs' : 'Czech'\n 'da' : 'Danish'\n 'nl' : 'Dutch'\n 'en' : 'English'\n 'en-au' : 'English (Australia)'\n 'en-uk' : 'English (United Kingdom)'\n 'en-us' : 'English (United States)'\n 'eo' : 'Esperanto'\n 'fi' : 'Finnish'\n 'fr' : 'French'\n 'de' : 'German'\n 'el' : 'Greek'\n 'hi' : 'Hindi'\n 'hu' : 'Hungarian'\n 'is' : 'Icelandic'\n 'id' : 'Indonesian'\n 'it' : 'Italian'\n 'ja' : 'Japanese'\n 'km' : 'Khmer (Cambodian)'\n 'ko' : 'Korean'\n 'la' : 'Latin'\n 'lv' : 'Latvian'\n 'mk' : 'Macedonian'\n 'no' : 'Norwegian'\n 'pl' : 'Polish'\n 'pt' : 'Portuguese'\n 'ro' : 'Romanian'\n 'ru' : 'Russian'\n 'sr' : 'Serbian'\n 'si' : 'Sinhala'\n 'sk' : 'Slovak'\n 'es' : 'Spanish'\n 'es-es' : 'Spanish (Spain)'\n 'es-us' : 'Spanish (United States)'\n 'sw' : 'Swahili'\n 'sv' : 'Swedish'\n 'ta' : 'Tamil'\n 'th' : 'Thai'\n 'tr' : 'Turkish'\n 'uk' : 'Ukrainian'\n 'vi' : 'Vietnamese'\n 'cy' : 'Welsh'\n`\n\n## Credit:\n- [gTTS][2c6d97b1]: Python Google text-to-speech\n\n [2c6d97b1]: https://github.com/pndurette/gTTS \"gTTs repo\"\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A Flask extension to help in generating Google Text-To-Speech files.",
"version": "0.19",
"project_urls": {
"Download": "https://github.com/mrf345/flask_gtts/archive/0.19.tar.gz",
"Homepage": "https://github.com/mrf345/flask_gtts/"
},
"split_keywords": [
"flask",
" extension",
" google",
" text",
" speech",
" gtts",
" tts",
" text-to-speech"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "59216c7439b82994830b302129d82369cff68d45ee005ec9e978b63dec212564",
"md5": "6670af1c91a36e4d30aaf70c738386f0",
"sha256": "6cf4b881673c413c383239a3e550211036de563dd6612e22cf950786fb62ae68"
},
"downloads": -1,
"filename": "Flask_gTTS-0.19-py3-none-any.whl",
"has_sig": false,
"md5_digest": "6670af1c91a36e4d30aaf70c738386f0",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 7177,
"upload_time": "2024-07-04T22:24:16",
"upload_time_iso_8601": "2024-07-04T22:24:16.613017Z",
"url": "https://files.pythonhosted.org/packages/59/21/6c7439b82994830b302129d82369cff68d45ee005ec9e978b63dec212564/Flask_gTTS-0.19-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d35c107de11e74d2258ae80cf45cf765e96e172a0c0109a1403927bae6514888",
"md5": "3eef9cb10ee98b6494b9064eec55bacb",
"sha256": "9b42fc13b5a976eec93492bf84be9bcf073e62b0a9b013356d2e3bcbe1c9ea5c"
},
"downloads": -1,
"filename": "flask_gtts-0.19.tar.gz",
"has_sig": false,
"md5_digest": "3eef9cb10ee98b6494b9064eec55bacb",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 6574,
"upload_time": "2024-07-04T22:24:18",
"upload_time_iso_8601": "2024-07-04T22:24:18.295175Z",
"url": "https://files.pythonhosted.org/packages/d3/5c/107de11e74d2258ae80cf45cf765e96e172a0c0109a1403927bae6514888/flask_gtts-0.19.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-04 22:24:18",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "mrf345",
"github_project": "flask_gtts",
"travis_ci": true,
"coveralls": false,
"github_actions": true,
"lcname": "flask-gtts"
}