Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การแก้ไขปัญหา >> ข้อผิดพลาด Windows

วิธีติดตั้ง Google Assistant บน Windows PC

Google Assistant มีอยู่บนเกือบทุก Android Phone ที่เปิดตัว gầnมา แตไม่มี Desktop Version อย่างเป็นทางการ แต่วันนี้จะแสดงวิธี (ค่อนข้างขี้เกียจ) ที่ได้ Google Assistant ทำงานบน Windows Machine

ขณะเขียน ไม่มี GUI สวยงามสำหรับสิ่งที่จะทำ และการติดตั้งจะอาศัย Command Lines เป็นหลัก แตเมื่อทำงานได้แล้ว คุณสามารถพูดเข้ามิกโทรศัพท์คอมพิวเตอร์เหมือนกับ Android Device เพื่อควบคุม Google Assistant

ข้อกำหนดเบื้องต้น

  • Python 3

ก่อนอื่น ต้องติดตั้ง Python บนคอมพิวเตอร์ และเพิ่มเข้า Path ทำตามขั้นตอนอย่างระมัดระวัง ดาวน์โหลดและรัน Python Installer .exe ให้ทำ Custom Install บนหน้าจอตัวเลือกที่ 2 ให้ติ๊ก "Add Python to environment variables"

วิธีติดตั้ง Google Assistant บน Windows PC

ติดตั้ง Python เสร็จ เปิด Command Terminal พิมพ์ "python" (ไม่ต้องใส่เครื่องหมายคำพูด) หากทุกอย่างปกติ Command Prompt จะแสดง Python Version ปัจจุบัน

ตอนนี้ต้องตั้งค่า Google Assistant API

  1. ไปที่หน้า Projects ใน Google Cloud Platform Console
  2. คลิก "Create Project" ด้านบน
  3. ตั้งชื่อ Project ว่า "Google Assistant" คลิก Create
  4. Console จะสร้าง Project ใหม่ ควรเห็น Spinning Progress Icon มุมขวาบน จบแล้วจะไปหน้า Project Configuration
  5. ไปหน้า Google Assistant API คลิก "Enable" ด้านบน
  6. เพื่อใช้ API ต้องสร้าง Credentials คลิกปุ่ม "Create credentials" มุมขวาบน Setup Wizard จะนำทาง
  7. ใต้ "Where will you be calling the API from?" เลือก "Other UI (e.g. Windows, CLI tool)" สำหรับ "What data will you be accessing?" เลือกวงกลม "User data" คลิก "What credentials do I need?"
  8. Google แนะนำสร้าง OAuth 2.0 Client ID ตั้งชื่อ Client ID ให้ Unique คลิก "Create client ID"
  9. ใต้ "Product name shown to users" ใส่ "My Google Assistant" หรืออะไรคล้ายๆ กัน
  10. คลิก "Done" แต อย่าคลิก Download ที่นี่ เราต้องแค่ Client Secret
  11. ในรายการ OAuth 2.0 Client IDs จะเห็น Client ID ที่เพิ่งสร้าง ด้านขวาสุด คลิกไอคอน Download เพื่อดาวน์โหลดไฟล์ client_secret_XXX.json โดย XXX คือ Client ID ของคุณ บันทึกไฟล์ไว้ที่ไหนก็ได้ แนะนำโฟลเดอร์ใหม่ชื่อ "google assistant"
  12. ไปหน้า Activity Controls ของ Google Account ตรวจสอบว่า "Web & App Activity", "Location History", "Device Information", และ "Voice & Audio Activity" เปิดอยู่ทั้งหมด เพื่อให้ Google Assistant อ่านข้อมูลส่วนตัวได้

ตอนนี้ต้องตั้งค่า Client ที่จะเข้าถึง Google Assistant API

เปิด Command Terminal พิมพ์คำสั่งต่อไปนี้:

วิธีติดตั้ง Google Assistant บน Windows PC

 

-m pip install google-assistant-sdk[samples]

จะเริ่มติดตั้ง Dependencies ที่ Python ต้องการ จบแล้ว ใส่คำสั่งต่อไป (เปลี่ยน Path Directory ในคำสั่ง)

py -m googlesamples.assistant.auth_helpers --client-secrets change\your\path\client_secret_XXX.apps.googleusercontent.com.json

ใน Command Prompt จะแสดง URL ให้ไป Authorize Application คัดลอก URL ไป Browser ใช้ Google Account เดียวกับที่ตั้งค่า Google Assistant API จะได้ Access Token สำหรับ Client คัดลอก Access Token ใส่ใน Command Prompt ที่ถาม

ตอนนี้ทดสอบว่า Google Assistant เข้าถึง Microphone ได้หรือไม่ พิมพ์ใน Command Prompt:

python -m googlesamples.assistant.audio_helpers

หากเล่น Audio ให้ฟังสำเร็จ สามารถสื่อสารกับ Google Assistant ได้ พิมพ์ใน Command Prompt:

python -m googlesamples.assistant

รอจนขึ้น "press Enter to send new request" กด Enter บนคีย์บอร์ด เริ่มพูดเข้ามิก ตอนพูดเสร็จ Command Prompt จะแสดง Transcript ของที่พูด และเล่น Response ของ Google Assistant

Command Prompt ข้างต้นเป็นวิธีโต้ตอบกับ Google Assistant API ที่ดูไม่สวยนัก แตโชคดีว่ามี Extension สำหรับ Chrome Browser ชื่อ "AutoVoice" ที่ต้องการแค่ Google Assistant Setup บนคอมพิวเตอร์ (ซึ่งเราทำเสร็จแล้ว!) แตต้องทำ Command Prompt Magic อีกนิดเพื่อ Setup ให้เหมาะสม

เปิด Command Prompt คัดลอกคำสั่งต่อไปนี้:

py -c "from distutils.sysconfig import get_python_lib; from urllib.request import urlretrieve; urlretrieve('https://joaoapps.com/AutoApps/Help/Info/com.joaomgcd.autovoice/googleassistant/__main__.py', get_python_lib() + '/googlesamples/assistant/__main__.py')"

ไปหน้า AutoVoice Extension ด้วย Chrome Browser ติดตั้ง ใน Extension Options ตั้ง Wake-up Command เป็น "Hey Google" หรือ "Okay Google" หรืออะไรก็ได้

เปิด Always Listening ตั้ง Wake up Expression เป็นอย่างอื่นที่ไม่ใช่ Wake-up Command จำไว้ - Expression หนึ่ง喚醒 Extension อีก Expression หนึ่ง喚醒 Google Assistant

พิมพ์ใน Command Prompt:

py -m googlesamples.assistant

ตอนนี้พูด "Hey Google!" หรือ Expression ที่ตั้งไว้ เพื่อ喚醒 Google Assistant และสั่งงานทันที ("Hey Google, what's the weather today?")