Skip to content

Instantly share code, notes, and snippets.

@hayatoito
Last active December 21, 2015 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hayatoito/6247690 to your computer and use it in GitHub Desktop.
Save hayatoito/6247690 to your computer and use it in GitHub Desktop.
Speech Server.
#!/usr/bin/env python3
import html
from http.server import (HTTPServer, SimpleHTTPRequestHandler)
import subprocess
import urllib.parse
def speech_server(port=8080):
class SpeechHandler(SimpleHTTPRequestHandler):
def do_GET(self):
words = urllib.parse.unquote_plus(self.path)[1:]
if words in ('favicon.ico',):
return
print(words)
self.wfile.write(html.escape(words).encode('UTF-8'))
subprocess.call(['say', words])
return
server_address = ('', port)
httpd = HTTPServer(server_address, SpeechHandler)
print("serving at http://localhost:{}/".format(port))
httpd.serve_forever()
if __name__ == '__main__':
speech_server()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment