Flask-gTTS
A Flask extension to add support for Google Text-To-Speech (TTS).
Install:
- With pip
pip install Flask-gTTS
- From the source:
git clone https://github.com/mrf345/flask_gtts.gitcd flask_gttspython setup.py install
Setup:
- Inside the Flask app:
from flask import Flask, render_template
from flask_gtts import gtts
app = Flask(__name__)
gtts(app)
- Inside the jinja template:
{% block content %}
<audio src="{{ sayit(text='Hello from Flask !')}}"></audio>
{% endblock %}
- Dynamic read TTS example:
<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:
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:
{
"mp3": "Generated audio file path."
}
Settings:
gtts()options:
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:
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:
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: Python Google text-to-speech
Metadata
Release files for Flask-gTTS 0.19
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| flask_gtts-0.19.tar.gz | 6.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| Flask_gTTS-0.19-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.8 kB
Release files / flask_gtts-0.19.tar.gz
| Download URL | flask_gtts-0.19.tar.gz |
|---|---|
| Size | 6.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9b42fc13b5a976eec93492bf84be9bcf073e62b0a9b013356d2e3bcbe1c9ea5c
|
|
BLAKE2b-256 checksum How to use checksums |
d35c107de11e74d2258ae80cf45cf765e96e172a0c0109a1403927bae6514888
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.8.19
|
Release files / Flask_gTTS-0.19-py3-none-any.whl
| Download URL | Flask_gTTS-0.19-py3-none-any.whl |
|---|---|
| Size | 7.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6cf4b881673c413c383239a3e550211036de563dd6612e22cf950786fb62ae68
|
|
BLAKE2b-256 checksum How to use checksums |
59216c7439b82994830b302129d82369cff68d45ee005ec9e978b63dec212564
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.8.19
|
Security for Flask-gTTS 0.19
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.