Community project

AI Voice Cat Companion

Photo of AI Voice Cat Companion
Generated with AI

[2C04] 成果 CHENG GUO

Published December 5, 2026

This AI Voice Cat Companion brings an interactive feline friend to life on an ESP32 microcontroller. The device listens for voice input through an I²S microphone, processes it with cloud-based AI, and responds with synthesized speech through a speaker while displaying expressive cat face animations on a small LCD screen.

Builders will receive a complete wiring diagram connecting the microphone module, amplifier breakout, capacitive touch sensor, and LCD display to the ESP32, along with a full parts list, firmware with AI integration, and step-by-step assembly instructions covering screen installation, microphone and touch sensor mounting, and amplifier-to-speaker connection.

Wiring diagram

Wiring diagram for AI Voice Cat Companion
Loading diagram…

Gather all the parts

QtyComponent
1

HiLetgo INMP441 I²S Microphone Module

Omnidirectional 24-bit I²S MEMS microphone module based on the TDK InvenSense INMP441 IC. Outputs digital audio over a 3-wire I²S bus (SCK/BCLK, WS/LRCLK, SD/DOUT). Supply 1.8–3.3 V; native 3.3 V operation with no level shifting required. L/R channel select pin: tie to GND for left-channel mono output or VDD for right-channel mono output. Use the ESP32 Arduino core or ESP-IDF I2S peripheral API; no separate PlatformIO library is required.

1

MAX98357A I2S Class-D Mono Amplifier Breakout

I2S-input Class-D mono audio amplifier IC on a compact breakout board. Accepts I2S digital audio input (BCLK, LRC, DIN) and drives a small speaker or transducer directly. No I2C/SPI control bus is needed. The amplifier supply range is 2.5V-5.5V, and the I2S input pins are compatible with 3.3V logic. SD/MODE controls shutdown and channel selection; GAIN selects 3 dB, 6 dB, 9 dB, 12 dB, or 15 dB gain.

1

TTP223 Capacitive Touch Sensor Module

Single-pad capacitive touch sensor module based on the TTP223 IC. Outputs a digital HIGH/LOW signal on touch/release. Operates at 2.0–5.5V (3.3V compatible). No firmware library required — output is read as a standard digital GPIO input. Default mode is momentary (active HIGH on touch); solder pads on module allow toggling to active-LOW or self-locking (toggle) mode.

1

Waveshare 1.83inch LCD Module Rev2

Waveshare SKU 26784 Rev2 1.83-inch IPS LCD module with 240×284 pixels, ST7789P controller, 65K colours, 4-wire write-only SPI, GH1.25 8-pin interface, and 3.3V/5V operation.

1

8Ω Speaker

8 Ω / 3 W

Generic small 8Ω 0.5-3W loudspeaker (~28mm typical). Pair with an I2S amp (MAX98357A) or class-D amp (TPA3116D2) for usable volume; do not drive directly from a GPIO pin. Audio output for music/voice playback.

Assemble it in 3 steps

1. 断电接好屏幕

按接线图连接 Waveshare 1.83 英寸 Rev2;CLK 是时钟,DIN 是图像数据,BL 和 VCC 都接 3V3。

  • 这套接线使用 GPIO38,请使用 RGB 灯接 GPIO48 的 DevKitC-1 v1.0,不要照搬到 v1.1。

2. 安装麦克风和头顶触摸板

两个模块均用 3V3;麦克风 L/R 接地,确保收音孔无遮挡;触摸板使用默认的触摸时输出高电平模式。

3. 接功放和喇叭

功放 VIN 接 5V,GND 接开发板 GND;喇叭两根线只接 SPK+ 和 SPK-。SD 和 GAIN 保留模块默认设置。

  • 不要把任一喇叭线接地。使用供电稳定的 USB 电源。

Review all connections

1. Connections between "mic" and "ESP32"

FunctionmicESP32
digitalSCKGPIO 4
digitalWSGPIO 5
dataSDGPIO 6
groundL/RGND
powerVDD3V3
groundGNDGND

2. Connections between "amp" and "ESP32"

FunctionampESP32
dataBCLKGPIO 7
dataLRCGPIO 15
dataDINGPIO 16
powerVIN5V
groundGNDGND
dataSPK+ → 8Ω Speaker POSEXT
dataSPK- → 8Ω Speaker NEGEXT

3. Connections between "touch" and "ESP32"

FunctiontouchESP32
digitalSIGGPIO 8
powerVCC3V3
groundGNDGND

4. Connections between "lcd" and "ESP32"

FunctionlcdESP32
spiCLKGPIO 21
spiDINGPIO 47
digitalRSTGPIO 38
digitalDCGPIO 39
spiCSGPIO 40
powerVCC3V3
powerBL3V3
groundGNDGND

Deploy the firmware

#include <Arduino.h>
#include <SPI.h>
#include <Adafruit_ST7789.h>
#include <ArduinoJson.h>
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <HTTPClient.h>
#include <driver/i2s.h>
#include <mbedtls/base64.h>
#include <time.h>
#include "settings.h"

Adafruit_ST7789 lcd(&SPI,40,39,38);
constexpr int TOUCH=8, RATE=16000, SAMPLES=RATE*2;
const String host="https://dashscope.aliyuncs.com";
const String chatPath="/compatible-mode/v1/chat/completions";
enum Face {Idle, Breathe, Blink, Listen, Think, Happy, Puzzled, Speak, Error};
Face shown=Error;
bool painted=false, audioReady=false;
String prevQuestion,prevAnswer;
void face(Face f){
 if(painted && f==shown)return;
 painted=true;shown=f;
 uint16_t bg=f==Error?0x7800:f==Think?0x3010:f==Idle?0x1084:0x1949;
 lcd.fillScreen(bg);
 int y=f==Idle?119:116;
 lcd.fillTriangle(30,y,48,y-61,101,y-18,0xFD8C);
 lcd.fillTriangle(210,y,192,y-61,139,y-18,0xFD8C);
 lcd.fillRoundRect(25,y-23,190,124,50,0xFD8C);
 for(int x:{78,162}){
  if(f==Blink || f==Happy){lcd.drawLine(x-14,y+25,x,y+17,0);lcd.drawLine(x,y+17,x+14,y+25,0);}
  else lcd.fillRoundRect(x-8,y+12,16,f==Listen?34:24,7,0);
  if(f==Puzzled)lcd.drawLine(x-14,y+2,x+14,y+10,0);
 }
 lcd.fillTriangle(111,y+45,129,y+45,120,y+54,0x8808);
 lcd.fillCircle(120,y+65,f==Listen?9:5,0);
 const char* label[]={"READY","READY","READY","LISTENING","THINKING","HAPPY","CURIOUS","SPEAKING","CHECK SERIAL"};
 lcd.setTextColor(ST77XX_WHITE);lcd.setTextSize(2);lcd.setCursor(28,232);lcd.print(label[f]);
}
bool i2sSetup(i2s_port_t port,bool rx){
 i2s_config_t c={};c.mode=(i2s_mode_t)(I2S_MODE_MASTER|(rx?I2S_MODE_RX:I2S_MODE_TX));
 c.sample_rate=RATE;c.bits_per_sample=rx?I2S_BITS_PER_SAMPLE_32BIT:I2S_BITS_PER_SAMPLE_16BIT;
 c.channel_format=rx?I2S_CHANNEL_FMT_ONLY_LEFT:I2S_CHANNEL_FMT_RIGHT_LEFT;
 c.communication_format=I2S_COMM_FORMAT_STAND_I2S;c.dma_buf_count=6;c.dma_buf_len=256;c.tx_desc_auto_clear=true;
 i2s_pin_config_t p={};p.mck_io_num=I2S_PIN_NO_CHANGE;p.bck_io_num=rx?4:7;p.ws_io_num=rx?5:15;
 p.data_in_num=rx?6:I2S_PIN_NO_CHANGE;p.data_out_num=rx?I2S_PIN_NO_CHANGE:16;
 return i2s_driver_install(port,&c,0,nullptr)==ESP_OK && i2s_set_pin(port,&p)==ESP_OK;
}
void le(uint8_t* p,uint32_t v,int n){while(n--){*p++=v;v>>=8;}}
uint32_t rd(const uint8_t* p,int n){uint32_t v=0;while(n--)v=(v<<8)|p[n];return v;}
String capture(){
 const size_t len=44+2*SAMPLES;
 uint8_t* wav=(uint8_t*)malloc(len);if(!wav)return "";
 memset(wav,0,44);memcpy(wav,"RIFF",4);le(wav+4,len-8,4);memcpy(wav+8,"WAVEfmt ",8);
 le(wav+16,16,4);le(wav+20,1,2);le(wav+22,1,2);le(wav+24,RATE,4);le(wav+28,2*RATE,4);
 le(wav+32,2,2);le(wav+34,16,2);memcpy(wav+36,"data",4);le(wav+40,len-44,4);
 i2s_start(I2S_NUM_0);int32_t raw[256];
 for(int offset=0;offset<SAMPLES;){size_t got=0;
  size_t bytes=4*min(256,SAMPLES-offset);
  if(i2s_read(I2S_NUM_0,raw,bytes,&got,pdMS_TO_TICKS(250))!=ESP_OK || !got){free(wav);i2s_stop(I2S_NUM_0);return "";}
  for(size_t i=0;i<got/4;i++)le(wav+44+2*offset++,constrain(raw[i]/16384,-32768,32767),2);
 }
 i2s_stop(I2S_NUM_0);
 // Encode incrementally so the WAV and full encoded copy need not coexist in extra buffers.
 String body;const char* prefix=R"({"model":"qwen3-asr-flash","stream":false,"messages":[{"role":"user","content":[{"type":"input_audio","input_audio":{"data":"data:audio/wav;base64,)";
 if(!body.reserve(4*((len+2)/3)+256)){free(wav);return "";}
 body=prefix; unsigned char enc[1025];
 for(size_t i=0;i<len;i+=768){size_t count=0;mbedtls_base64_encode(enc,sizeof(enc),&count,wav+i,min(size_t(768),len-i));body.concat((const char*)enc,count);}
 free(wav);body+=R"("}}]}]})";return body;
}
bool post(const String& path,String& body,JsonDocument& out){
 WiFiClientSecure tls;tls.setCACert(TRUSTED_ROOTS);
 HTTPClient http;http.setTimeout(17000);http.setConnectTimeout(6000);http.useHTTP10(true);
 if(!http.begin(tls,host+path))return false;
 http.addHeader("Authorization",String("Bearer ")+DASHSCOPE_KEY);http.addHeader("Content-Type","application/json");
 int code=http.POST((uint8_t*)body.c_str(),body.length());body=String();
 if(code!=200){Serial.printf("Cloud HTTP: %d\n",code);return false;}
 return !deserializeJson(out,http.getStream(),DeserializationOption::NestingLimit(16));
}
bool touched(){return digitalRead(TOUCH)==HIGH;}
bool play(const String& url){
 if(!url.startsWith("https://"))return false;
 WiFiClientSecure tls;tls.setCACert(TRUSTED_ROOTS);HTTPClient http;http.useHTTP10(true);http.setTimeout(3500);http.setConnectTimeout(6000);
 if(!http.begin(tls,url)||http.GET()!=200)return false;
 Stream& s=http.getStream(); s.setTimeout(800);
 auto read=[&](uint8_t* p,size_t n){return !touched() && s.readBytes(p,n)==n;};
 uint8_t b[512];if(!read(b,12)||memcmp(b,"RIFF",4)||memcmp(b+8,"WAVE",4))return false;
 uint32_t rate=0,n=0;int channels=0;
 for(int i=0;i<24;i++){
  if(!read(b,8))return touched();n=rd(b+4,4);
  if(!memcmp(b,"data",4))break;
  bool fmt=!memcmp(b,"fmt ",4);if(n>65536)return false;
  if(fmt){if(n<16||!read(b,16)||rd(b,2)!=1||rd(b+14,2)!=16)return false;channels=rd(b+2,2);rate=rd(b+4,4);n-=16;}
  n+=(n&1);while(n){size_t k=min(n,uint32_t(sizeof b));if(!read(b,k))return touched();n-=k;}
 }
 if(!n || n>2000000 || rate<8000 || rate>48000 || (channels!=1&&channels!=2) || n%(2*channels))return false;
 if(i2s_set_clk(I2S_NUM_1,rate,I2S_BITS_PER_SAMPLE_16BIT,I2S_CHANNEL_STEREO)!=ESP_OK)return false;
 i2s_start(I2S_NUM_1);bool ok=true;int16_t stereo[512];
 while(n&&!touched()){
  size_t k=min(n,uint32_t(sizeof b));if(!read(b,k)){ok=touched();break;}
  for(size_t j=0;j<k/(2*channels);j++){
   stereo[2*j]=(int16_t)rd(b+j*2*channels,2)/3;
   stereo[2*j+1]=channels==1?stereo[2*j]:(int16_t)rd(b+j*4+2,2)/3;
  }
  size_t got=0,len=k*2/channels;
  if(i2s_write(I2S_NUM_1,stereo,len,&got,pdMS_TO_TICKS(100))!=ESP_OK||got!=len){ok=false;break;}
  n-=k;
 }
 if(!touched()&&ok)for(int i=0;i<120&&!touched();i+=5)delay(5);
 i2s_stop(I2S_NUM_1);i2s_zero_dma_buffer(I2S_NUM_1);
 return ok;
}
bool converse(){
 if(!audioReady||!WIFI_NAME[0]||!DASHSCOPE_KEY[0]||!TRUSTED_ROOTS[0]){Serial.println("Check audio or fill src/settings.h");return false;}
 if(WiFi.status()!=WL_CONNECTED||time(nullptr)<1700000000){Serial.println("Waiting for Wi-Fi and time sync");return false;}
 face(Listen);String body=capture();face(Think);if(!body.length()){Serial.println("Recording or memory error");return false;}
 JsonDocument res,req;if(!post(chatPath,body,res))return false;
 String question=res["choices"][0]["message"]["content"]|"";if(!question.length())return false;
 res.clear();req["model"]="qwen-plus";req["enable_thinking"]=false;req["max_tokens"]=200;
 auto msgs=req["messages"].to<JsonArray>();
 auto message=[&](const char* role,const String& text){auto m=msgs.add<JsonObject>();m["role"]=role;m["content"]=text;};
 message("system","你是桌宠猫。用用户的语言简短回答,最多两句话。第一行仅写 HAPPY、PUZZLED 或 NEUTRAL;第二行写给用户听的回答。开心话题用 HAPPY,复杂问题用 PUZZLED。");
 if(prevQuestion.length()){message("user",prevQuestion);message("assistant",prevAnswer);}
 message("user",question);serializeJson(req,body);req.clear();
 if(!post(chatPath,body,res))return false;
 String answer=res["choices"][0]["message"]["content"]|"";res.clear();answer.trim();
 int split=answer.indexOf('\n');String emotion=split<0?"":answer.substring(0,split);emotion.trim();
 if(emotion=="HAPPY"||emotion=="PUZZLED"||emotion=="NEUTRAL")answer.remove(0,split+1);
 answer.trim();if(!answer.length())return false;
 req["model"]="qwen3-tts-flash";req["input"]["text"]=answer;req["input"]["voice"]="Cherry";req["input"]["language_type"]="Auto";
 serializeJson(req,body);req.clear();
 if(!post("/api/v1/services/aigc/multimodal-generation/generation",body,res))return false;
 String url=res["output"]["audio"]["url"]|"";res.clear();
 face(emotion=="HAPPY"?Happy:emotion=="PUZZLED"?Puzzled:Speak);
 if(!play(url)){Serial.println("Audio URL or WAV playback error");return false;}
 prevQuestion=question;prevAnswer=answer;return true;
}
void setup(){
 Serial.begin(115200);pinMode(TOUCH,INPUT_PULLDOWN);SPI.begin(21,-1,47,40);lcd.init(240,284);face(Idle);
 audioReady=i2sSetup(I2S_NUM_0,true)&&i2sSetup(I2S_NUM_1,false);
 if(audioReady){i2s_stop(I2S_NUM_0);i2s_stop(I2S_NUM_1);}
 if(WIFI_NAME[0]){WiFi.mode(WIFI_STA);WiFi.setAutoReconnect(true);WiFi.begin(WIFI_NAME,WIFI_PASSWORD);configTime(0,0,"ntp.aliyun.com","pool.ntp.org");}
}
void loop(){
 static uint32_t next=0, breath=0;
 if((shown==Idle||shown==Breathe) && millis()-breath>=850){breath=millis();face(shown==Idle?Breathe:Idle);}
 if(touched()){delay(35);if(!touched())return;uint32_t start=millis();face(Happy);
  while(touched()&&millis()-start<500)delay(10);
  if(touched()){while(touched())delay(20);delay(250);if(!converse()){face(Error);delay(1600);} }
  else delay(280);
  while(touched())delay(20);face(Idle);next=millis()+2600;
 }else if((int32_t)(millis()-next)>=0){face(Blink);delay(115);face(Idle);next=millis()+random(2000,4200);}
 delay(12);
}

Remix this project

Make it yours in one click

Open a full copy of this project in your own Schematik workspace, diagram, code, parts, and assembly steps included. Swap the sensor, add features, or redesign the whole thing with AI. The author's original stays untouched.

Open in Schematik