Last active
April 2, 2025 16:14
-
-
Save mongonta0716/b5aff6d7a1bfcf8a460d8a8c4bb3c9fb to your computer and use it in GitHub Desktop.
M5Stack ModuleLLMで日本語をPC(シリアル通信)から入力し、回答をAquesTalkESP32で読み上げるサンプル。(main.cppのコメントを参照してください。)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD | |
* SPDX-License-Identifier: MIT | |
* M5Stack LLM Module で日本語対話。Serial MonitorでBoth BL&CRを設定するとよいです。 | |
* ksasaoさんのバージョンをAquesTalkで喋るようにしたバージョンです。(https://gist.github.com/ksasao/37425d3463013221e7fd0f9ae5ab1c62) | |
* | |
* --- セットアップ --- | |
* 1.プロジェクトにlibフォルダを作成して、そこにAquesTalkESP32のライブラリを解凍してください。(https://www.a-quest.com/download.html#a-etc) | |
* 2. VSCode+PlatformIOで、srcフォルダにAquesTalkのExampleにある(AquesTalkTTS_M5.cppとAquesTalkTTS.h)をコピーする必要があります。 | |
* 3.SDカード上に"/aq_dic/aqdic_m.bin"が必要です。 | |
*/ | |
#include <Arduino.h> | |
#include <M5Unified.h> | |
#include <M5ModuleLLM.h> | |
#include "AquesTalkTTS.h" // AquesTalk-ESP32のラッパークラス | |
M5ModuleLLM module_llm; | |
String llm_work_id; | |
String talk_str = ""; // AquesTalkで喋る文字列 | |
void setup() | |
{ | |
M5.begin(); | |
M5.Display.setTextSize(1); | |
M5.Display.setTextScroll(true); | |
M5.Lcd.setTextFont(&fonts::efontJA_16); | |
/* Init module serial port */ | |
Serial.begin(115200); | |
//Serial2.begin(115200, SERIAL_8N1, 16, 17); // Basic | |
//Serial2.begin(115200, SERIAL_8N1, 13, 14); // Core2 | |
//Serial2.begin(115200, SERIAL_8N1, 18, 17); // CoreS3 | |
Serial2.begin(115200, SERIAL_8N1, M5.getPin(m5::pin_name_t::port_c_rxd), M5.getPin(m5::pin_name_t::port_c_txd)); // Port.C | |
/* Init module */ | |
module_llm.begin(&Serial2); | |
/* Make sure module is connected */ | |
M5.Display.printf(">> Check ModuleLLM connection..\n"); | |
while (1) { | |
if (module_llm.checkConnection()) { | |
break; | |
} | |
} | |
/* Reset ModuleLLM */ | |
M5.Display.printf(">> Reset ModuleLLM..\n"); | |
module_llm.sys.reset(); | |
/* Setup LLM module and save returned work id */ | |
M5.Display.printf(">> Setup llm..\n"); | |
llm_work_id = module_llm.llm.setup(); | |
Serial.print("Initialized..."); | |
// AquesTalkの初期化 | |
int err = TTS.createK(); | |
if (err) { | |
M5_LOGI("ERR:TTS.createK(): %d", err); | |
} | |
M5.Speaker.setVolume(128); | |
TTS.playK("こんにちは、漢字を混ぜた文章です。"); | |
TTS.wait(); // 終了まで待つ | |
} | |
void loop() | |
{ | |
if (Serial.available() > 0) { | |
String input = Serial.readString(); | |
std::string question = input.c_str(); | |
M5.Display.setTextColor(TFT_GREEN); | |
M5.Display.printf("<< %s\n", question.c_str()); | |
Serial.printf("<< %s\n", question.c_str()); | |
M5.Display.setTextColor(TFT_YELLOW); | |
M5.Display.printf(">> "); | |
Serial.printf(">> "); | |
/* Push question to LLM module and wait inference result */ | |
module_llm.llm.inferenceAndWaitResult(llm_work_id, question.c_str(), [](String& result) { | |
/* Show result on screen */ | |
talk_str += result.c_str(); | |
M5.Display.printf("%s", result.c_str()); | |
Serial.printf("%s", result.c_str()); | |
}); | |
M5.Display.println(llm_work_id); | |
TTS.playK(talk_str.c_str(), 100); | |
TTS.wait(); | |
talk_str = ""; | |
M5.Display.println(); | |
} | |
delay(500); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; | |
; Build options: build flags, source filter | |
; Upload options: custom upload port, speed and extra flags | |
; Library options: dependencies, extra library storages | |
; Advanced options: extra scripting | |
; | |
; Please visit documentation for the other options and examples | |
; https://docs.platformio.org/page/projectconf.html | |
[platformio] | |
default_envs = m5stack-cores3 | |
[env] | |
platform = espressif32 @ 6.5.0 | |
framework = arduino | |
upload_speed = 1500000 | |
monitor_speed = 115200 | |
board_build.f_flash = 80000000L | |
board_build.filesystem = spiffs | |
board_build.partitions = default_16MB.csv | |
build_flags = | |
-DCORE_DEBUG_LEVEL=4 | |
-Llib/ | |
lib_deps = | |
m5stack/[email protected] | |
m5stack/[email protected] | |
lib_extra_dirs = lib | |
lib_ldf_mode = deep | |
[env:m5stack-core2] | |
board = m5stack-core2 | |
[env:m5stack-grey] | |
; Flash16MBのBasicはこちらを使ってください。 | |
board = m5stack-grey | |
[env:m5stack-fire] | |
; fireはespressif32最新版(5.x)で動かない場合は下記の1行をコメントアウトしてください。 | |
; platform = espressif32 @ 4.4.0 | |
board = m5stack-fire | |
[env:m5stack-core-esp32] | |
; Flash 16MBのBasicはm5stack-greyを使ってください。 | |
board = m5stack-core-esp32 | |
board_build.partitions = huge_app.csv | |
[env:m5stack-cores3] | |
board = m5stack-cores3 | |
build_flags = | |
${env.build_flags} | |
lib_deps = | |
${env.lib_deps} | |
https://github.com/GOB52/gob_unifiedButton | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment