我正在使用天气API让NAO机器人告诉世界上任何城市的天气。我需要NAO来收听一大堆城市。我已经使用过SQLite数据库以及尝试使用后续解析的JSON文件,但是将列表加载到语音识别词汇表中需要很长时间。我可以按地区缩短列表,但有没有办法有效地加载大量词汇?
以下是我尝试成功的例子,但延迟时间约为12秒(这太长了):
import sqlite3 as lite
connectionString = "/home/nao/USCities.db"
myState = "Alabama"
con = lite.connect(connectionString)
with con:
cur = con.cursor()
cur.execute("SELECT cityState FROM USCitiesTable LIMIT 2000")
rows = cur.fetchall()
d = [[s.encode('ascii') for s in list] for list in rows]
listofStrings = map(''.join, d)
vocabulary = listofStrings
self.asr.setVocabulary(vocabulary, False)
self.memory.subscribeToEvent("WordRecognized", self.getName(), "onWordRecognized")
self.hasSubscribed = True