Talking Twitter

From IronPython Cookbook

This fun example covers downloading a web file, parsing xml and making IronPython talk.

import clr
clr.AddReference('System.Speech')
clr.AddReference('System.Xml')

from System.Speech.Synthesis import SpeechSynthesizer
from System.Net import WebClient
from System.Xml import XmlDocument, XmlTextReader


content = WebClient().DownloadString("http://twitter.com/statuses/public_timeline.xml")
xmlDoc = XmlDocument()
spk = SpeechSynthesizer()

xmlDoc.LoadXml(content)
statusesNode = xmlDoc.SelectSingleNode("statuses")
for status in statusesNode:
    s = "<?xml version=\"1.0\"?><speak version=\"1.0\" xml:lang=\"en-US\"><break/>"
    s = s + status.SelectSingleNode("text").InnerText + "</speak>"
    spk.SpeakSsml(s)


Back to Contents.

TOOLBOX
LANGUAGES