Skip to content

Instantly share code, notes, and snippets.

@mperlet
Created January 20, 2015 10:56
Show Gist options
  • Save mperlet/703e27e136f37c51dc6b to your computer and use it in GitHub Desktop.
Save mperlet/703e27e136f37c51dc6b to your computer and use it in GitHub Desktop.
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