Talking Twitter

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 = " " s = s + status.SelectSingleNode("text").InnerText + " " spk.SpeakSsml(s)

Back to Contents.