Beispiel #1
0
def say_URL(url):
    # Set up SpeechTokenizer to handle HTML tags
    st = token.SpeechTokenizer()
    st.add_rules(rules.html_rules)

    text = urllib.urlopen(url).read()
    text = token.untokenize(st.tokenize(text))

    tts.say_text(text)
    return text
def say_URL(url):
	# Set up SpeechTokenizer to handle HTML tags
	st = token.SpeechTokenizer()
	st.add_rules(rules.html_rules)

	text = urllib.urlopen(url).read()
	text = token.untokenize(st.tokenize(text))

	tts.say_text(text)
	return text
Beispiel #3
0
def say_text(s):
    text = process(s)
    tts.say_text(text)
    return text
def say_text(s):
	text = process(s)
	tts.say_text(text)
	return text
to the tts module to be converted to speech.

As the URL and the regular expression are both hard-coded, this application
is very sensitive to changes in the location and layout of the target web
page.
"""

import urllib, re
import nltk_contrib.misc.festival.tts as tts

URL	= "http://www.bom.gov.au/cgi-bin/wrap_fwo.pl?IDV10450.txt"
REGEXP	= "(Forecast for Melbourne .*)Suburban"

try:
	page = urllib.urlopen(URL).read()
except IOError, e:
	print "Unable to connect to web server."
	sys.exit(1)

x = re.search(REGEXP, page, re.DOTALL)  # DOTALL ensures newlines are included

if x:
	text = x.group(1)
	print text

	tts.initialize()
	tts.say_text(text)

else:
	print "Web page does not have the expected format."