背景
测试环境不能采用真实打电话,不能拿到ASR语音转文本的数据,只能模拟ASR语音转文本去请求对话处理接口,于是乎就有了以下的一段脚本,模拟一通电话坐席跟客户的对话。
import requests import json,random,time from automation import public_data as p #请求Go对话处理接口 def qndialog(data): url = "http://ip:port/qnDialog" headers = { 'Content-Type':'application/json' } response = requests.post(url=url, headers=headers, data=json.dumps(data)) result = response.json() return result if __name__ =="__main__": sum = 0 #传参 data = { "enterpriseId": "2000000002", "callList": { "recordId": "100001", "initialagentId": "123456", "curuserdn": "123456", "talkertype": "02418242307249", "begintime": "1582254653", "endtime": "1582254698", "agentID": "10081", "callCentraTag": "ccod", "isEnd": False }, "taskData": { "bps": 39000, "eps": 44090, "index": 15, "callType": "2", "text": "嗯嗯,什么事", "silence_duration": 600, "speech_rate": 100, "emotion_value": "neutral" } } #模拟一通电话13段对话 for i in range(21): time.sleep(1) sum += 1 if i % 21 == 0: agentid = str(random.randint(10000, 10099)) recordid = str(random.randint(2000000, 2999999)) data["callList"]["agentID"] = agentid data["callList"]["recordId"] = recordid data["taskData"]["callType"] = "2" data["taskData"]["text"] = '您的年龄属于以下哪个组别' data["callList"]["isEnd"] = False print(qndialog(data)) elif i % 21 == 1: data["callList"]["agentID"] = agentid data["callList"]["recordId"] = recordid data["taskData"]["callType"] = "1" data["taskData"]["text"] = '我16到17岁有劳动收入' data["callList"]["isEnd"] = False print(qndialog(data)) elif i % 21 == 2: data["callList"]["agentID"] = agentid data["callList"]["recordId"] = recordid data["taskData"]["callType"] = "2" data["taskData"]["text"] = '您有几年年非保本类投资产品的经验' data["callList"]["isEnd"] = False print(qndialog(data)) elif i % 21 == 3: data["callList"]["agentID"] = agentid data["callList"]["recordId"] = recordid data["taskData"]["callType"] = "1" data["taskData"]["text"] = '没有投资过' data["callList"]["isEnd"] = False print(qndialog(data)) elif i % 21 == 4: data["callList"]["agentID"] = agentid data["callList"]["recordId"] = recordid data["taskData"]["callType"] = "2" data["taskData"]["text"] = '下方的哪个选项能说明您的投资经验请您说一个' data["callList"]["isEnd"] = False print(qndialog(data)) elif i % 21 == 5: data["callList"]["agentID"] = agentid data["callList"]["recordId"] = recordid data["taskData"]["callType"] = "1" data["taskData"]["text"] = '没经验' data["callList"]["isEnd"] = False print(qndialog(data)) elif i % 21 == 6: data["callList"]["agentID"] = agentid data["callList"]["recordId"] = recordid data["taskData"]["callType"] = "2" data["taskData"]["text"] = '您目前的非保本资产占总资产的百分之几' data["callList"]["isEnd"] = False print(qndialog(data)) elif i % 21 == 7: data["callList"]["agentID"] = agentid data["callList"]["recordId"] = recordid data["taskData"]["callType"] = "1" data["taskData"]["text"] = '百分之零' data["callList"]["isEnd"] = False print(qndialog(data)) elif i % 21 == 8: data["callList"]["agentID"] = agentid data["callList"]["recordId"] = recordid data["taskData"]["callType"] = "2" data["taskData"]["text"] = '以下哪种描述最适用于您对于投资收益的态度' data["callList"]["isEnd"] = False print(qndialog(data)) elif i % 21 == 9: data["callList"]["agentID"] = agentid data["callList"]["recordId"] = recordid data["taskData"]["callType"] = "1" data["taskData"]["text"] = '希望得到高额的回报' data["callList"]["isEnd"] = False print(qndialog(data)) elif i % 21 == 10: data["callList"]["agentID"] = agentid data["callList"]["recordId"] = recordid data["taskData"]["callType"] = "2" data["taskData"]["text"] = '您愿意接受多少年的投资年限' data["callList"]["isEnd"] = False print(qndialog(data)) elif i % 21 == 11: data["callList"]["agentID"] = agentid data["callList"]["recordId"] = recordid data["taskData"]["callType"] = "1" data["taskData"]["text"] = '5年以上' data["callList"]["isEnd"] = False print(qndialog(data)) elif i % 21 == 12: data["callList"]["agentID"] = agentid data["callList"]["recordId"] = recordid data["taskData"]["callType"] = "2" data["taskData"]["text"] = '除了储蓄存款之外,有多少比重是可以用于投资的' data["callList"]["isEnd"] = False print(qndialog(data)) elif i % 21 == 13: data["callList"]["agentID"] = agentid data["callList"]["recordId"] = recordid data["taskData"]["callType"] = "1" data["taskData"]["text"] = '占了一半以上' data["callList"]["isEnd"] = False print(qndialog(data)) elif i % 21 == 14: data["callList"]["agentID"] = agentid data["callList"]["recordId"] = recordid data["taskData"]["callType"] = "2" data["taskData"]["text"] = '您随时可以调动的金额相当于您所负担几个月的家庭开支' data["callList"]["isEnd"] = False print(qndialog(data)) elif i % 21 == 15: data["callList"]["agentID"] = agentid data["callList"]["recordId"] = recordid data["taskData"]["callType"] = "1" data["taskData"]["text"] = '没有可以随时调用的钱' data["callList"]["isEnd"] = False print(qndialog(data)) elif i % 21 == 16: data["callList"]["agentID"] = agentid data["callList"]["recordId"] = recordid data["taskData"]["callType"] = "2" data["taskData"]["text"] = '您投资的目的是什么' data["callList"]["isEnd"] = False print(qndialog(data)) elif i % 21 == 17: data["callList"]["agentID"] = agentid data["callList"]["recordId"] = recordid data["taskData"]["callType"] = "1" data["taskData"]["text"] = 'A' data["callList"]["isEnd"] = False print(qndialog(data)) elif i % 21 == 18: data["callList"]["agentID"] = agentid data["callList"]["recordId"] = recordid data["taskData"]["callType"] = "2" data["taskData"]["text"] = '好的,谢谢' data["callList"]["isEnd"] = False print(qndialog(data)) elif i % 21 == 19: data["callList"]["agentID"] = agentid data["callList"]["recordId"] = recordid data["taskData"]["callType"] = "1" data["taskData"]["text"] = '再见' data["callList"]["isEnd"] = True print(qndialog(data)) elif i % 21 == 20: data["callList"]["agentID"] = agentid data["callList"]["recordId"] = recordid data["taskData"]["callType"] = "2" data["taskData"]["text"] = '再见' data["callList"]["isEnd"] = True print(qndialog(data)) else: pass print(sum)