{"id":2092,"date":"2023-05-31T10:40:18","date_gmt":"2023-05-31T02:40:18","guid":{"rendered":"https:\/\/104.es\/?p=2092"},"modified":"2023-07-29T23:06:50","modified_gmt":"2023-07-29T15:06:50","slug":"talk-with-zenbo","status":"publish","type":"post","link":"https:\/\/104.es\/index.php\/2023\/05\/31\/talk-with-zenbo\/","title":{"rendered":"\u3010Zenbo\u3011\u548cZenbo\u8aaa\u8aaa\u8a71\u5427"},"content":{"rendered":"\n<p>\u6a5f\u5668\u4eba\u6700\u68d2\u7684\u4e00\u500b\u529f\u80fd\u5c31\u662f\u53ef\u4ee5\u8ddf\u6211\u5011\u4f7f\u7528\u6211\u5011\u719f\u6089\u7684\u81ea\u7136\u8a9e\u8a00\u5c0d\u8a71\u3002\u9019\u500b\u529f\u80fd\u5176\u5be6\u73fe\u5728\u56e0\u70baChatGPT API\u7684\u63a8\u51fa\uff0c\u4f7f\u7528Python\u7a0b\u5f0f\u5df2\u53ef\u8f15\u6613\u5730\u5728\u81ea\u5df1\u7684\u96fb\u8166\u4e2d\u5be6\u73fe\u4e86\uff0c\u7136\u800c\uff0c\u5c0d\u8a71\u7684\u904e\u7a0b\u5982\u679c\u80fd\u5920\u900f\u904eZenbo\u8aaa\u51fa\u4f86\u7684\u8a71\uff0c\u5c31\u66f4\u6709\u548c\u6a5f\u5668\u4eba\u4e92\u52d5\u7684\u611f\u89ba\u3002\u6211\u5011\u9019\u7bc7\u6587\u7ae0\u5c31\u4f86\u6559\u540c\u5b78\u5011\u5982\u4f55\u5b8c\u6210\u9019\u500b\u6709\u8da3\u7684\u529f\u80fd\u3002<\/p>\n\n\n\n<p>\u5728\u9019\u500b\u4f8b\u5b50\u4e2d\uff0c\u6211\u5011\u60f3\u8981\u8b93\u96fb\u8166\u4f86\u6536\u807d\u4e26\u8fa8\u8b58\u4f7f\u7528\u8005\u8b1b\u8a71\u7684\u5167\u5bb9\uff0c\u5728\u865b\u64ec\u74b0\u5883\u4e2d\u8981\u5148\u5b89\u88dd3\u500b\u6a21\u7d44\uff0c\u5206\u5225\u662fpyaudio\u3001pydub\u3001\u4ee5\u53caSpeechRecognition\u3002\u5b89\u88dd\u5b8c\u7562\u4e4b\u5f8c\uff0c\u5373\u53ef\u5229\u7528\u4ee5\u4e0b\u9019\u500b\u4f8b\u5b50\uff0c\u4f86\u6e2c\u8a66\u4e00\u4e0b\u4f60\u7684\u96fb\u8166\u662f\u5426\u53ef\u4ee5\u9806\u5229\u5730\u5b8c\u6210\u8a9e\u97f3\u8fa8\u8b58\u7684\u529f\u80fd\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import speech_recognition as sr\n\nr = sr.Recognizer()\n\ntext = \"\"\nwhile \"\u7d50\u675f\" not in text:\n    with sr.Microphone() as source:\n        print(\"Listening...\")\n        try:\n            audio_data = r.listen(source=source, timeout=5)\n            text = r.recognize_google(audio_data, language='zh-TW')\n            print(text)\n        except:\n            text = \"\"\nprint(\"Bye!\")<\/code><\/pre>\n\n\n\n<p>\u4e0a\u9762\u7684\u9019\u500b\u7a0b\u5f0f\u6703\u4e0d\u65b7\u5730\u8046\u807d\u6211\u5011\u8b1b\u8a71\u7684\u5167\u5bb9\u4e26\u628a\u9019\u4e9b\u5167\u5bb9\u7ffb\u8b6f\u6210\u6587\u5b57\u4e26\u986f\u793a\u51fa\u4f86\uff0c\u4ee5\u4e0b\u662f\u7a0b\u5f0f\u57f7\u884c\u7684\u904e\u7a0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"916\" height=\"315\" src=\"http:\/\/104es.nkust.org\/wp-content\/uploads\/2023\/05\/image-7.png?w=916\" alt=\"\" class=\"wp-image-2098\" srcset=\"https:\/\/104.es\/wp-content\/uploads\/2023\/05\/image-7.png 916w, https:\/\/104.es\/wp-content\/uploads\/2023\/05\/image-7-300x103.png 300w, https:\/\/104.es\/wp-content\/uploads\/2023\/05\/image-7-768x264.png 768w\" sizes=\"auto, (max-width: 916px) 100vw, 916px\" \/><\/figure>\n\n\n\n<p>\u6709\u4e86\u9019\u500b\u529f\u80fd\u4e4b\u5f8c\uff0c\u6211\u5011\u5c31\u53ef\u4ee5\u628a\u8a9e\u97f3\u8fa8\u8b58\u7684\u529f\u80fd\u8b8a\u6210\u4e00\u500b\u51fd\u5f0f\uff0c\u628a\u5b83\u53eb\u505aget_prompt\uff0c\u53d6\u4ee3\u539f\u672c\u7684input\u51fd\u5f0f\uff0c\u7136\u5f8c\uff0c\u6211\u5011\u5c31\u5b8c\u6210\u4e86\u7528\u81ea\u7136\u8a9e\u8a00\u548cZenbo\u5c0d\u8a71\u7684\u529f\u80fd\u4e86\u3002\u7a0b\u5f0f\u5982\u4e0b\uff0c\u6709\u8208\u8da3\u7684\u540c\u5b78\u5011\u8d95\u5feb\u8a66\u8a66\u770b\u5427\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import speech_recognition as sr\nimport pyzenbo\nimport openai\nfrom pyzenbo.modules.dialog_system import RobotFace\n\nhost = open('ip.txt', \"r\", encoding=\"utf-8\").read()\nsdk = pyzenbo.connect(host)\nkey = open(\"key.txt\", \"r\", encoding=\"utf-8\").read()\nopenai.api_key= key\nr = sr.Recognizer()\n\ndef get_prompt():\n    with sr.Microphone() as source:\n        print(\"Listening...\")\n        try:\n            audio_data = r.listen(source=source, timeout=5)\n            text = r.recognize_google(audio_data, language='zh-TW')\n            print(text)\n        except:\n            text = \"\"\n        return text\nsdk.robot.speak(\"\u4f60\u597d\uff0c\u6211\u662f\u73cd\u5bf6\u842c\u4e8b\u901a\uff0c\u6709\u4ec0\u9ebc\u4e8b\u90fd\u53ef\u4ee5\u554f\u6211\u5594\uff01\")\nprompt = get_prompt()\nwhile \"\u7d50\u675f\" not in prompt:\n    if prompt !=\"\":\n        sdk.robot.set_expression(RobotFace.PLEASED, \"\u4f60\u525b\u525b\u8aaa\uff0c\"+prompt)\n        response = openai.Completion.create(\n            engine='text-davinci-003',\n            prompt=prompt,\n            temperature=0.7,\n            max_tokens=100,\n            n=1,\n            stop=None,\n        )\n        reply = response.choices&#91;0].text.strip()\n        sdk.robot.speak(\"\u6211\u89ba\u5f97\uff1a\"+reply)\n        sdk.robot.speak(\"\u4f60\u9084\u6709\u4ec0\u9ebc\u60f3\u554f\u7684\u55ce\uff1f\")\n    prompt = get_prompt()\nsdk.robot.speak(\"\u90a3\u5c31\u4e0b\u6b21\u518d\u804a\u5427\uff01\")\nsdk.robot.set_expression(RobotFace.HIDEFACE) \nsdk.release()<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6a5f\u5668\u4eba\u6700\u68d2\u7684\u4e00\u500b\u529f\u80fd\u5c31\u662f\u53ef\u4ee5\u8ddf\u6211\u5011\u4f7f\u7528\u6211\u5011\u719f\u6089\u7684\u81ea\u7136\u8a9e\u8a00\u5c0d\u8a71\u3002\u9019\u500b\u529f\u80fd\u5176\u5be6\u73fe\u5728\u56e0\u70baChatGPT API\u7684\u63a8\u51fa\uff0c\u4f7f\u7528Python\u7a0b\u5f0f\u5df2\u53ef\u8f15\u6613\u5730\u5728\u81ea\u5df1\u7684\u96fb\u8166\u4e2d\u5be6\u73fe\u4e86\uff0c\u7136\u800c\uff0c\u5c0d\u8a71\u7684\u904e\u7a0b\u5982\u679c\u80fd\u5920\u900f\u904eZenbo\u8aaa\u51fa\u4f86\u7684\u8a71\uff0c\u5c31\u66f4\u6709\u548c\u6a5f\u5668\u4eba\u4e92\u52d5\u7684\u611f\u89ba\u3002\u6211\u5011\u9019\u7bc7\u6587\u7ae0\u5c31\u4f86\u6559\u540c\u5b78\u5011\u5982\u4f55\u5b8c\u6210\u9019\u500b\u6709\u8da3\u7684\u529f\u80fd\u3002<\/p>\n","protected":false},"author":1,"featured_media":2150,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-2092","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-asus-zenbo"],"jetpack_featured_media_url":"https:\/\/104.es\/wp-content\/uploads\/2023\/05\/zenbo.jpg","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/2092","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/comments?post=2092"}],"version-history":[{"count":2,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/2092\/revisions"}],"predecessor-version":[{"id":2353,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/2092\/revisions\/2353"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/media\/2150"}],"wp:attachment":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/media?parent=2092"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/categories?post=2092"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/tags?post=2092"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}