mirror of
https://github.com/CodeLabClub/codelab_adapter_extensions.git
synced 2024-11-25 16:36:27 +08:00
<feat>: update yanshee, add start_auto_transform, get_transform_result
This commit is contained in:
parent
9a9e3fc413
commit
ffc83c882a
@ -2,18 +2,21 @@
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 10,
|
||||
"execution_count": 28,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# pip3 install logger https://github.com/UBTEDU/Yan_ADK/archive/latest.tar.gz\n",
|
||||
"import time\n",
|
||||
"import json\n",
|
||||
"\n",
|
||||
"import openadk\n",
|
||||
"from openadk.rest import ApiException\n",
|
||||
"from openadk.models.motions_parameter import MotionsParameter\n",
|
||||
"from openadk.models.motions_operation import MotionsOperation\n",
|
||||
"from openadk.api.motions_api import MotionsApi\n",
|
||||
"from loguru import logger\n",
|
||||
"import time\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class Robot:\n",
|
||||
" def __init__(self, node=None):\n",
|
||||
@ -87,12 +90,50 @@
|
||||
" timestamp = int(time.time())\n",
|
||||
" api_instance = openadk.VoiceApi(openadk.ApiClient(self.configuration))\n",
|
||||
" body = openadk.VoiceTTSStr(content) # VoiceTTSStr |\n",
|
||||
" api_response = api_instance.put_voice_tts(body)"
|
||||
" api_response = api_instance.put_voice_tts(body)\n",
|
||||
" \n",
|
||||
" def start_auto_transform(self):\n",
|
||||
" if not self.configuration:\n",
|
||||
" return\n",
|
||||
" api_instance = openadk.VoiceApi(openadk.ApiClient(self.configuration))\n",
|
||||
" body = openadk.VoiceIatRequest() # VoiceIatRequest | (optional)\n",
|
||||
"\n",
|
||||
" try:\n",
|
||||
" # Start auto transform\n",
|
||||
" api_response = api_instance.put_voice_iat(body=body)\n",
|
||||
" logger.debug(api_response)\n",
|
||||
" except ApiException as e:\n",
|
||||
" error_message = f\"Exception when calling VoiceApi->put_voice_iat: {str(e)}\"\n",
|
||||
" logger.error(error_message)\n",
|
||||
" if node:\n",
|
||||
" node.pub_notification(error_message, type=\"ERROR\")\n",
|
||||
" \n",
|
||||
" def get_transform_result(self):\n",
|
||||
" if not self.configuration:\n",
|
||||
" return\n",
|
||||
" api_instance = openadk.VoiceApi(openadk.ApiClient(self.configuration))\n",
|
||||
" try:\n",
|
||||
" # Get auto transform(iat) result\n",
|
||||
" api_response = api_instance.get_voice_iat()\n",
|
||||
" logger.debug(api_response)\n",
|
||||
" except ApiException as e:\n",
|
||||
" error_message = f\"Exception when calling VoiceApi->get_voice_iat: {str(e)}\"\n",
|
||||
" logger.error(error_message)\n",
|
||||
" if node:\n",
|
||||
" node.pub_notification(error_message, type=\"ERROR\")\n",
|
||||
" # 接口返回的是以转义字符结尾的字符串,去除转义字符并转为 python dict\n",
|
||||
" normalization_res = api_response.data.replace(\"\\x00\", \"\")\n",
|
||||
" n = json.loads(normalization_res)\n",
|
||||
" # 将结果拼接为语音指令\n",
|
||||
" cmd = \"\"\n",
|
||||
" for i in n['text']['ws']:\n",
|
||||
" cmd += i['cw'][0]['w']\n",
|
||||
" return cmd"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 11,
|
||||
"execution_count": 29,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -101,15 +142,15 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 12,
|
||||
"execution_count": 30,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"2020-06-02 16:05:23.799 | DEBUG | __main__:ping_robot:35 - {'code': 0,\n",
|
||||
" 'data': {'charging': 0, 'percent': 93, 'voltage': 4048},\n",
|
||||
"2020-06-04 16:13:49.938 | DEBUG | __main__:ping_robot:38 - {'code': 0,\n",
|
||||
" 'data': {'charging': 0, 'percent': 91, 'voltage': 4021},\n",
|
||||
" 'msg': 'success'}\n"
|
||||
]
|
||||
},
|
||||
@ -119,7 +160,7 @@
|
||||
"True"
|
||||
]
|
||||
},
|
||||
"execution_count": 12,
|
||||
"execution_count": 30,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@ -130,7 +171,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 18,
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -178,24 +219,61 @@
|
||||
"robot.play(name=\"Forward\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"robot.play(name=\"Stop\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 25,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"2020-06-04 16:11:43.717 | DEBUG | __main__:start_auto_transform:96 - {'code': 0, 'data': '{}', 'msg': 'Success'}\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"robot.start_auto_transform()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 31,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"2020-06-04 16:13:55.455 | DEBUG | __main__:get_transform_result:110 - {'code': 0,\n",
|
||||
" 'data': '{\"text\":{\"bg\":0,\"ed\":0,\"ls\":false,\"sn\":1,\"ws\":[{\"bg\":0,\"cw\":[{\"sc\":0,\"w\":\"你好\"}]}]}}\\x00',\n",
|
||||
" 'msg': 'Success',\n",
|
||||
" 'status': 'idle',\n",
|
||||
" 'timestamp': None}\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"{'code': 0, 'data': {'total_time': 1790}, 'msg': 'success'}"
|
||||
"'你好'"
|
||||
]
|
||||
},
|
||||
"execution_count": 25,
|
||||
"execution_count": 31,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"robot.play(name=\"Stop\")"
|
||||
"robot.get_transform_result() # after start auto transform"
|
||||
]
|
||||
}
|
||||
],
|
||||
@ -215,7 +293,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.2"
|
||||
"version": "3.8.3"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
Loading…
Reference in New Issue
Block a user