Say a Text File to a AIF

Posted on
Wed Jun 27, 2012 2:55 pm
jay (support) offline
Site Admin
User avatar
Posts: 18225
Joined: Mar 19, 2008
Location: Austin, Texas

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)
Twitter | Facebook | LinkedIn

Posted on
Wed Jun 27, 2012 3:00 pm
nsheldon offline
Posts: 2469
Joined: Aug 09, 2010
Location: CA

Re: Say a Text File to a AIF

Nice! That's certainly more elegant than the gobbledygook sed stuff! :-D

Posted on
Wed Jun 27, 2012 6:59 pm
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

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

Posted on
Thu Jun 28, 2012 10:21 am
jay (support) offline
Site Admin
User avatar
Posts: 18225
Joined: Mar 19, 2008
Location: Austin, Texas

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)
Twitter | Facebook | LinkedIn

Posted on
Thu Jun 28, 2012 10:35 am
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

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

Posted on
Thu Jun 28, 2012 3:10 pm
jay (support) offline
Site Admin
User avatar
Posts: 18225
Joined: Mar 19, 2008
Location: Austin, Texas

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)
Twitter | Facebook | LinkedIn

Posted on
Thu Jun 28, 2012 3:18 pm
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

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

Who is online

Users browsing this forum: No registered users and 21 guests