M5StackからLinuxが動く液晶画面付きユニットである CoreMP135が発売されました。
スタックチャンは同社のM5Stack BASIC, Fire, Core2, CoreS3m ATOMといったESP32を用いたユニットを用いてつくられることが多いですが、これらのユニットを使って複雑な通信処理や音声信号処理を行うには、リアルタイムOS上で省メモリでの処理の実装が必要です。このため、特にAIスタックチャンのように複雑な機能を持つソフトウェアの開発にはそれなりのリソースが必要となります。
一方、CoreMP135はLinuxが動くため、Linux上で動く既存のソフトウェア資産を組み合わせて、複雑な機能をもつソフトウェアを少ないリソースで開発することが可能です。
CoreMP135で用いられているSoC STM32MP135D (STMicroelectronics) は、Cortex-A7 1GHz 1コアを内蔵しており、またCoreMP135には512MBのDDR3L SDRAMが実装されています。 これらのスペックは、現在よく用いられているRaspberry Pi 4などと比較するとかなり劣るものですが、ESP32シリーズから比較すると数倍の性能があります。また特にRAMの容量と帯域はかなり有利です。
というわけで、CoreMP135でサクッとAIスタックチャンを実装してみました。
The M5Stack has released the CoreMP135, a new unit featuring an LCD screen that runs Linux.
While Stackchan is often implemented with units like the M5Stack BASIC, Fire, Core2, CoreS3, and ATOM, which utilize the ESP32. But implementing complex communication and audio signal processing on these units requires implementing softwares on real-time OS with low memory usage. Therefore, developing software with complex functionalities like the AI stack often needs considerable resources.
However, the CoreMP135, which runs Linux, allows for the development of complex software with fewer resources by leveraging existing software assets that operate on Linux.
The CoreMP135 is equipped with the SoC STM32MP135D (STMicroelectronics), which includes a Cortex-A7 1GHz single-core processor, and has 512MB of DDR3L SDRAM installed. While these specs are significantly inferior compared to commonly used devices like the Raspberry Pi 4, they represent a substantial improvement over the ESP32 series, especially in terms of RAM capacity and bandwidth.
With these capabilities, I quickly implemented an AI stack on the CoreMP135.
もともとM5Stack Core2向けにRustで記述した Rusty Stackchan を作っていたので、それをベースにLinuxに移植しました。
Rusty Stackchanの時点で、スタックチャンの重要機能の一つである、カワイイ顔を表示する機能は実装してあったので、残りはサーボモーターの制御と、音声認識・対話生成・音声合成機能の実装が必要でした。
Originally, I had developed the Rusty Stackchan for the M5Stack Core2 using Rust, so I used this as a base to port it to Linux.
At the time of Rusty Stackchan, one of its key features, displaying a kawaii face, had already been implemented. The remaining tasks were to implement control for servo motors and functionalities for speech recognition, dialogue generation, and speech synthesis.
CoreMP135スタックチャンには、Feetechのサーボモーター SCS0009 を用いています。SCS0009は所謂シリアルサーボと呼ばれるタイプのサーボモーターで、その名の通り双方向のUARTによるシリアル通信経由でコマンド・レスポンスをやりとりして制御します。
SCS0009のコマンドの詳細の解説は省きますが、FeetechのSCSシリーズ向けの通信処理とそれを用いたSCS0009の制御を行うソフトウェアを新たに実装しました。
For the CoreMP135 Stackchan, I'm using the Feetech servo motor SCS0009. The SCS0009 is a type of servo motor known as a serial servo, which is controlled through bidirectional UART serial communication for command-response exchanges.
While I will omit the detailed explanation of the SCS0009 commands, I have implemented new software for handling communication with Feetech's SCS series and for controlling the SCS0009.
音声認識、対話生成、音声合成には、AIスタックチャンと同じく、OpenAIのSTT (Whisper), Chat Completion, TTS APIを用いています。
このうち、STTに音声データを投げる前に、音声の有効区間の検出 (VAD)やノイズ除去の処理が必要だったため、webrtc-vad
や nnnoiseless
クレートを用いています。これらの処理を一から実装すると時間がかかりますが、Linux向けのオープンソース実装が利用可能なため助かりました。
For speech recognition, dialogue generation, and speech synthesis, just like in the AI Stackchan, we are using OpenAI's STT (Whisper), Chat Completion, and TTS APIs.
Before sending audio data to STT, it is necessary to perform voice activity detection (VAD) and noise reduction. For these processes, I utilized the webrtc-vad and nnnoiseless crates. Implementing these from scratch would be time-consuming, but fortunately, open-source implementations for Linux are available, which was a great help.
現時点ではユーザーが画面を触ったことを起点として音声認識を開始していますが、ウェイクワード検出処理を追加して、AIスピーカーとして機能できるようにする予定です。
Currently, speech recognition starts when a user touches the screen. However, I plan to add wake word detection to enable the device to function as an AI speaker.
サーボの制御はLinux上でSCS0009の通信処理をUART経由で行っています。
上面にEthernetポートとUSB Type-Cコネクタを向けるために、CoreMP135は上下逆に配置しています。
本体上部にはStackchan Takao Base SCS0009が収まっており、CoreMP135とサーボへの+5Vの電源供給、およびCoreMP135のUARTとサーボモーター SCS0009の通信線との変換をしています。