国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

【ESP32S3 Sense接入語音識別+MiniMax模型對話】

這篇具有很好參考價(jià)值的文章主要介紹了【ESP32S3 Sense接入語音識別+MiniMax模型對話】。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

1. 前言

圍繞ESP32S3 Sense接入語音識別+MiniMax模型對話展開,首先串口輸入“1”字符,隨后麥克風(fēng)采集2s聲音數(shù)據(jù),對接百度在線語音識別,將返回文本結(jié)果丟入MiniMax模型,進(jìn)而返回第二次結(jié)果文本,實(shí)現(xiàn)語言對話文本效果。以上一共有兩次調(diào)用,后期只需加入tts模塊就可完整對話。

講解視頻:

ESP32S3 Sense接入語音識別+MiniMax模型對話

目前這是我使用的ESP32S3官方硬件??????(小小的身材有大大的力量)只需要35元加攝像頭麥克風(fēng)79元,后期我會整理相關(guān)專欄進(jìn)行Arduino系統(tǒng)學(xué)習(xí)??????。有需要可以購買xiao開發(fā)板??????,SeeedXIAO ESP32S3 Sense硬件購買地址:https://s.click.taobao.com/lekazrt
esp32接入語音平臺,arduino學(xué)習(xí),語音識別,人工智能,Arduino,esp32

1.1 語音接入

百度在線語音接入教程:
【ESP32S3 Sense接入百度在線語音識別】
esp32接入語音平臺,arduino學(xué)習(xí),語音識別,人工智能,Arduino,esp32

使用Seeed XIAO ESP32S3 Sense開發(fā)板接入百度智能云實(shí)現(xiàn)在線語音識別。自帶麥克風(fēng)模塊用做語音輸入,通過串口發(fā)送字符“1”來控制數(shù)據(jù)的采集和上傳。

1.2 大模型接入

國產(chǎn)大模型接入分享如下:
【ESP32接入國產(chǎn)大模型之MiniMax】
【ESP32接入語言大模型之智譜清言】
【ESP32接入國產(chǎn)大模型之文心一言】
【ESP32接入語言大模型之通義千問】

下面是不標(biāo)準(zhǔn)測評,推薦使用MiniMax大模型,參考而已
esp32接入語音平臺,arduino學(xué)習(xí),語音識別,人工智能,Arduino,esp32

MM智能助理是一款由MiniMax自研的,沒有調(diào)用其他產(chǎn)品的接口的大型語言模型。MiniMax是一家中國科技公司,一直致力于進(jìn)行大模型相關(guān)的研究。

模型 響應(yīng)時(shí)間 內(nèi)容質(zhì)量 免費(fèi)token次數(shù) 地址
MiniMax 3s 8分 500萬 https://www.minimaxi.com/
智譜清言 7s 8分 300萬 https://open.bigmodel.cn/
文心一言 10s 9分 500萬 https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Nlks5zkzu
通義千問 8s 8分 800萬 https://tongyi.aliyun.com/qianwen/

這一次還是采用Arduino編程就會輕松許多開發(fā)。這樣就可以把stt+chat大模型裝進(jìn)口袋啦??????,接下來就只差tts播報(bào)啦!

esp32接入語音平臺,arduino學(xué)習(xí),語音識別,人工智能,Arduino,esp32

2. 先決條件

在繼續(xù)此項(xiàng)目之前,請確保檢查以下先決條件。

我們將使用 Arduino IDE 對 ESP32/ESP8266 開發(fā)板進(jìn)行編程,因此在繼續(xù)本教程之前,請確保已在 Arduino IDE 中安裝這些開發(fā)板。

2.1 環(huán)境配置

  1. Arduino IDE:下載并安裝 Arduino IDE;
  2. ESP32 開發(fā)板庫:在 Arduino IDE 中添加 ESP32 支持;
    參考博客:【esp32c3配置arduino IDE教程】
    為安裝過程留出一些時(shí)間,具體時(shí)間可能因您的互聯(lián)網(wǎng)連接而異。

2.2 所需零件

要學(xué)習(xí)本教程,您需要1個 ESP32 開發(fā)板+馬克風(fēng)或者ESP32 Sense,建議使用后者,筆者發(fā)現(xiàn)同樣的代碼后者可以輕松調(diào)用,ESP32不行(可能板子壞了)。

esp32接入語音平臺,arduino學(xué)習(xí),語音識別,人工智能,Arduino,esp32

3. 核心代碼

提供兩種硬件測試

  1. ESP32S3 Sense
  2. ESP32 + max9814麥克風(fēng)模塊用做語音輸入,一個按鍵來控制數(shù)據(jù)的采集和上傳

3.1 ESP32S3 Sense

esp32接入語音平臺,arduino學(xué)習(xí),語音識別,人工智能,Arduino,esp32
ESP32S3 Sense自帶麥克風(fēng)直接燒錄
Arduino代碼如下

#include <Arduino.h>
#include "base64.h"
#include <WiFi.h>
#include "HTTPClient.h"
#include "cJSON.h"
#include <I2S.h>
#include <ArduinoJson.h>
#define data_len 16000
// #define key 4             //端口0
// #define ADC 2             //端口39
// #define led 15            //端口2

HTTPClient http_client;
// 1. Replace with your network credentials
const char* ssid = "J09 502";
const char* password = "qwertyuiop111";
// 2. Check your Aduio port
const int buttonPin = 1;  // the number of the pushbutton pin
const int ledPin = 21;    // the number of the LED pin
hw_timer_t* timer = NULL;
uint16_t adc_data[data_len];    //16000個數(shù)據(jù),8K采樣率,即2秒,錄音時(shí)間為2秒,想要實(shí)現(xiàn)更長時(shí)間的語音識別,就要改這個數(shù)組大小
                                //和下面data_json數(shù)組的大小,改大一些。
uint8_t adc_start_flag = 0;     //開始標(biāo)志
uint8_t adc_complete_flag = 0;  //完成標(biāo)志
char data_json[45000];          //用于儲存json格式的數(shù)據(jù),大一點(diǎn),JSON編碼后數(shù)據(jù)字節(jié)數(shù)變成原來的4/3,所以得計(jì)算好,避免出現(xiàn)越界

// 3. Replace with your MiniMax API key
const char* apiKey = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJHcm91cE5hbWUiOiIyMzQ1dm9yIiwiVXNlck5hbWUiOiIyMzQ1dm9yIiwiQWNjb3VudCI6IiIsIlN1YmjE3NTk0ODIxODAxMDAxNzAyMDgiLCJQI6IjE3NTk0ODIxODAwOTU5NzU5MDQiLCJQYWdlTmFtZSI6IiIsIk1haWwiOiIiLCJDcmVhdGVUaW1lIjoiMjAyNC0wMy0xNiAxMzoyNDoxOCIsImlzcyI6Im1pbmltYXgifQ.WlEj8Nk0j_WOMXZE9SbIC8sHpwJ6R6Pi8Spl5mahJsW3-Jsz7Ev53sGGz3v__Bd5dDkt7o9-Y8BOW0WZq2ImaN7Rof7YNtYnYnvPNDyGx23_xRqq5co9P5UkC3ciYEcIch2SUZ5QPkXR-sMUPzhdowSYvfdu1N25kdKJ8GE_63NfCnsdDVt8mv0wQSSweJK0yf_C8a8ADdB1uF4vg_WKMDjHlvzERsoNZgX6FYtr-bee85rIyu4U-OrbUvEpR1FLPXa7lTlx65QvhVIYGbIKde7ERIT_7QLOQoVFvPz0gX-H6V7UlmSRgRy4LK_R9mvV5TqCy3v90WK_AFuwEhPXcg";
HTTPClient http;
String token_key = String("Bearer ") + apiKey;
// Send request to MiniMax API
String inputText = "你好,minimax!";
String apiUrl = "https://api.minimax.chat/v1/text/chatcompletion_v2";
int httpResponseCode;
String response,question,answer;
DynamicJsonDocument jsonDoc(1024);

uint32_t num = 0;
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
void IRAM_ATTR onTimer() {
  // Increment the counter and set the time of ISR
  portENTER_CRITICAL_ISR(&timerMux);
  if (adc_start_flag == 1) {
    //Serial.println("");
    // adc_data[num] = analogRead(ADC);
    adc_data[num] = I2S.read();
    num++;
    if (num >= data_len) {
      adc_complete_flag = 1;
      adc_start_flag = 0;
      num = 0;
      //Serial.println(Complete_flag);
    }
  }
  portEXIT_CRITICAL_ISR(&timerMux);
}

String getGPTAnswer(String inputText) {
  http.begin(apiUrl);
  http.addHeader("Content-Type", "application/json");
  http.addHeader("Authorization", token_key);
  String payload = "{\"model\":\"abab5.5s-chat\",\"messages\":[{\"role\": \"system\",\"content\": \"你是鵬鵬的生活助手機(jī)器人,要求下面的回答嚴(yán)格控制在256字符以內(nèi)。\"},{\"role\": \"user\",\"content\": \"" + inputText + "\"}]}";
  httpResponseCode = http.POST(payload);
  if (httpResponseCode == 200) {
    response = http.getString();
    http.end();
    Serial.println(response);
    // Parse JSON response
    deserializeJson(jsonDoc, response);
    String outputText = jsonDoc["choices"][0]["message"]["content"];
    return outputText;
    // Serial.println(outputText);
  } else {
    http.end();
    Serial.printf("Error %i \n", httpResponseCode);
    return "<error>";
  }
}

void setup() {

  //Serial.begin(921600);
  Serial.begin(115200);
  // pinMode(ADC, ANALOG);
  // pinMode(buttonPin, INPUT_PULLUP);
  pinMode(ledPin, OUTPUT);
  // start I2S at 16 kHz with 16-bits per sample
  I2S.setAllPins(-1, 42, 41, -1, -1);
  if (!I2S.begin(PDM_MONO_MODE, 16000, 16)) {
    Serial.println("Failed to initialize I2S!");
    while (1)
      ;  // do nothing
  }
  uint8_t count = 0;
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    count++;
    if (count >= 75) {
      Serial.printf("\r\n-- wifi connect fail! --");
      break;
    }
    vTaskDelay(200);
  }
  Serial.printf("\r\n-- wifi connect success! --\r\n");
  Serial.println(WiFi.localIP());
  http.setTimeout(10000);
  // gain_token();

  timer = timerBegin(0, 80, true);    //  80M的時(shí)鐘 80分頻 1M
  timerAlarmWrite(timer, 125, true);  //  1M  計(jì)125個數(shù)進(jìn)中斷  8K
  timerAttachInterrupt(timer, &onTimer, true);
  timerAlarmEnable(timer);
  timerStop(timer);  //先暫停
}


uint32_t time1, time2;
void loop() {

  if (Serial.available() > 0)  //按鍵按下
  {
    if (Serial.read() == '1') {
      Serial.printf("Start recognition\r\n\r\n");
      digitalWrite(ledPin, HIGH);
      adc_start_flag = 1;
      timerStart(timer);

      // time1=micros();
      while (!adc_complete_flag)  //等待采集完成
      {
        ets_delay_us(10);
      }
      // time2=micros()-time1;

      timerStop(timer);
      adc_complete_flag = 0;  //清標(biāo)志
      digitalWrite(ledPin, LOW);
      memset(data_json, '\0', strlen(data_json));  //將數(shù)組清空
      strcat(data_json, "{");
      strcat(data_json, "\"format\":\"pcm\",");
      strcat(data_json, "\"rate\":16000,");                                                                        //采樣率    如果采樣率改變了,記得修改該值,只有16000、8000兩個固定采樣率
      strcat(data_json, "\"dev_pid\":1537,");                                                                      //中文普通話
      strcat(data_json, "\"channel\":1,");                                                                         //單聲道
      strcat(data_json, "\"cuid\":\"666666\",");                                                                   //識別碼    隨便打幾個字符,但最好唯一
      strcat(data_json, "\"token\":\"24.8f6143793af76e02f5e191.2592000.1713789066.282335-57722200\",");  //token	這里需要修改成自己申請到的token
      strcat(data_json, "\"len\":32000,");                                                                         //數(shù)據(jù)長度  如果傳輸?shù)臄?shù)據(jù)長度改變了,記得修改該值,該值是ADC采集的數(shù)據(jù)字節(jié)數(shù),不是base64編碼后的長度
      strcat(data_json, "\"speech\":\"");
      strcat(data_json, base64::encode((uint8_t*)adc_data, sizeof(adc_data)).c_str());  //base64編碼數(shù)據(jù)
      strcat(data_json, "\"");
      strcat(data_json, "}");
      // Serial.println(data_json);
      int httpCode;
      http_client.setTimeout(5000);
      http_client.begin("http://vop.baidu.com/server_api");  //https://vop.baidu.com/pro_api
      http_client.addHeader("Content-Type", "application/json");
      httpCode = http_client.POST(data_json);

      if (httpCode == 200) {
        if (httpCode == HTTP_CODE_OK) {
          response = http_client.getString();
          http_client.end();
          Serial.println(response);
          // Parse JSON response
          // DynamicJsonDocument jsonDoc(512);
          deserializeJson(jsonDoc, response);
          String question = jsonDoc["result"][0];
          // 訪問"result"數(shù)組,并獲取其第一個元
          // 輸出結(jié)果
          Serial.println("\n Input:"+question);
          answer = getGPTAnswer(question);
          Serial.println("Answer: " + answer);
          Serial.println("Enter a prompt:");

        } else {
          Serial.printf("[HTTP] GET... failed, error: %s\n", http_client.errorToString(httpCode).c_str());
        }
      }
      // while (!digitalRead(buttonPin))
      //   ;
      Serial.printf("Recognition complete\r\n");
    }
  }
  vTaskDelay(1);
}

用于實(shí)現(xiàn)一個通過 I2S 接口采集音頻信號并將其發(fā)送到百度語音識別 API 進(jìn)行語音識別,然后將識別出的文本通過 MiniMax API 獲取 AI 回答的功能。以下是代碼的主要結(jié)構(gòu)和功能說明:

  1. 引入必要的庫文件,包括 Arduino.h、base64.h、WiFi.h、HTTPClient.h、cJSON.h、I2S.h 和 ArduinoJson.h,這些庫分別提供了基本的 Arduino 功能、Base64 編解碼、Wi-Fi 連接、HTTP 客戶端操作、JSON 數(shù)據(jù)處理和 I2S 音頻接口驅(qū)動。

  2. 定義了一些全局變量,如 Wi-Fi 的 SSID 和密碼,以及與音頻采集和處理相關(guān)的變量,如 ADC 數(shù)據(jù)緩沖區(qū)、錄音標(biāo)志位、完成標(biāo)志位、JSON 格式數(shù)據(jù)緩沖區(qū),還有 MiniMax API 的密鑰(apiKey)。

修改Wi-Fi 的 SSID 和密碼

// 1. Replace with your network credentials
const char* ssid = "J09 502";
const char* password = "qwertyuiop111";

修改MiniMax API 的密鑰(apiKey)

// 3. Replace with your MiniMax API key
const char* apiKey = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJHcm91cE5hbWUiOiIyMzQ1dm9yIiwiVXNlck5hbWUiOiIyMzQ1dm9yIiwiQWNjb3VudCI6IiIsIlN1YmjE3NTk0ODIxODAxMDAxNzAyMDgiLCJQI6IjE3NTk0ODIxODAwOTU5NzU5MDQiLCJQYWdlTmFtZSI6IiIsIk1haWwiOiIiLCJDcmVhdGVUaW1lIjoiMjAyNC0wMy0xNiAxMzoyNDoxOCIsImlzcyI6Im1pbmltYXgifQ.WlEj8Nk0j_WOMXZE9SbIC8sHpwJ6R6Pi8Spl5mahJsW3-Jsz7Ev53sGGz3v__Bd5dDkt7o9-Y8BOW0WZq2ImaN7Rof7YNtYnYnvPNDyGx23_xRqq5co9P5UkC3ciYEcIch2SUZ5QPkXR-sMUPzhdowSYvfdu1N25kdKJ8GE_63NfCnsdDVt8mv0wQSSweJK0yf_C8a8ADdB1uF4vg_WKMDjHlvzERsoNZgX6FYtr-bee85rIyu4U-OrbUvEpR1FLPXa7lTlx65QvhVIYGbIKde7ERIT_7QLOQoVFvPz0gX-H6V7UlmSRgRy4LK_R9mvV5TqCy3v90WK_AFuwEhPXcg";

修改百度api

strcat(data_json, "\"token\":\"24.8f6143793af76e02f5e191.2592000.1713789066.282335-57722200\",");  //token	這里需要修改成自己申請到的token
  1. 定義了一個 HTTPClient 實(shí)例 http_client,用于向 API 發(fā)送請求。

  2. 函數(shù) getGPTAnswer() 負(fù)責(zé)調(diào)用 MiniMax API,并傳入用戶輸入文本以獲取 AI 的回答。

  3. onTimer() 函數(shù)是一個中斷服務(wù)程序,每當(dāng)定時(shí)器觸發(fā)時(shí)會讀取 I2S 接口上的音頻數(shù)據(jù)并存入緩沖區(qū) adc_data 中。當(dāng)緩沖區(qū)滿或者錄音結(jié)束時(shí),會設(shè)置完成標(biāo)志。

  4. setup() 函數(shù)負(fù)責(zé)初始化串口通信、配置 I2S 接口、連接 Wi-Fi,并設(shè)置定時(shí)器和中斷。

  5. loop() 函數(shù)是 Arduino 主循環(huán)函數(shù),在循環(huán)中檢查是否有按鍵輸入(這里未實(shí)際使用)。如果有特定輸入,開始音頻采集過程,并在采集完成后將音頻數(shù)據(jù)轉(zhuǎn)換為 Base64 編碼,構(gòu)建一個 JSON 請求體,然后通過 HTTP POST 方式發(fā)送到百度語音識別 API。收到識別結(jié)果后,調(diào)用 getGPTAnswer() 函數(shù)獲取 AI 回答,并打印在控制臺上。

3.2 ESP32 + max9814

ESP32 + max9814麥克風(fēng)模塊用做語音輸入,一個按鍵來控制數(shù)據(jù)的采集和上傳
注意端口:

#define key 0   //按鍵端口0
#define ADC 32  //max9814麥克風(fēng)模塊端口39
#define led 2   //LED端口2

stt_chat_max.ino

#include <Arduino.h>
#include "base64.h"
#include <WiFi.h>  //#include "WiFi.h"
#include "HTTPClient.h"
#include "cJSON.h"
// #include <I2S.h>
#include <ArduinoJson.h>
#define data_len 16000

#define key 0   //端口0
#define ADC 32  //端口39
#define led 2   //端口2
HTTPClient http_client;
// 1. Replace with your network credentials
const char* ssid = "J09 502";
const char* password = "qwertyuiop111";
// 2. Check your Aduio port
// const int buttonPin = 1;  // the number of the pushbutton pin
// const int ledPin = 21;    // the number of the LED pin
hw_timer_t* timer = NULL;
uint16_t adc_data[data_len];    //16000個數(shù)據(jù),8K采樣率,即2秒,錄音時(shí)間為2秒,想要實(shí)現(xiàn)更長時(shí)間的語音識別,就要改這個數(shù)組大小
                                //和下面data_json數(shù)組的大小,改大一些。
uint8_t adc_start_flag = 0;     //開始標(biāo)志
uint8_t adc_complete_flag = 0;  //完成標(biāo)志
char data_json[45000];          //用于儲存json格式的數(shù)據(jù),大一點(diǎn),JSON編碼后數(shù)據(jù)字節(jié)數(shù)變成原來的4/3,所以得計(jì)算好,避免出現(xiàn)越界

// 3. Replace with your MiniMax API key
const char* apiKey = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJHcm91iOiIyMzQ1dm9yIiwiQWNjb3VudCI6IiIsIlN1YmplY3RJRCI6IjE3NTk0ODIxODAxMDAxNzAyMDgiLCJQaG9uZSI6IjE1MDcyNjQxNTYxIiwiR3JvdXBJRCI6IjE3NTk0ODIxODAwOTU5NzU5MDQiLCJQYWdlTmFtZSI6IiIsIk1haWwiOiIiLCJDcmVhdGVUaW1lIjoiMjAyNC0wMy0xNiAxMzoyNDoxOCIsImlzcyI6Im1pbmltYXgifQ.WlEj8Nk0j_WOMXZE9SbIC8sHpwJ6R6Pi8Spl5mahJsW3-Jsz7Ev53sGGz3v__Bd5dDkt7o9-Y8BOW0WZq2ImaN7Rof7YNtYnYnvPNDyGx23_xRqq5co9P5UkC3ciYEcIch2SUZ5QPkXR-sMUPzhdowSYvfdu1N25kdKJ8GE_63NfCnsdDVt8mv0wQSSweJK0yf_C8a8ADdB1uF4vg_WKMDjHlvzERsoNZgX6FYtr-bee85rIyu4U-OrbUvEpR1FLPXa7lTlx65QvhVIYGbIKde7ERIT_7QLOQoVFvPz0gX-H6V7UlmSRgRy4LK_R9mvV5TqCy3v90WK_AFuwEhPXcg";
HTTPClient http;
String token_key = String("Bearer ") + apiKey;
// Send request to MiniMax API
String inputText = "你好,minimax!";
String apiUrl = "https://api.minimax.chat/v1/text/chatcompletion_v2";
int httpResponseCode;
String response, question, answer;
DynamicJsonDocument jsonDoc(1024);

uint32_t num = 0;
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
void IRAM_ATTR onTimer() {
  // Increment the counter and set the time of ISR
  portENTER_CRITICAL_ISR(&timerMux);
  if (adc_start_flag == 1) {
    //Serial.println("");
    adc_data[num] = analogRead(ADC);
    // adc_data[num] = I2S.read();
    num++;
    if (num >= data_len) {
      adc_complete_flag = 1;
      adc_start_flag = 0;
      num = 0;
      //Serial.println(Complete_flag);
    }
  }
  portEXIT_CRITICAL_ISR(&timerMux);
}

String getGPTAnswer(String inputText) {
  http.begin(apiUrl);
  http.addHeader("Content-Type", "application/json");
  http.addHeader("Authorization", token_key);
  String payload = "{\"model\":\"abab5.5s-chat\",\"messages\":[{\"role\": \"system\",\"content\": \"你是鵬鵬的生活助手機(jī)器人,要求下面的回答嚴(yán)格控制在256字符以內(nèi)。\"},{\"role\": \"user\",\"content\": \"" + inputText + "\"}]}";
  httpResponseCode = http.POST(payload);
  if (httpResponseCode == 200) {
    response = http.getString();
    http.end();
    Serial.println(response);
    // Parse JSON response
    deserializeJson(jsonDoc, response);
    String outputText = jsonDoc["choices"][0]["message"]["content"];
    return outputText;
    // Serial.println(outputText);
  } else {
    http.end();
    Serial.printf("Error %i \n", httpResponseCode);
    return "<error>";
  }
}

void setup() {

  //Serial.begin(921600);
  Serial.begin(115200);
  pinMode(ADC, ANALOG);
  pinMode(key, INPUT_PULLUP);
  pinMode(led, OUTPUT);
  // pinMode(ADC, ANALOG);
  // pinMode(buttonPin, INPUT_PULLUP);
  // pinMode(ledPin, OUTPUT);
  // start I2S at 16 kHz with 16-bits per sample
  // I2S.setAllPins(-1, 42, 41, -1, -1);
  // if (!I2S.begin(PDM_MONO_MODE, 16000, 16)) {
  //   Serial.println("Failed to initialize I2S!");
  //   while (1)
  //     ;  // do nothing
  // }
  uint8_t count = 0;
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    count++;
    if (count >= 75) {
      Serial.printf("\r\n-- wifi connect fail! --");
      break;
    }
    vTaskDelay(200);
  }
  Serial.printf("\r\n-- wifi connect success! --\r\n");
  Serial.println(WiFi.localIP());
  http.setTimeout(10000);
  // gain_token();

  timer = timerBegin(0, 80, true);    //  80M的時(shí)鐘 80分頻 1M
  timerAlarmWrite(timer, 125, true);  //  1M  計(jì)125個數(shù)進(jìn)中斷  8K
  timerAttachInterrupt(timer, &onTimer, true);
  timerAlarmEnable(timer);
  timerStop(timer);  //先暫停
}


uint32_t time1, time2;
void loop() {

    if (digitalRead(key)==0) {
      Serial.printf("Start recognition\r\n\r\n");
      digitalWrite(led,HIGH);
      adc_start_flag = 1;
      timerStart(timer);

      // time1=micros();
      while (!adc_complete_flag)  //等待采集完成
      {
        ets_delay_us(10);
      }
      // time2=micros()-time1;

      timerStop(timer);
      adc_complete_flag = 0;  //清標(biāo)志
      digitalWrite(led, LOW);
      memset(data_json, '\0', strlen(data_json));  //將數(shù)組清空
      strcat(data_json, "{");
      strcat(data_json, "\"format\":\"pcm\",");
      strcat(data_json, "\"rate\":8000,");                                                                        //采樣率    如果采樣率改變了,記得修改該值,只有16000、8000兩個固定采樣率
      strcat(data_json, "\"dev_pid\":1537,");                                                                      //中文普通話
      strcat(data_json, "\"channel\":1,");                                                                         //單聲道
      strcat(data_json, "\"cuid\":\"666666\",");                                                                   //識別碼    隨便打幾個字符,但最好唯一
      strcat(data_json, "\"token\":\"24.8f6143793af76191.2592000.1713789066.282335-57722200\",");  //token	這里需要修改成自己申請到的token
      strcat(data_json, "\"len\":32000,");                                                                         //數(shù)據(jù)長度  如果傳輸?shù)臄?shù)據(jù)長度改變了,記得修改該值,該值是ADC采集的數(shù)據(jù)字節(jié)數(shù),不是base64編碼后的長度
      strcat(data_json, "\"speech\":\"");
      strcat(data_json, base64::encode((uint8_t*)adc_data, sizeof(adc_data)).c_str());  //base64編碼數(shù)據(jù)
      strcat(data_json, "\"");
      strcat(data_json, "}");
      // Serial.println(data_json);
      int httpCode;
      http_client.setTimeout(5000);
      http_client.begin("http://vop.baidu.com/server_api");  //https://vop.baidu.com/pro_api
      http_client.addHeader("Content-Type", "application/json");
      httpCode = http_client.POST(data_json);

      if (httpCode == 200) {
        if (httpCode == HTTP_CODE_OK) {
          response = http_client.getString();
          http_client.end();
          Serial.println(response);
          // Parse JSON response
          // DynamicJsonDocument jsonDoc(512);
          deserializeJson(jsonDoc, response);
          String question = jsonDoc["result"][0];
          // 訪問"result"數(shù)組,并獲取其第一個元
          // 輸出結(jié)果
          Serial.println("\n Input:" + question);
          answer = getGPTAnswer(question);
          Serial.println("Answer: " + answer);
          Serial.println("Enter a prompt:");

        } else {
          Serial.printf("[HTTP] GET... failed, error: %s\n", http_client.errorToString(httpCode).c_str());
        }
      }
      // while (!digitalRead(buttonPin))
      //   ;
      Serial.printf("Recognition complete\r\n");
    }
  // }
  vTaskDelay(1);
}

4. 上傳驗(yàn)證

如果提示Compilation error: ArduinoJson.h: No such file or directory
esp32接入語音平臺,arduino學(xué)習(xí),語音識別,人工智能,Arduino,esp32
直接在庫管理安裝Arduinojson
esp32接入語音平臺,arduino學(xué)習(xí),語音識別,人工智能,Arduino,esp32

打開串口監(jiān)視器,注意右下角選擇換行符,選擇115200波特率,輸入你想問的問題,他就可以回答你

4.1 對話測試

esp32接入語音平臺,arduino學(xué)習(xí),語音識別,人工智能,Arduino,esp32

串口發(fā)送“1”,開始錄音,然后返回對話結(jié)果,以上是兩次連續(xù)對話效果??????

4.2 報(bào)錯

  1. 如果返回error ,大家對照列表查詢錯誤代碼,結(jié)合提示排查解決
    esp32接入語音平臺,arduino學(xué)習(xí),語音識別,人工智能,Arduino,esp32
  2. 如果第一次可以二次自動重啟
  3. esp32接入語音平臺,arduino學(xué)習(xí),語音識別,人工智能,Arduino,esp32
    可以配置下載程序運(yùn)行在core0
    esp32接入語音平臺,arduino學(xué)習(xí),語音識別,人工智能,Arduino,esp32

esp32接入語音平臺,arduino學(xué)習(xí),語音識別,人工智能,Arduino,esp32

5. 總結(jié)

??????現(xiàn)在,我們在本教程中,您學(xué)習(xí)了如何使用ESP32S3 Sense接入語音識別+MiniMax模型對話。??????從而實(shí)現(xiàn)對外部世界進(jìn)行感知,充分認(rèn)識這個有機(jī)與無機(jī)的環(huán)境,后期會持續(xù)分享esp32跑freertos實(shí)用案列??????科學(xué)地合理地進(jìn)行創(chuàng)作和發(fā)揮效益,然后為人類社會發(fā)展貢獻(xiàn)一點(diǎn)微薄之力。??????

如果你有任何問題,可以通過下面的二維碼加入鵬鵬小分隊(duì),期待與你思維的碰撞??????文章來源地址http://www.zghlxwxcb.cn/news/detail-853422.html

到了這里,關(guān)于【ESP32S3 Sense接入語音識別+MiniMax模型對話】的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • esp32s3使用多串口

    esp32s3使用多串口

    我按照別人博客中設(shè)置串口2,串口打印有問題,因?yàn)闆]有看到esp32s3 多串口,就總結(jié)了一下自己的經(jīng)驗(yàn) 下圖為esp32的引腳圖 下圖為esp32s3的引腳圖 ESP32-S3 有三個 UART(通用異步收發(fā)器)控制器,即 UART0、UART1、UART2,支持異步通信(RS232 和 RS485)和 IrDA,通信速率可達(dá)到 5 Mbps。

    2024年02月04日
    瀏覽(27)
  • ESP32S3入手體驗(yàn)測試

    ESP32S3入手體驗(yàn)測試

    ??所入手的型號是 YD-ESP32-S3 N16R8 ,該款和樂鑫官方推出的 ESP32-S3-DevKitC-1 配置差不多。 ??樂鑫官方介紹:ESP32-S3-DevKitC-1 v1.1 ??兩者采用的模組:ESP32-S3-WROOM-1 和ESP32-S3-WROOM-1U模組對比: ?? YD-ESP32-S3 和 ESP32-S3-DevKitC-1 硬件基本信息: ??核心模組配置都是可選。兩款開發(fā)板從原

    2024年02月05日
    瀏覽(50)
  • ESP32S3系列--SPI主機(jī)驅(qū)動詳解(一)

    ESP32S3系列--SPI主機(jī)驅(qū)動詳解(一)

    SPI是一種串行同步接口,可用于與外圍設(shè)備進(jìn)行通信。 ESP32S3自帶4個SPI外設(shè),其中SPI0/SPI1內(nèi)部專用,共用一組信號線,通過一個仲裁器訪問外部Flash和PSRAM;SPI2/3各自使用一組獨(dú)立的信號線;開發(fā)者可以使用SPI2/3控制外部SPI從設(shè)備(Slave device);其中SPI2作為主設(shè)備有6個片選,數(shù)據(jù)

    2023年04月09日
    瀏覽(22)
  • 【EPS32S3學(xué)習(xí)筆記】ESP32+OPENCV+OV2640+LVGL

    【EPS32S3學(xué)習(xí)筆記】ESP32+OPENCV+OV2640+LVGL

    提示:這里可以添加系列文章的所有文章的目錄,目錄需要自己手動添加 例如:第一章 Python 機(jī)器學(xué)習(xí)入門之pandas的使用 提示:寫完文章后,目錄可以自動生成,如何生成可參考右邊的幫助文檔 提示:這里可以添加本文要記錄的大概內(nèi)容: 前面已經(jīng)完成了ESP32S3+LVGL+OV2640的工

    2024年02月06日
    瀏覽(27)
  • ESP32S3學(xué)習(xí)——LEDC LED PWM 控制器

    ESP32S3學(xué)習(xí)——LEDC LED PWM 控制器

    芯片:esp32s3 開發(fā)環(huán)境:espidfv4.4 1)LED 控制器 (LEDC) 主要用于控制 LED,也可產(chǎn)生 PWM 信號用于 其他設(shè)備 的控制。 該控制器有 8 路通道 ,可以產(chǎn)生獨(dú)立的波形來驅(qū)動 RGB LED 等設(shè)備。 LED PWM 控制器可在 無需 CPU 干預(yù) 的情況下 自動改變占 空比,實(shí)現(xiàn)亮度和顏色漸變(因?yàn)檫@個功能

    2024年02月06日
    瀏覽(23)
  • ESP32S3 ADC DMA使用記錄(坑記錄)(大牛歡迎給出建議)

    目前測到三個問題: 一、ADC DMA采樣頻率sample_freq_hz取值范圍611-83333,雖然可以達(dá)到83333,但是只能是在while循環(huán)里面不停采樣才可以,如果想要隔一段時(shí)間采樣一次則不行,假如隔一段時(shí)間使用adc_digi_read_bytes讀取40byte數(shù)據(jù),結(jié)果經(jīng)常會返回ESP_ERR_INVALID_STATE,且經(jīng)常讀取的數(shù)據(jù)

    2024年02月11日
    瀏覽(40)
  • 視頻圖像處理算法opencv在esp32及esp32s3上面的移植,也可以移植openmv

    視頻圖像處理算法opencv在esp32及esp32s3上面的移植,也可以移植openmv

    opencv 在 esp32 及 esp32s3 上面的移植 Opencv 簡介 ? ? ? OpenCV 是一個基于 Apache2.0 許可(開源)發(fā)行的跨平臺計(jì)算機(jī)視覺和機(jī)器學(xué)習(xí)軟件庫,可以運(yùn)行在 Linux 、 Windows 、 Android 和 Mac OS 操作系統(tǒng)上,它輕量級而且高效—— 由一系列 C 函數(shù)和少量 C++ 類構(gòu)成,同時(shí)提供了 Python 、 R

    2024年02月09日
    瀏覽(18)
  • ESP32S3使用esp-iot-solution SDK開發(fā)USBHID鼠標(biāo)鍵盤教程

    ESP32S3使用esp-iot-solution SDK開發(fā)USBHID鼠標(biāo)鍵盤教程

    ? 手里最近翻到了一個ESP32S3開發(fā)板,于是想做個鼠標(biāo)鍵盤玩玩,這是我第二次接觸ESP32,上一次18年買的吃灰板子至今沒上過電。新找到的S3看手冊是支持OTG的,按照官方的教程搭建的WSL+VSCODE環(huán)境。然而一切準(zhǔn)備就緒發(fā)現(xiàn)ESP-IDF里面沒有USB-HIDdemo。沒有demo怎么玩。于是乎查找資

    2024年02月09日
    瀏覽(26)
  • ESP32-S3語音喚醒技術(shù),智能機(jī)器人應(yīng)用,物聯(lián)網(wǎng)技術(shù)發(fā)展

    ESP32-S3語音喚醒技術(shù),智能機(jī)器人應(yīng)用,物聯(lián)網(wǎng)技術(shù)發(fā)展

    隨著技術(shù)的發(fā)展,智能服務(wù)正在融入群眾的生活。智能機(jī)器人的應(yīng)用,大大提高人們的工作效率,并減少投入的成本。 傳感器檢測是否有來賓,指紋識別模塊可以用來簽到,語音識別處理模塊可以進(jìn)行簡單的日常提問進(jìn)行識別并用相應(yīng)的回答,觸摸屏界面實(shí)現(xiàn)人機(jī)互動,可以

    2024年02月13日
    瀏覽(43)
  • ESP32 Tensorflow 實(shí)現(xiàn)語音識別

    教程介紹 如何 通過外部麥克風(fēng) I2S 將 Tensorflow 微語音與 ESP32 結(jié)合使用。換句話說,我們想要定制 Tensorflow 微語音示例,以便它在使用 I2S 協(xié)議連接到外部麥克風(fēng)的 ESP32 上運(yùn)行。在本例中,我們將使用連接到 ESP32 的 INMP441 來捕獲音頻。雖然 ESP32-EYE 具有內(nèi)置麥克風(fēng),但如果我

    2024年02月04日
    瀏覽(19)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包