Created
April 17, 2014 23:34
-
-
Save wbbradley/11017252 to your computer and use it in GitHub Desktop.
A Flask wrapper around say Mac OS
This file contains hidden or 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 | |
import subprocess | |
app = Flask(__name__) | |
def talkie(voice, text): | |
try: | |
output, error = subprocess.Popen( | |
["say", "-v", voice, text], stdout=subprocess.PIPE, | |
stderr=subprocess.PIPE).communicate() | |
print output | |
return output | |
except: | |
app.logger.warn('An error occurred') | |
return 'error' | |
@app.route("/voices") | |
def voices(): | |
return talkie('?', '') | |
@app.route("/<voice>/<text>") | |
def say_voice(voice='Alex', text=None): | |
print text | |
return talkie(voice, text) | |
@app.route("/<text>") | |
def say(text=None): | |
if text == 'favicon.ico': | |
return | |
print text | |
return talkie('Alex', text) | |
if __name__ == "__main__": | |
app.run(host='0.0.0.0') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment