ArduinoVN
Đăng nhập Tham gia
Dự án / ESP32 / Trung Bình /u/linucat

Xe robot điều khiển bằng giọng nói qua app Android

Nói "đi tới", "quay trái", "dừng" — xe phản hồi. App Android "Arduino Bluetooth Voice" dùng Google Speech recognition gửi command qua Bluetooth tới ESP32.

Danh sách linh kiện

CSV
Linh kiện SL Đơn giá Thành tiền Đã có Mua
Tổng chi phí còn lại:

Các bước thực hiện

6 bước

Bước 1: Kiến trúc

Voice recognition trực tiếp trên ESP32 khá khó. Cách dễ nhất: app Android dùng Google Speech-to-Text (free, tích hợp sẵn) → convert thành text → gửi text command qua Bluetooth tới ESP32 → ESP32 parse text + điều khiển motor.

Workflow:

  1. Bạn nói "đi tới" vào điện thoại.
  2. App Android dùng Google Voice API convert → "đi tới".
  3. App gửi "di toi" qua Bluetooth.
  4. ESP32 nhận "di toi" → forward motor.

Bước 2: Linh kiện và đấu nối

Tương tự dự án Xe robot Bluetooth (Phase 2). Cần:

  • Kit khung xe 2 bánh + 2 motor + L298N.
  • ESP32 DevKit.
  • Pin 2× 18650.

Đấu nối motor giống Xe robot Bluetooth. App khác = OK với cùng hardware.

Bước 3: App Android

Option 1: App có sẵn

Cài "Arduino Bluetooth Voice Controller" hoặc "AMR_Voice" trên Play Store. Pair với ESP32 → app có nút mic → bấm và nói. App tự gửi text qua Bluetooth.

Lưu ý: text gửi thường KHÔNG có dấu, lowercase, có dấu cách. VD: "di toi", "quay trai", "dung lai".

Option 2: MIT App Inventor DIY

Build app tự code khoảng 30 phút. Module SpeechRecognizer + BluetoothClient. Trigger speech → khi nhận text → send via BT.

Bước 4: Code ESP32

Parse command đa từ với hashmap đơn giản:

voice_car.ino — C++ / Arduino
#include <BluetoothSerial.h>

BluetoothSerial BT;

const int IN1=25, IN2=26, IN3=27, IN4=14;
const int ENA=32, ENB=33;
const int SPEED = 180;

void setMotor(int l, int r) {
  digitalWrite(IN1, l >= 0 ? HIGH : LOW);
  digitalWrite(IN2, l >= 0 ? LOW : HIGH);
  digitalWrite(IN3, r >= 0 ? HIGH : LOW);
  digitalWrite(IN4, r >= 0 ? LOW : HIGH);
  analogWrite(ENA, abs(l));
  analogWrite(ENB, abs(r));
}

void forward()  { setMotor(SPEED, SPEED); }
void backward() { setMotor(-SPEED, -SPEED); }
void turnLeft() { setMotor(-SPEED, SPEED); }
void turnRight(){ setMotor(SPEED, -SPEED); }
void stopAll()  { setMotor(0, 0); }

void xuLyCommand(String cmd) {
  cmd.toLowerCase();
  cmd.trim();
  Serial.print("CMD: "); Serial.println(cmd);

  // Match keywords trong cmd (linh hoat)
  if (cmd.indexOf("di toi") != -1 || cmd.indexOf("forward") != -1 ||
      cmd.indexOf("tien") != -1) {
    forward();
  } else if (cmd.indexOf("lui") != -1 || cmd.indexOf("back") != -1) {
    backward();
  } else if (cmd.indexOf("trai") != -1 || cmd.indexOf("left") != -1) {
    turnLeft();
    delay(500);
    stopAll();
  } else if (cmd.indexOf("phai") != -1 || cmd.indexOf("right") != -1) {
    turnRight();
    delay(500);
    stopAll();
  } else if (cmd.indexOf("dung") != -1 || cmd.indexOf("stop") != -1) {
    stopAll();
  } else if (cmd.indexOf("quay vong") != -1) {
    turnRight();
    delay(1000);
    stopAll();
  } else {
    BT.println("Khong hieu: " + cmd);
  }
}

void setup() {
  for (int p : {IN1, IN2, IN3, IN4, ENA, ENB}) pinMode(p, OUTPUT);
  Serial.begin(115200);
  BT.begin("ESP32-VoiceCar");
  Serial.println("Ready");
}

void loop() {
  if (BT.available()) {
    String cmd = BT.readStringUntil('\n');
    xuLyCommand(cmd);
  }
}

Bước 5: Test và tinh chỉnh

Quy trình:

  1. Pair điện thoại với "ESP32-VoiceCar".
  2. Mở "Arduino Bluetooth Voice" → kết nối.
  3. Bấm mic, nói rõ "đi tới" — chờ ~1 giây Google trả lời.
  4. App gửi text → xe đi.

Mẹo:

  • Nói rõ, không quá nhanh.
  • Môi trường yên tĩnh — tiếng ồn → Google nhận sai.
  • Internet phải có — Google STT chạy cloud.
  • App có thể lặp lại text — code indexOf match flexible.

Bước 6: Mở rộng và voice offline

Mở rộng:

  • Thêm command "bật đèn" → trigger LED/relay.
  • Voice feedback: ESP32 phát buzzer mã hoá "đã nhận lệnh".
  • Action chain: "đi tới 3 giây rồi quay trái" — parse số trong text.
  • Multi-language: thêm command tiếng Anh + Việt.

Voice offline:

  • Module Voice Recognition V3 (Elechouse, ~250k) — train tối đa 80 từ tiếng Việt offline.
  • ESP32-S3 + TensorFlow Lite Micro — keyword spotting cơ bản.
  • Cả 2 đều khó hơn nhiều so với Google STT app.

Thảo luận (0)

Đăng nhập để tham gia thảo luận.
Chưa có bình luận nào. Hãy là người đầu tiên!