def main(tok): bt = baidu_tts() bs = baidu_stt(1, 2, 3, 4) r = recorder() youdao = youdao_tts() appKey = selfset['ts']['appkey'] secretkey = selfset['ts']['secretkey'] httpClient = None myurl = '/api' q = 'good' bt.tts('请问您要翻译的是什么语言?', tok) speaker.speak() speaker.ding() r.record() speaker.dong() fromLang = lang_choose(bs.stt('./voice.wav', tok), tok) bt.tts('请问您要翻译为什么语言?', tok) speaker.speak() speaker.ding() r.record() speaker.dong() toLang = lang_choose(bs.stt('./voice.wav', tok), tok) bt.tts('请说出您要翻译的内容', tok) speaker.speak() speaker.ding() r.tsrecord() speaker.dong() tstext = bs.stt('./voice.wav', tok) salt = random.randint(1, 65536) sign = appKey+q+str(salt)+secretKey m1 = md5.new() m1.update(sign) sign = m1.hexdigest() myurl = myurl + '?appKey=' + appKey + '&q=' + urllib.quote(q) + '&from=' + fromLang + '&to=' + toLang + '&salt=' + str(salt) + '&sign=' + sign try: httpClient = httplib.HTTPConnection('openapi.youdao.com') httpClient.request('GET', myurl) #response是HTTPResponse对象 response = httpClient.getresponse() json = json.loads(response.read()) try: youdao.tts('第一种意思为,' + json['translation'][0] + ',第二种意思为,' + json['translation'][1], toLang) speaker.speak() except: youdao.tts('翻译结果为' + json['translation'][0], toLang) speaker.speak() except Exception, e: print e
def __init__(self): self.awaken = Xiaolan.awaken() self.selfset = setting.setting() self.r = recorder() self.bt = baidu_tts() self.yt = youdao_tts() self.bs = baidu_stt(1, 2, 3, 4) self.sk = Skills() self.sm = hass() self.mu = xlMusic() self.ma = maps() self.xlnlu = Nlu() self.tok = bt.get_token()
def main(tok): bt = baidu_tts() yt = youdao_tts() bs = baidu_stt(1, 2, 3, 4) r = recorder() selfset = setting.setting() hash = hashlib.md5() bt.tts('您好,请说出您的快递单号和快递公司', tok) speaker.speak() speaker.ding() r.exrecord() speaker.dong() idss = bs.stt('./voice.wav', tok) ids = number_choose(ids, tok) requestData = { 'OrderCode': ids, 'ShipperCode': service, 'LogisticCode':'12345678' } data = { 'EBusinessID': '1349773', 'RequestType': '1002', 'RequestData': parse.quote(str(requestData)), 'DataType': '2', } strings = str(requestData) + '1f0c5c35-67a8-495f-b3ab-a7fc534a826f' string = strings.encode(encoding='UTF-8',errors='strict') hashs.update(string) s = hashs.hexdigest().encode('utf-8') y = base64.b64encode(s) z = str(y, 'utf-8') data['DataSign'] = parse.quote(z, 'utf-8') r = requests.post('http://api.kdniao.cc/Ebusiness/EbusinessOrderHandle.aspx', data=data) json = r.json() try: bt.tts(json['Traces'][-1]['AcceptStation'], tok) speaker.speak() except KeyError: bt.tts('对不起,包裹信息查询失败', tok) speaker.speak()
def main(tok): bt = baidu_tts() yt = youdao_tts() bs = baidu_stt(1, 2, 3, 4) r = recorder() selfset = setting.setting() hash = hashlib.md5() bt.tts('您好,请说出您要查询的快递单号', tok) speaker.speak() speaker.ding() r.exrecord() speaker.dong() requestData = { 'OrderCode': '', 'ShipperCode': 'YTO', 'LogisticCode': number_choose(bs.stt('./voice.wav', tok), tok) } data = { 'EBusinessID': selfset['express']['EBusinessID'], 'RequestType': '1002', 'RequestData': urllib.urlencode(str(requestData)), 'DataType': '2', } hash.update(str(requestData) + selfset['express']['key'], encoding='utf-8') data['DataSign'] = urllib.urlencode(base64.b64encode(hash.hexdigest())) json = requests.post( 'http://api.kdniao.cc/Ebusiness/EbusinessOrderHandle.aspx', data=data, headers='application/x-www-form-urlencoded;charset=utf-8') try: bt.tts(json['Traces'][-1]['AcceptStation'], tok) speaker.speak() except KeyError: bt.tts('对不起,包裹信息查询失败', tok) speaker.speak()