View unanswered posts | View active topics It is currently Sat May 25, 2013 3:21 am



Reply to topic  [ 22 posts ]  Go to page: Previous  1, 2
 Say a Text File to a AIF 
Author Message
Site Admin
User avatar

Joined: Mar 19, 2008
Posts: 6665
Location: Austin, Texas
Post Re: Say a Text File to a AIF
This python script should work - I'm unclear why it's needed as an AIF file so I just have the Indigo Server say the article titles.

Code: Select all
import urllib2
import xml.dom.minidom

f = urllib2.urlopen("http://query.yahooapis.com/v1/public/yql?q=select%20title%20from%20rss%20where%20url%3D%22http%3A%2F%2Fwww.npr.org%2Frss%2Frss.php%3Fid%3D1001%22&diagnostics=true")
dom = xml.dom.minidom.parse(f)
f.close()
sayString = ""
for titleElem in dom.getElementsByTagName("title"):
   sayString += "%s\n" % titleElem.firstChild.data

# Unclear if you really need it spoken to a file
# so I'll just tell the server to speak the string
indigo.server.speak(sayString)


You'll probably want to run this as an external script so that if the network connection is slow the script won't get killed prematurely.

_________________
Jay (Indigo Support)
Image


Wed Jun 27, 2012 2:55 pm
Profile WWW

Joined: Aug 09, 2010
Posts: 767
Location: CA
Post Re: Say a Text File to a AIF
Nice! That's certainly more elegant than the gobbledygook sed stuff! :-D


Wed Jun 27, 2012 3:00 pm
Profile WWW

Joined: Nov 26, 2009
Posts: 930
Location: Kalispell, MT
Post Re: Say a Text File to a AIF
Very nice, thanks a bunch! I have my Squeezebox Radio do most my announcements etc.
hence the aif file.

Thanks,

Carl


Wed Jun 27, 2012 6:59 pm
Profile
Site Admin
User avatar

Joined: Mar 19, 2008
Posts: 6665
Location: Austin, Texas
Post Re: Say a Text File to a AIF
This one does the same thing but saves it into the specified file - just change the path to the output file. If the path has spaces in it I think you'll need to precede them with a backslash.

Code: Select all
import urllib2
import xml.dom.minidom
import subprocess

f = urllib2.urlopen("http://query.yahooapis.com/v1/public/yql?q=select%20title%20from%20rss%20where%20url%3D%22http%3A%2F%2Fwww.npr.org%2Frss%2Frss.php%3Fid%3D1001%22&diagnostics=true")
dom = xml.dom.minidom.parse(f)
f.close()
sayString = ""
for titleElem in dom.getElementsByTagName("title"):
   sayString += "%s.\n" % titleElem.firstChild.data
   
# So we need to call the "say" command-line tool to
# record the string spoken into an .aif file
subprocess.call(["say", "-o", "/PATH/TO/RSS.aif", sayString])

_________________
Jay (Indigo Support)
Image


Thu Jun 28, 2012 10:21 am
Profile WWW

Joined: Nov 26, 2009
Posts: 930
Location: Kalispell, MT
Post Re: Say a Text File to a AIF
Thanks. Curious about something... I've been getting the "rest query" to use in my scripts from this site http://developer.yahoo.com/yql/console/#h=select%20title%20from%20rss%20where%20url%3D%22http%3A//www.jokesareawesome.com/rss/random/%22

Works fine for just titles but am not seeing how to have the body text included as well. Is that a different process?

Thanks,

Carl


Thu Jun 28, 2012 10:35 am
Profile
Site Admin
User avatar

Joined: Mar 19, 2008
Posts: 6665
Location: Austin, Texas
Post Re: Say a Text File to a AIF
No clue - I just used your URL, I know nothing about your data source... ;)

_________________
Jay (Indigo Support)
Image


Thu Jun 28, 2012 3:10 pm
Profile WWW

Joined: Nov 26, 2009
Posts: 930
Location: Kalispell, MT
Post Re: Say a Text File to a AIF
Thanks Jay...it's always something. Trying to have Indigo read a random joke when prompted.

Carl


Thu Jun 28, 2012 3:18 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 22 posts ]  Go to page: Previous  1, 2

Who is online

Users browsing this forum: No registered users and 2 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.   Template designed by STSoftware.