资源算法flask_gtts

flask_gtts

2019-12-30 | |  48 |   0 |   0

flask_gtts

 

A  Flask extension to add gTTS (Google text to speech), into the template,  it makes adding and configuring multiple text to speech audio files at a  time much easier and less time consuming.

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:

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 %}

  • More complex example:

{% block content %}   <button type='button' onclick='document.getElementById("us").play();'>American</button>   <button type='button' onclick='document.getElementById("ausi").play();'>Australian</button>   <button type='button' onclick='document.getElementById("brit").play();'>British</button>   <audio id='us' src="{{ sayit(lang='en-us', text='Hello from Flask !') }}"></audio>   <audio id='ausi' src="{{ sayit(lang='en-au', text='Hello from Flask !') }}"></audio>   <audio id='brit' src="{{ sayit(lang='en-uk', text='Hello from Flask !') }}"></audio> {% endblock %}

  • Dynamic TTS example:

<head>   {{ read(id='.readIt') }} </head> <body>   <h1 class='readIt'>Say something</h1>   <h1 class='readIT' language='it'>qualcosa da dire</h1> </body>

Settings:

  • gtts() options

gtts(app=app,     temporary=True, # to remove audio files on exit     tempdir='tempfile', # relative path in-which audio files will be stored     route=False # opens route on /gtts that takes /language/text as args to return gtts mp3 link     )

  • sayit() options

sayit(lang='en-us', # language to convert text to       text='say hi') # text to be converted`_<br />

  • read() options

read(   id='.toRead', # text element id to read text from takes . or #   mouseover=False # if enabled event mouseover instead of click )

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


上一篇:gtts.js

下一篇:XuebaOnline

用户评价
全部评价

热门资源

  • seetafaceJNI

    项目介绍 基于中科院seetaface2进行封装的JAVA...

  • spark-corenlp

    This package wraps Stanford CoreNLP annotators ...

  • Keras-ResNeXt

    Keras ResNeXt Implementation of ResNeXt models...

  • capsnet-with-caps...

    CapsNet with capsule-wise convolution Project ...

  • inferno-boilerplate

    This is a very basic boilerplate example for pe...