Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
FlaskApp, TTS-mp3 (localhost:5000/Ich+bin+kein+Mensch)
from flask import Flask
from flask import send_file
from urllib.request import urlopen
import random, string
import os, glob
app = Flask(__name__)
@app.route("/<tts>")
def hello(tts):
for fl in glob.glob("*wav*"):
os.remove(fl)
ttsnamef = ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(6))
mp3file = urlopen("http://mary.dfki.de:59125/process?INPUT_TEXT=%s&INPUT_TYPE=TEXT&OUTPUT_TYPE=AUDIO&AUDIO=WAVE_FILE&LOCALE=de" % tts)
output = open('%s.wav' % ttsnamef,'wb')
output.write(mp3file.read())
output.close()
os.system('lame -V 1 %s.wav %s.wav.mp3' % (ttsnamef, ttsnamef))
#os.remove("%s.wav" % ttsnamef)
return send_file("%s.wav.mp3" % ttsnamef, mimetype='audio/mp3')
if __name__ == "__main__":
app.run(host='0.0.0.0', debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment