Journal

Thai Wake Word ด้วย Porcupine + Rasa NLU: Voice Command สมาร์ทโฮมภาษาไทยแบบ Local ไม่ส่งเสียงขึ้น Cloud

Thai Wake Word with Porcupine + Rasa NLU: Local Thai Voice Commands for Smart Home Without Cloud ASR

12 พฤษภาคม 2569 · 1 นาที
24.5°C · 52%

Thai Voice Command ที่เป็นส่วนตัว: ไม่มีใครฟังนอกจากบ้านคุณ

ระบบ voice command ส่วนใหญ่ (Google Assistant, Siri, Alexa) ส่งเสียงทุกคำพูดไปประมวลผลบน cloud server ของบริษัทต่างชาติ ระบบ Local Voice Command ประมวลผลทุกอย่างในบ้าน ไม่มีเสียงพูดออกนอกเครือข่าย

สถาปัตยกรรม: 3 ชั้น

Microphone → Wake Word Detection (Porcupine) → ASR (Whisper local) → NLU (Rasa) → Home Assistant

ชั้นที่ 1: Thai Wake Word ด้วย Porcupine

Picovoice Porcupine เป็น on-device wake word engine ที่รัน binary บน CPU ปกติ: ฝึก Custom Wake Word:

  1. ไปที่ Picovoice Console 2. เลือกภาษา Thai 3. พิมพ์ wake word ที่ต้องการ เช่น บ้านฉลาด หรือ เฮ้บ้าน 4. ดาวน์โหลด model file (ฟรีสำหรับ 3 wake words) ใช้งานบน Raspberry Pi 5:
python import pvporcupine import pyaudio import struct  porcupine = pvporcupine.create(     access_key='YOUR_PICOVOICE_KEY',     keyword_paths=['บ้านฉลาด_th_raspberry-pi.ppn'] )  pa = pyaudio.PyAudio() audio_stream = pa.open(     rate=porcupine.sample_rate,     channels=1,     format=pyaudio.paInt16,     input=True,     frames_per_buffer=porcupine.frame_length )  while True:     pcm = audio_stream.read(porcupine.frame_length)     pcm = struct.unpack_from('h' * porcupine.frame_length, pcm)     result = porcupine.process(pcm)     if result >= 0:         # Wake word detected - start recording command         record_and_transcribe()

CPU usage: ~2% บน Raspberry Pi 5 สำหรับ continuous wake word monitoring

ชั้นที่ 2: Whisper ASR ภาษาไทย (Local)

หลัง wake word detect → บันทึก audio 3–5 วินาที → ส่งให้ Whisper ถอดเสียงเป็นข้อความ:

python import whisper  model = whisper.load_model('small', device='cpu')  # ~461MB, Thai-capable  def transcribe_thai(audio_file):     result = model.transcribe(audio_file, language='th', fp16=False)     return result['text']  # Thai text

Whisper small model: 461MB, Thai transcription WER ~8–12% สำหรับประโยคคำสั่งสั้นๆ Rasberry Pi 5: ~3–5 วินาที/transcription (ยอมรับได้สำหรับ home automation)

ชั้นที่ 3: Rasa NLU Thai Intent Recognition

Rasa เป็น open-source NLU framework ที่รองรับภาษาไทยผ่าน Thai tokenizer:

yaml # domain.yml intents:   - turn_on_light   - turn_off_light   - set_temperature   - lock_door   - check_air_quality  entities:   - room   - temperature_value  responses:   utter_confirm:     - text: เรียบร้อยแล้ว
yaml # nlu.yml (training data) nlu: - intent: turn_on_light   examples: |     - เปิดไฟห้องนั่งเล่น     - เปิดไฟที่ห้องนอน     - ช่วยเปิดไฟให้หน่อย     - สว่างหน่อยได้ไหม     - เปิดแสงสิ  - intent: set_temperature   examples: |     - ตั้งแอร์ที่ 25 องศา     - เย็นลงหน่อยได้ไหม     - ปรับอุณหภูมิเป็น [24](temperature_value) องศา

ฝึก Rasa ด้วยคำสั่งไทย 20–30 ตัวอย่างต่อ intent ให้ได้ accuracy ~90%+

Home Assistant Integration

Rasa classify intent → ส่ง HTTP request → HA REST API:

python def handle_intent(intent, entities):     if intent == 'turn_on_light':         room = entities.get('room', 'living_room')         ha_service_call('light', 'turn_on',                         entity_id=f'light.{room}')     elif intent == 'set_temperature':         temp = entities.get('temperature_value', 25)         ha_service_call('climate', 'set_temperature',                         temperature=float(temp))

Latency และ Privacy

| ขั้นตอน | เวลา | |---------|------| | Wake word detection | <50ms (continuous) | | Audio recording (3s) | 3,000ms | | Whisper transcription | 3,000–5,000ms | | Rasa NLU classification | <200ms | | HA service call | <500ms | | รวม | ~7–9 วินาที | ไม่มีข้อมูลเสียงออกนอก local network ทั้งสิ้น

คำถามที่พบบ่อย

Porcupine รองรับ Wake Word ภาษาไทยจริงไหม?
Picovoice รองรับภาษาไทยอย่างเป็นทางการตั้งแต่ปี 2023 สามารถสร้าง custom Thai wake word ได้จาก Picovoice Console โดยใช้ text เป็น input ไม่จำเป็นต้องบันทึกเสียงตัวเอง model ทำงานได้กับ Thai phonology
Whisper กับ WangchanBERTa ต่างกันอย่างไรสำหรับ Thai ASR?
Whisper เป็น general-purpose ASR ที่ทำงานได้ดีกับภาษาไทยโดยไม่ต้อง fine-tune เหมาะสำหรับ voice command WangchanBERTa เป็น language model สำหรับ text classification ไม่ใช่ ASR ต้องใช้ร่วมกับ Wav2Vec2 หรือ model อื่นสำหรับ speech-to-text
ระบบนี้รองรับผู้ใช้หลายคนในบ้านได้ไหม?
Rasa NLU classify intent จาก text ไม่ใช่จาก speaker identity ดังนั้นทุกคนในบ้านใช้คำสั่งเดียวกันได้ ถ้าต้องการ speaker identification เพิ่มเติม สามารถเพิ่ม speaker diarization layer ด้วย pyannote.audio