I've always been a huge enthusiast of wearable computing; if you need any evidence, take a look at my Master's thesis, Scouter, an augmented-reality, wearable computing facial detection and recognition system. In the vein of wearable computing and ubiquitous computing, I threw together a quick application for my netbook that will use the Python feedparser module to grab one or more RSS feeds at regular intervals, and read the titles and authors of new items using the flite/festival Text-to-Speech (TTS) program. To add extra feeds, just append to the feeds array in the config options. I've tested it with a bluetooth headset and regular headphones, although I found that ALSA/PulseAudio interactions for the bluetooth headset are very finicky. I was able to solve this by creating an /etc/asound.conf file; I'd be happy to share the contents of mine.


Code:
#!/usr/bin/python

#------ Config options start here
feeds = [ "http://www.cemetech.net/forum/rss.php" ]
checkfreq = 30      #seconds
alsa_device = "pulse"

#------ Config options end here

# Import our modules!
import sys,os
import feedparser
import time
from subprocess import *

# Set up per-feed variables!
feedlatest = [""]*len(feeds);

#audio setup
aplay_args = ["aplay", "feedwav"]
if alsa_device != "":
   aplay_args.append("--device="+alsa_device);

while 1:
   for i in range(len(feeds)):
      try:
         parsed = feedparser.parse(feeds[i])
         if feedlatest[i] == "":
            feedlatest[i] = parsed["items"][0]["date"]
         j = 0;
         while j < len(parsed["items"]) and parsed["items"][j]["date"] != feedlatest[i]:
            text2read = "BOL Topic: " + parsed["items"][j]["title"] + " by author " + parsed["items"][j]["author"] + ".  EOL"

            p1 = Popen(["flite", "-", "feedwav"], stdin=PIPE)
            print "Saying '%s'" % (text2read)
            p1.communicate(input=text2read)
            p1.stdin.close()
            p1.wait()
            p2 = Popen(aplay_args,stdout=None)
            p2.wait()

            j+=1

         #remember what we read now
         feedlatest[i] = parsed["items"][0]["date"]
      except:
         print "Warning: failed to fetch/parse feed!"

   time.sleep(checkfreq)
Wow, this looks really cool. Very Happy /me tests on his laptop.
souvik1997 wrote:
Wow, this looks really cool. Very Happy /me tests on his laptop.
Thanks. Smile And I'm enjoying audio post notifications, like the one about the post you just made! Very Happy
I get "Warning: failed to fetch/parse feed!". :/
souvik1997 wrote:
I get "Warning: failed to fetch/parse feed!". :/
Are you running under Linux? You might need to apt-get install python-feedparser.

Edit: Tari pointed out that if you're missing the package, it would have failed at the import. Do you have flite, the TTS program? If not, you need it. You also need aplay if you don't have it.
Test post.
_player1537 wrote:
Test post.
"by author underscore player fifteen thirty-seven". That one made me laugh aloud.
Haha, that is cool Very Happy I also like how I am "underscore player fifteen thirty-seven" Very Happy

Ninja'd Razz
Very cool stuff. =) Nice work!
Thanks elfprince! _player, that's creepy that we both said the exact same thing. I think my next step is to play with some of the voice command recognition programs I've made in the past to add mute and unmute voice commands, then try to see what other functionality I could add to this.

Edit: As asked by tanner/_player on IRC: if you want to change the text spoken, the order, etc, just change the text2read=blah line.
Test post. Smile
KermMartian wrote:
souvik1997 wrote:
I get "Warning: failed to fetch/parse feed!". :/
Are you running under Linux? You might need to apt-get install python-feedparser.

Edit: Tari pointed out that if you're missing the package, it would have failed at the import. Do you have flite, the TTS program? If not, you need it. You also need aplay if you don't have it.

I installed alsaplayer-alsa and flite, so I hope it works now. I already had python-feedparser.
Agreed, very cool Smile
souvik1997 wrote:
Test post. Smile
KermMartian wrote:
souvik1997 wrote:
I get "Warning: failed to fetch/parse feed!". :/
Are you running under Linux? You might need to apt-get install python-feedparser.

Edit: Tari pointed out that if you're missing the package, it would have failed at the import. Do you have flite, the TTS program? If not, you need it. You also need aplay if you don't have it.

I installed alsaplayer-alsa and flite, so I hope it works now. I already had python-feedparser.
Did it work out for you? I'm about to mess with the command recognition stuff now; I remember previously working on this.
I wonder if I can get aplay and flite via MacPorts.

[edit]

Evidently not. But it shouldn't be too hard to do something similar with the builtin TTS capabilities of OS X.
KermMartian wrote:
souvik1997 wrote:
Test post. Smile
KermMartian wrote:
souvik1997 wrote:
I get "Warning: failed to fetch/parse feed!". :/
Are you running under Linux? You might need to apt-get install python-feedparser.

Edit: Tari pointed out that if you're missing the package, it would have failed at the import. Do you have flite, the TTS program? If not, you need it. You also need aplay if you don't have it.

I installed alsaplayer-alsa and flite, so I hope it works now. I already had python-feedparser.
Did it work out for you? I'm about to mess with the command recognition stuff now; I remember previously working on this.

Yup, it worked. Great job!
Awesome! I'm going to try Julius as my speech recognition framework; right now it's having difficulty finding my microphone, likely due to the Pulseaudio/ALSA mess my netbook is in. Also, I'm having difficulty finding flite voices; festvox-voices has lots of 20MB-large voices, but those are not compatible with flite.
How difficult is it to change python-feedparser to be something else? There isn't a python-feedparser for iDevices and I'm trying to get it to work on my iPod :/
_player1537 wrote:
How difficult is it to change python-feedparser to be something else? There isn't a python-feedparser for iDevices and I'm trying to get it to work on my iPod :/
There are tons of way to parse RSS; you could even write your own little state machine to do it. In fact, I think you should! Although Benryves would yell at me for promoting the reinvention of the wheel.
*bump* I've abandoned Julius/Julian as a speech recognizer for now due to sadly low accuracy, and I've started experimenting with PocketSphinx. For those who want to replicate my results, thus far I tried the Python bindings, but then reverted to these three packages:

pocketsphinx-utils
pocketsphinx-hmm-wsj
pocketsphinx-lm-wsj1

Then you just run:

pocketsphinx_wsj [-adcdev audiodevicename]

and you start talking!
Is there a way to take just the words out of the output of pocketsphinx_wsj? You posted some regex in the channel, but I am probably using it the wrong way. Here is the regex: ^([0-9]+): WORDS ([\-0-9]+)$
And I was trying to use it like:
Code:
pocketsphinx_wsj | grep -E '^([0-9]+): WORDS ([\-0-9]+)$'
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement