怎么让pyspeech忽略某些词

时间:2013-06-19 02:19:14

标签: python google-maps

您好我在python中使用pyspeech和googlemaps获取方向,我正在尝试让pyspeech说出大声的方向就是说比“< b>”更大,小于和b在代码中有没有办法忽略这些括号,只是说出其余的或方向?

代码:

from googlemaps import GoogleMaps
import speech
api_key = (my key)
gmaps = GoogleMaps(api_key)
place1 = raw_input("Your address: ")
place = raw_input("Destination: ")
start = place1
end = place
dirs = gmaps.directions(start, end)
time = dirs['Directions']['Duration']['seconds']
dist = dirs['Directions']['Distance']['meters']
route = dirs['Directions']['Routes'][0]
for step in route['Steps']:
    print step['descriptionHtml']
    speech.say(step['descriptionHtml'])

1 个答案:

答案 0 :(得分:1)

由于每个step只是字符串,所以您只需使用:

step['descriptionHtml'].replace("<b>", "").replace("</b>", "")

删除HTML标记。

另一个要考虑的选项是文本中只有strip all the HTML,但如果您遇到的唯一标记是<b></b>,那么这可能会有点过分。