Revision as of 12:21, 26 April 2010 by Ypolius (Talk | contribs)

Jump to: navigation, search

I am a senior Computer Science student who has elected to take this course in order to get more familiar with linux on the kernel side. I am very comfortable with the linux environment and would love to learn how it works. Currently I am working on the audio mbox project.

Project Work 3/30/2010 So far I have gotten a python script that runs on the beagleboard. This script takes in a textual topic and speaks the intro of the topic's wiki page using flite. The script is:

   # -*- coding: utf-8 -*-

import commands import HTMLParser import re class CustomParser(HTMLParser.HTMLParser):

   section = 'intro'
   reading = ""
   dictionary = {}
   def __init__(self, *args, **kwargs):
       self.stack = []
   def handle_starttag(self,  tag,  attrs):
       if tag.lower() == 'p':
           self.reading = 'text'
       if tag.lower() == 'h2':
           if(self.section == 'intro'):
               self.stack = []
           if(self.section != 'Contents' and self.section != 'intro'):
               self.dictionary[self.section]= "".join(self.stack)
               self.stack = []
           self.reading = 'title'
           self.section = ""
       if(self.section == 'Contents'):
           if(tag.lower() == 'span'):
               self.reading = 'text'
   def handle_endtag(self,  tag):
       if tag.lower() == 'p':
           self.reading = ""
       if tag.lower() == 'h2':
           self.reading = ""
           if(self.section == 'Contents'):
               self.dictionary['Contents'] = []
       if tag.lower() == 'table':  
           if self.section == 'Contents':
               self.reading = ""  
           if self.section == 'intro':                
               self.reading = 'text'
       if tag.lower() == 'span':            
           if self.section == 'Contents':
               self.reading = ""  
               self.stack = []
   def handle_data(self,  data):
       if self.reading == 'text':
       if self.reading == 'title':
           self.section += data

topic = raw_input('Enter a wikipedia topic you would like to hear about\n').replace(' ', '+') commands.getstatusoutput('wget --output-document=result.html' + topic +'&go=Go') parser = CustomParser() html = open('result.html', 'r') parser.feed( html.close() parser.close()

  1. cleanup files

for k, v in parser.dictionary.iteritems():

   if k != 'Contents':
       parser.dictionary[k] = re.sub('\[[0-9]\]', ,  v)

commands.getstatusoutput('mkdir output') output = open('output/intro.txt', 'w')

  1. start with intro

output.write('intro\n') output.write(parser.dictionary['intro']) output.close() for k in range(len(parser.dictionary['Contents'])):

   if k % 2 != 0:
           section = parser.dictionary['Contents'][k]
           output = open('output/' + section + '.txt', 'w')
           output.write(section + '\n')
       except KeyError:
           print 'no section: ' + section
  1. commands.getstatusoutput('flite output.txt speech.wav')
  2. commands.getstatusoutput('aplay speech.wav')

The python package can be installed with the 'opkg install python' command. Since this script depends on HTMLParser and the python installation is minimal, you need to get some dependencies. They are,, and (unsure of name, something similar) and can be obtained from a more fleshed out install. I copied my files over using scp from an Arch Linux python installation and it worked fine.