Skip to content

Instantly share code, notes, and snippets.

@wbbradley
Created April 17, 2014 23:34
Show Gist options
  • Save wbbradley/11017252 to your computer and use it in GitHub Desktop.
Save wbbradley/11017252 to your computer and use it in GitHub Desktop.
A Flask wrapper around say Mac OS
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