Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mrf345/flask_gtts
A Flask extension to add gTTS Google text to speech
https://github.com/mrf345/flask_gtts
extension flask gtts text-to-speech
Last synced: 10 days ago
JSON representation
A Flask extension to add gTTS Google text to speech
- Host: GitHub
- URL: https://github.com/mrf345/flask_gtts
- Owner: mrf345
- License: mit
- Created: 2017-11-25T21:15:06.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-07-04T22:23:26.000Z (4 months ago)
- Last Synced: 2024-10-11T08:26:48.112Z (27 days ago)
- Topics: extension, flask, gtts, text-to-speech
- Language: Python
- Size: 67.4 KB
- Stars: 9
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
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.git`
- `cd flask_gtts`
- `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 %}
{% endblock %}
```#### - Dynamic read TTS example:
```jinja{{ read(id='.readIt') }}
Say something
qualcosa da dire
```
#### - 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_requiredapp = 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 FalseReturns
-------
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"