diff --git a/17.DIY智能硬件ESP8266篇.docx b/17.DIY智能硬件ESP8266篇.docx index b333f9a..44c8016 100644 Binary files a/17.DIY智能硬件ESP8266篇.docx and b/17.DIY智能硬件ESP8266篇.docx differ diff --git a/17.DIY智能硬件ESP8266篇.pdf b/17.DIY智能硬件ESP8266篇.pdf index dc9f064..29ae515 100644 Binary files a/17.DIY智能硬件ESP8266篇.pdf and b/17.DIY智能硬件ESP8266篇.pdf differ diff --git a/2.组件接入基础篇.docx b/2.组件接入基础篇.docx index c08bd33..1f4f426 100644 Binary files a/2.组件接入基础篇.docx and b/2.组件接入基础篇.docx differ diff --git a/2.组件接入基础篇.pdf b/2.组件接入基础篇.pdf index 0e433f4..ad87691 100644 Binary files a/2.组件接入基础篇.pdf and b/2.组件接入基础篇.pdf differ diff --git a/ais_cli.py b/ais_cli.py new file mode 100644 index 0000000..b505a07 --- /dev/null +++ b/ais_cli.py @@ -0,0 +1,38 @@ +""" +This is the client to public AIs' API for voice_assistant. +""" + +import requests + +class tuling123(object): + def __init__(self, user_id, api_key, base_url='http://openapi.tuling123.com/openapi/api/v2'): + self._session = requests.Session() + + self._base_url = base_url + self._base_data = { 'reqType': 0, + 'userInfo': { + 'apiKey': api_key, + 'userId': user_id + }, + 'perception': { + 'inputText': { + 'text': '' + } + } + } + + + def command(self, input_sentence): + data = self._base_data + data['perception']['inputText']['text'] = input_sentence + + r = self._session.post(url=self._base_url, json = data) + output = r.json() + + ouput_sentence = None + for result in output['results']: + if result['resultType']=='text': + ouput_sentence = result['values']['text'] + break + + return(ouput_sentence)