クライアントの構成
658字程度約2分
2024-11-7
構成では、ESP-AI ハードウェア ライブラリに、Wi-Fi 資格情報、サーバー アドレス、ウェイクアップモード、マイク/スピーカー ピン、ボリューム アクションなどの実行方法を説明します。
構造を構成する
決定は、構造フィールドと必要に応じて同じ順序があります。
struct ESP_AI_CONFIG
{
// Debug mode, outputs more logs
bool debug;
// Wi-Fi config
ESP_AI_wifi_config wifi_config;
// Server config
ESP_AI_server_config server_config;
// Offline wake-up config
ESP_AI_wake_up_config wake_up_config;
// Volume control config
ESP_AI_volume_config volume_config;
// Microphone pin config
ESP_AI_i2s_config_mic i2s_config_mic;
// Speaker pin config
ESP_AI_i2s_config_speaker i2s_config_speaker;
// Reset button config
ESP_AI_i2s_reset_btn_config reset_btn_config;
// Light config
ESP_AI_lights_config lights_config;
};デバッグ モード (debug)
デバッグモードでは、开発とトラブルシューティングを簡単にするために、より多くのログが出力されます。
例
bool debug = true;
esp_ai.begin({ debug });Wi-Fi 設定 (ESP_AI_wifi_config)
Wi-Fi接続設定。wifi_name と wifi_pwd の両方がの文字列の際、プロビジョニングは自動的に開始されます。 デバイスのホットスポットに続いた後、192.168.4.1 を开いてプロビジョニングページにアクセスします。 このURLも順次上に印刷されます。onAPInfo。
例
ESP_AI_wifi_config wifi_config = {
.wifi_name = "MyWiFi",
.wifi_pwd = "12345678",
// Hotspot name, default: ESP-AI + last 4 chars of MAC
.ap_name = "ESP-AI",
// Custom provisioning page
// .html_str = "xxx";
// Provisioning mode: AP | BLE
// .way = "AP";
};
// Custom provisioning page (optional)
char html_str[] = "<html><body>Provisioning Page</body></html>";
wifi_config.html_str = html_str;
esp_ai.begin({ debug, wifi_config });カスタム プロビジョニング ページ
リポジトリ内の client\esp-ai\src\webServer\index.html を参照できます。
HOMEストレージに保存できます。 カスタムフィールドをプロビジョニングAPIに信します。サポートされているカスタムフィールドは時のとおりです。 ext1 | ext2 | ext3 | ext4 | ext5 | ext6 | ext7
保存後、getLocalData("ext1")。
ESP-AI。プロビジョニング ページから ESP-AI プロビジョニング サービス API に信するだけです。
サーバー構成 (ESP_AI_server_config)
はい。ユーザーがプロビジョニング ページでオープン プラットフォーム スーパーエージェント api_key を入力した際、これは省略できます。
注記:protocol が https この場合、ポート 443 (またはカスタム HTTPS ポート) を使用する必要があります。
.params 目的:Alone のサービスをデプロイし、追加の涚パラメータが必要な場合は、.params を解いて多います。サーバーは auth でそれらをお知らせできます。
例
ESP_AI_server_config server_config = {
.protocol = "http"
.ip = "192.168.1.100",
.port = 8080,
.params = "key1=value1&key2=value2",
.path = "/api/v1"
};
esp_ai.begin({ debug, ..., server_config });オープンプラットフォームサービスの利用
// Fill in your Open Platform API key
// Note: device binding is required. See the `esp_ai.onBindDevice` function in:
// https://gitee.com/xm124/esp-ai-business-arduino
ESP_AI_server_config server_config = {"http", "node.espai.fun", 80, "api_key=your_open_platform_api_key"};ウェイクアップ設定 (ESP_AI_wake_up_config)
はい。一部手動設定が必要です。。
構造の定義
struct ESP_AI_wake_up_config
{
// Offline wake-up scheme
char wake_up_scheme[20];
// Wake-up threshold: 0-1
float threshold;
// Pin used in pin-based wake-up
int pin;
// Wake-up keyword for serial wake-up
char str[32];
// // Silence timeout before user starts speaking, default 5000
// int vad_first;
// // Silence timeout after user starts speaking, default 1500
// int vad_course;
};例
ESP_AI_wake_up_config wake_up_config = {};
// Mode 1: Voice wake-up (ASRPro module)
strcpy(wake_up_config.wake_up_scheme, "asrpro");
strcpy(wake_up_config.str, "hello xiaoming");
// Mode 2: Pin wake-up
strcpy(wake_up_config.wake_up_scheme, "pin_high");
wake_up_config.pin = 10;
// Mode 3: Serial wake-up
strcpy(wake_up_config.wake_up_scheme, "serial");
strcpy(wake_up_config.str, "start");
esp_ai.begin({ debug, ..., wake_up_config });マイク設定 [オプション] (ESP_AI_i2s_config_mic)
I2Sマスター。
例
ESP_AI_i2s_config_mic i2s_config_mic = {
.bck_io_num = 4, // BCK pin
.ws_io_num = 5, // WS pin
.data_in_num = 6 // DATA input pin
.bits_per_sample=16, // MIC valid bits
.channel_format=I2S_CHANNEL_FMT_ONLY_LEFT, // Channel selection
};
esp_ai.begin({ debug, ..., i2s_config_mic });スピーカー構成 [オプション] (ESP_AI_i2s_config_speaker)
I2S。
例
ESP_AI_i2s_config_speaker i2s_config_speaker = {
.bck_io_num = 16, // BCK pin
.ws_io_num = 17, // WS pin
.data_in_num = 15, // DATA input pin
.sample_rate = 16000 // Sample rate
};
esp_ai.begin({ debug, ..., i2s_config_speaker });ボリューム構成 [オプション] (ESP_AI_volume_config)
ボリュームコントロールのアクションを設定します。ポテンショメータを配線し、ハードウェアのボリュームコントロールを効果的にするピンを設定します。
例
// Default config below, do not change unless needed
ESP_AI_volume_config volume_config = {
.input_pin = 7, // Input pin, default 7
.max_val = 4096, // Maximum output value
.volume = 0.5, // Default volume
.enable = true // Enable potentiometer
};
esp_ai.begin({ debug, ..., volume_config });リセット ボタン (ESP_AI_i2s_reset_btn_config)
デフォルトのピンは IO10 です。
例
// Pin number and trigger level
ESP_AI_reset_btn_config reset_btn_config = { 10, "high" };
esp_ai.begin({ debug, ..., reset_btn_config });ライト作曲 (ESP_AI_lights_config)
デフォルトのピンは IO18 です。ノーマル ESP32-S3 ボードでは、これはノーマル 48 です。
例
// IO pin, LED count
ESP_AI_lights_config lights_config = { 18, 1 };
esp_ai.begin({ debug, ..., lights_config });
