Skip to content

Instantly share code, notes, and snippets.

@jrialland
Created September 26, 2021 13:40
Show Gist options
  • Save jrialland/1d0c600d074b311c812f7199646c643b to your computer and use it in GitHub Desktop.
Save jrialland/1d0c600d074b311c812f7199646c643b to your computer and use it in GitHub Desktop.
from flask import Flask, request, Response
from shelljob import proc
app = Flask(__name__)
@app.route('/tts/<lang>.mp3')
def text_to_speech(lang):
text = request.args.get('text')
g = proc.Group()
p = g.run(['bash', '-c', 'espeak-ng -v mb-fr1 -q --pho "'+text+'" | mbrola -t 1.2 -f 1.0 /usr/share/mbrola/fr1/fr1 - -.au' + "|ffmpeg -i 'pipe:0' -vn -ar 16000 -ac 1 -b:a 48k -f mp3 'pipe:1'"])
def read_process():
while g.is_pending():
lines = g.readlines()
for proc, line in lines:
yield line
return Response(read_process(), mimetype='audio/mpeg')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment