Saturday, May 12, 2007

TuxDroid and D-Bus

D-bus is a local IPC protocol that allows applications on a single machine to signal each other and request or consume each other's services. Examples include the little notificiation pop-up that tells you your battery is charged.

Tuxdroid is a robot version of the linux mascot, available from www.kysoh.com. Developer pages here: www.tuxisalive.com/

Here's a tuxdroid service that lets other application speak with the mighty voice of Tux:


#!/usr/bin/python
# Borrowed from http://webcvs.freedesktop.org/dbus/dbus/python/examples/example-service.py

import dbus
import dbus.service
import dbus.glib
import gobject
import sys
sys.path.append('/opt/tuxdroid/api/python')
from tux import *
class TuxObject(dbus.service.Object):
def __init__(self, bus_name, object_path="/Tux"):
dbus.service.Object.__init__(self, bus_name, object_path)

@dbus.service.method("org.dfwpython.TuxInterface")
def Speak(self, hello_message, voice='Male'):
print (str(hello_message))
if voice == 'Male':
speaker = SPK_US_MALE
else:
speaker = SPK_US_FEMALE
pitch=100
tux.tts.select_voice(speaker,pitch)
tux.cmd.mouth_open()
tux.tts.speak( str(hello_message))
tux.cmd.mouth_close()


session_bus = dbus.SessionBus()
name = dbus.service.BusName("org.dfwpython.TuxService", bus=session_bus)
object = TuxObject(name)

mainloop = gobject.MainLoop()
mainloop.run()

No comments: