Skip to content

Instantly share code, notes, and snippets.

@KitWallace
KitWallace / ssml.py
Created August 17, 2012 17:24
ssml functions
def escape_XML(str) :
str.replace('"',"\042")
str.replace('&',"\046")
str.replace("'","\047")
str.replace('<',"\074")
str.replace('>',"\076")
return str
def ssml_break(msec):
return '<break time="'+str(msec)+'"msec/>'
@KitWallace
KitWallace / speek.py
Created August 17, 2012 22:12
TTS interface
import subprocess
def speak (text):
command = "echo '" + text + "'| espeak -v en+m2 -m"
subprocess.call(command,shell=True)
@KitWallace
KitWallace / simple_clock.py
Created August 17, 2012 22:38
A simple talking clock
#!/usr/bin/python
import time
import speak
while True :
message = "The Raspberry Pi time is " + speak.escape_XML(speak.ssml_break(500)) + time.strftime('%I %M %p')
speak.say(message)
time.sleep(60)
@KitWallace
KitWallace / presenter.py
Created August 17, 2012 23:09
Read the Labtec Presenter keys
#!/usr/bin/python
import sys
import tty
def read_key() :
tty.setcbreak(sys.stdin)
last = 0
while True :
code = ord(sys.stdin.read(1))
@KitWallace
KitWallace / talk_presenter.py
Created August 17, 2012 23:21
Testing the presenter
#!/usr/bin/python
import speak
import presenter
for key in presenter.read_key() :
print key
speak.say(key)
@KitWallace
KitWallace / yacht_menu.xml
Created August 18, 2012 00:22
Example menu
<menu name="yacht" title="Main yacht menu">
<item title="Navigation">
<item title="Position"/>
<item title="Speed over ground"/>
<item title="Heading"/>
</item>
<item title="Weather">
<item title="Windspeed"/>
<item title="Barometer"/>
</item>
@KitWallace
KitWallace / say_menu.py
Created August 18, 2012 00:24
Walk through a menu with the presenter
#!/usr/bin/python
import sys
import speak
from menu import *
def visit(item) :
text = item.getAttribute('title')
speak.say(text)
print text
@KitWallace
KitWallace / menu.py
Created August 18, 2012 00:35
Menu class supporting the Presenter
#!/usr/bin/python
from xml.dom.minidom import parse
import presenter
from xmlutils import remove_whitespace_nodes
class Menu :
""" a menu represents a menu and its current status
attributes
@KitWallace
KitWallace / run_menu.py
Created August 18, 2012 01:03
Execute actions in the yacht menu
#!/usr/bin/python
""" talking yacht
"""
import sys
import speak
# application specific imports
import time
@KitWallace
KitWallace / simple_clock.py
Created August 19, 2012 10:22
A simple talking clock
#!/usr/bin/python
import time
import speak
while True :
message = "The Raspberry Pi time is " + speak.escape_XML(speak.ssml_break(500)) + time.strftime('%I %M %p')
speak.say(message)
time.sleep(60)