Created
January 20, 2015 10:56
-
-
Save mperlet/703e27e136f37c51dc6b to your computer and use it in GitHub Desktop.
FlaskApp, TTS-mp3 (localhost:5000/Ich+bin+kein+Mensch)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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