Everything is AI: A solution based on MTK Genio 130 combined with ChatGPT function

Hedy · Dasenic Dec 02,2024 219

With the explosive growth of artificial intelligence (AI) in 2022-2023, we have ushered in the AI era. Whether it is transportation, industry, finance, manufacturing, medical and other fields, AI has been widely used to solve various problems and accelerate develop. As AI enters our lives, we are also seeing a variety of AI tools and products on various smart devices we own.



Figure 1: MediaTek Genio 130 chip (data from MediaTek)

ChatGPT is a natural language generation model that we are familiar with and widely used; ChatGPT was developed by OpenAI and launched in 2022. Through ChatGPT, we can not only interact with it in human natural language. It can also transmit text, audio, images, multimedia and other information, and give nearly real-life and corresponding responses based on deep learning to the user's inquiries.Such advanced AI technology is widely used in various fields and scenarios. In the field of IoT, MediaTek uses its own solution: Genio 130, which is a single-chip integrated with Arm Cortex-M33 MCU, Wi-Fi 6 and Bluetooth 5.2 connection subsystems, power management unit (PMU) and optional audio DSP as the basis, combined with OpenAI API, to create a new generation of smart connected AI devices that can be used in various IoT scenarios and situations.

Figure 2: MediaTek Genio 130 block diagram

This article will further introduce the solution of Genio 130 combined with ChatGPT function:

·Genio 130 environment & SDK setup

·OpenAI API import & behavior design

·Actual operation demonstration

Genio 130 environment & SDK setup

Figure 3: MediaTek Genio 130 EVK (data from AcSip)

After setting up a Linux development environment (ex. VM + Ubuntu 20.04 LTS), import the Genio 130 SDK and start implementing OpenAI functions.

Regarding how to set up the Genio 130 development environment, further build a project, and burn the project binary file to the Genio 130 EVK, before importing the OpenAI API, we need to implement the following functions to meet the requirements of the OpenAI API. The Genio 130 SDK already has some functions.

·Audio data capture from microphone: capture microphone audio.

·Audio playback: used to play OpenAI response content.

·HTTP Client: send and receive network packets between Genio 130 and OpenAI Server.

OpenAI API Import & Behavior Design

By referring to the OpenAI development documents, we can find various OpenAI APIs and integrate them on Genio 130, using HTTP Request to complete. The following is an HTTP Request example using Chat Completions API:

 curl https://api.openai.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "model": "gpt-4o-mini",
    "messages": [
      {
        "role": "system",
        "content": "You are a helpful assistant."                                                                             
      },
      {
        "role": "user",
        "content": "What is a LLM?"
      }
    ]
  }'

It is worth mentioning that developing the OpenAI API requires registering an account at OpenAI and obtaining an OpenAI API Key (which requires payment).

For details, please refer to: OpenAI Platform

On the Genio 130, we designed to use the button (SW2) on the EVK to trigger the microphone to pick up sound, which is then sent to the OpenAI Server via the HTTP Requet packet. Then, the audio response returned after processing by the OpenAI Server is obtained, and finally the audio playback function is used to play the result on the Speaker.

Figure 4: MediaTek Genio 130 EVK

Actual Operation Demonstration

Next is the actual operation of Genio 130 ChatGPT function demonstration. We can simply connect the speaker to the Genio 130 EVK. After completion, connect the Gneio 130 EVK to the power supply. The Gneio 130 EVK will quickly complete the initialization and wait for the user to perform the next step.

Figure 5: MediaTek Genio 130 EVK

Next, we need to connect the Gneio 130 EVK to a known WIFI AP; use a series of WIFI CLI commands to establish the Gneio 130 EVK's network connection. This WIFI AP profile can also be stored in the Gneio 130 EVK's NVDM. The subsequent boot will automatically apply the profile for WIFI connection.

$ wifi init
$ wifi config set ssid 0 SSID
$ wifi config set sec 0 7 6
$ wifi config set psk 0 PASSWORD
$ wifi config set reload

Next, we start the ChatGPT service through the implemented ChatGPT CLI command

$ chatgpt_start


After completion, we can press the SW2 button and use natural language to ask questions:
Hello, please introduce yourself.

Through the OpenAI API, a series of processing: audio/transcriptions --> chat/completions --> audio/speech. A "conversation" is completed, and the following is displayed in the form of a package:

[249093]<633>[common][I][openAI_chatGPT_task][1289]send audio data complete!
recv data_size:38,
{
  "text": "Hello, please introduce yourself"
}
[249637]<634>[common][I][openAI_chatGPT_task][1294]httpclient_post https://api.openai.com/v1/audio/transcriptions success !
req: Hello, please introduce yourself
[249639]<635>[common][I][openAI_chatGPT_task][1335]send chat request !
[249645]<636>[common][I][openAI_chatGPT_task][1351]send chat request complete!
recv data_size:757,
{
  "id": "chatcmpl-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "object": "chat.completion",
  "created": 1724683334,
  "model": "gpt-4o-mini-2024-07-18",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello! I am a chatbot assistant, designed to answer questions, provide information and help solve various needs. 
        Whether it is learning I can help you with new knowledge, finding advice, writing texts, or any other topic.
         If you have any questions or needs, please let me know!",
        "refusal": null
      },
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 13,
    "completion_tokens": 74,
    "total_tokens": 87
  },
  "system_fingerprint": "fp_507c9469a1"
}
[251591]<637>[common][I][openAI_chatGPT_task][1355]httpclient_post https://api.openai.com/v1/chat/completions success !
req txt: Hello! I am a chatbot assistant, designed to answer questions, provide information and help solve various needs. Whether 
it is learning I can help you with new knowledge, finding advice, writing texts, or any other topic.
 If you have any questions or needs, please let me know!
[251594]<638>[common][I][openAI_chatGPT_task][1397]send text!
[251601]<639>[common][I][openAI_chatGPT_task][1413]send text complete!
mp3_codec_start_play,829
[MP3 Codec]Open codec
[MP3 Codec]: mp3_decode_buffer 0x1067c0c8 (len 41000), mp3_codec_internal_handle 0x1057a1f0 (size 220), handle 0x1057a1f0
[MP3 Codec]mp3_codec_task_main create
[MP3 Codec Demo] first write data 4095.mp3_codec_start_play,848
[MP3 Codec Demo] play +
[MP3 Codec] mp3_codec_play_internal ++
[MP3 Codec] mp3_codec_play_internal --
[MP3 Codec Demo] play -
recv data done:total size:340800, this block:14400
· [260847]<649>[common][I][openAI_chatGPT_task][1434]httpclient_post https://api.openai.com/v1/audio/speech success !

►Scenario application diagram

► Display board photos

►Solution Block Diagram

►Core technology advantages

MediaTek Genio 130 (MT7931/MT7933) microprocessor products represented by Pinjia Group are based on the Arm Cortex-M33 architecture processor, with a clock speed of up to 300MHz and built-in up to 8MB UHS PSRAM, providing efficient computing power. It also provides wireless connection technologies such as WiFi 6 and BT 5.2, and has dual-band (2.4GHz and 5GHz) connections; in addition, Genio 130 (MT7933 version) has built-in HiFi4 DSP, 3 ADCs, and 2 DAC channels, providing voice activity detection and trigger word functions, suitable for the development of IoT devices that support voice assistant cloud services.

►Solution Specifications

MediaTek Genio 130 series (MT7931/MT7933) features: • Arm Cortex-M33 processor, 300MHz clock • Embedded 1MB SRAM and 8MB UHS (Ultra High Speed) PSRAM • WiFi 6 and dual-band IEEE 802.11 a/b/g/n/ac/ax 2.4G/5G connectivity subsystem • Bluetooth 5.2 connectivity subsystem • Audio Cadence® Tensilica® HiFi4 DSP@600MHz (Note 1) • Hardware encryption engine (AES/DES/3DES/SHA/ECC/TRNG) • Power management unit • Supports USB 2.0 OTG (Note 1) • Rich peripheral interfaces such as: USB, SDIO, SPI master/slave, I2C, I2S, UART, AUXADC, PWM and up to 46 GIPO • Provides FreeRTOS and Arduino development SDK and multiple sample projects shorten the development time. Note 1: HiFi4 DSP and USB 2.0 are functions supported by MT7933.


Больше ничего.

Больше ничего.

  • RFQ