Skip to content

Instantly share code, notes, and snippets.

@KitWallace
Created August 21, 2012 08:05
Show Gist options
  • Save KitWallace/3413355 to your computer and use it in GitHub Desktop.
Save KitWallace/3413355 to your computer and use it in GitHub Desktop.
expanding abbreviations for TTS
# in weather
substitutes = {
"W":"West","N":"North","S":"South","E":"East",
"km/h":"kilometers per hour","C":"Celsius","mph":"miles per hours",
"Mon":"Monday","Tue":"Tuesday","Wed":"Wednesday","Thu":"Thursday","Fri":"Friday","Sat":"Saturday","Sun":"Sunday",
"NNE":"Nor Nor East","NE":"Nor East","ENE":"East Nor East","ESE":"East Sow East",
"SE":"Sow East" ,"SSE" :"Sow Sow East", "SSW":"Sow Sow West","SW":"Sow West","WSW":"West Sow West",
"WNW":"West Nor West","NW":"Nor West","NNW":"Nor Nor West",
"%":"percent"
}
# in xmlutils
def substitute(word,substitutes) :
try :
replacement = substitutes[word]
return '<sub alias="' + replacement +'">'+word+'</sub>'
except :
return word
def expand(text,substitutes) :
return " ".join([substitute(word,substitutes) for word in text.split(" ")])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment