{"id":2039,"date":"2024-03-26T18:40:54","date_gmt":"2024-03-26T09:40:54","guid":{"rendered":"https:\/\/www.rocher.kyoto.jp\/arbr\/?p=2039"},"modified":"2024-04-05T16:30:47","modified_gmt":"2024-04-05T07:30:47","slug":"%e8%87%aa%e5%ae%85%e7%94%a8%e9%80%9a%e7%9f%a5%e3%83%9e%e3%82%b7%e3%83%b3%e4%bd%9c%e6%88%904","status":"publish","type":"post","link":"https:\/\/www.rocher.kyoto.jp\/arbr\/?p=2039","title":{"rendered":"\u81ea\u5b85\u7528\u901a\u77e5\u30de\u30b7\u30f3\u4f5c\u6210(4)"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u97f3\u58f0\u95a2\u9023\u30af\u30e9\u30b9\u5316<\/h2>\n\n\n\n<p>\u898b\u901a\u3057\u304c\u60aa\u304f\u306a\u308a\u305d\u3046\u306a\u306e\u3067\u97f3\u58f0\u5468\u308a\u306f\u5225\u30af\u30e9\u30b9\u306b\u3002\u591a\u5206\u307e\u3060\u4e88\u60f3\u3057\u3066\u306a\u3044\u6539\u9020\u3092\u3057\u305d\u306a\u306e\u3067\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u6e21\u3059\u3068\u304b\u8003\u3048\u305a\u306b\u5358\u7d14\u306a\u5225\u30d5\u30a1\u30a4\u30eb\u5316\u3060\u3051\u3002\uff08StackSpeaker.h\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-dark-gray-background-color has-text-color has-background has-link-color wp-elements-1df601f74118d4bbb07a0170e9f4fc11\"><code>#ifndef STACK_SPEAKER_H\n#define STACK_SPEAKER_H\n\n#include &lt;AudioFileSourceSD.h&gt;\n#include &lt;AudioFileSourceBuffer.h&gt;\n#include &lt;AudioGeneratorMP3.h&gt;\n\n#include \"EpeaAudioOutputM5Speaker.h\"\n\nstatic epea::AudioOutputM5Speaker out(&amp;M5.Speaker);\nstatic AudioGeneratorMP3 mp3;\nstatic AudioFileSourceSD *file = nullptr;\nstatic AudioFileSourceBuffer *buff = nullptr;\nconst int preallocateBufferSize = 50 * 1024;\nuint8_t *preallocateBuffer;\n\nclass StackSpeaker {\npublic:\n  StackSpeaker() {}\n  ~StackSpeaker(void){};\n  boolean init(void) {\n    auto spk_cfg = M5.Speaker.config();\n    spk_cfg.sample_rate = 26000;\n    spk_cfg.task_priority = 23;\n    spk_cfg.dma_buf_count = 20;\n    spk_cfg.dma_buf_len = 128;\n    M5.Speaker.config(spk_cfg);\n    M5.Speaker.begin();\n\n    M5.Speaker.setVolume(255);\n\n    preallocateBuffer = (uint8_t *)malloc(preallocateBufferSize);\n\n    return preallocateBuffer;\n  }\n\n  void stopVoice() {\n    if (file == nullptr) return;\n\n    out.stop();\n    mp3.stop();\n    file-&gt;close();\n    delete file;\n    file = nullptr;\n  }\n\n  void startVoice(const char *filename) {\n    if (file != nullptr) { stopVoice(); }\n\n    file = new AudioFileSourceSD(filename);\n    buff = new AudioFileSourceBuffer(file, preallocateBuffer, preallocateBufferSize);\n    mp3.begin(buff, &amp;out);\n\n    delay(10);\n    while (mp3.isRunning()) {\n      while (mp3.loop()) {}\n      mp3.stop();\n      file-&gt;close();\n      delete file;\n      delete buff;\n      file = nullptr;\n      buff = nullptr;\n    }\n  }\n};\n\n#endif \/* STACK_SPEAKER_H *\/<\/code><\/pre>\n\n\n\n<p>\u547c\u3073\u51fa\u3057\u306f<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-dark-gray-background-color has-text-color has-background has-link-color wp-elements-63783e05ac02297ed834ad6eecf56734\"><code><strong>#include \"StackSpeaker.h\"<\/strong> \/\/\u30a4\u30f3\u30af\u30eb\u30fc\u30c9\n\nstatic StackSpeaker speaker; \/\/ \u5ba3\u8a00\nvoid setup() {\n  M5.begin();\n  <strong>speaker.init();<\/strong>  \/\/\u521d\u671f\u5316<\/code><\/pre>\n\n\n\n<p>\u3057\u3066\u304a\u3044\u3066\u4f7f\u3044\u305f\u3044\u3068\u3053\u308d\u3067<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-dark-gray-background-color has-text-color has-background has-link-color wp-elements-577bb75c3ea7cba25a9439196eadb211\"><code>void loop() {\n\n  M5.update();\n  if (M5.BtnA.wasPressed()) {\n    Serial.println(\"BtnA\");\n<strong>    speaker.stopVoice(); \/\/\u3000\u505c\u6b62\n    speaker.startVoice(\"\/mp3\/010.mp3\");<\/strong> \/\/ \u8d77\u52d5\n  }<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u901a\u4fe1<\/h2>\n\n\n\n<p>\u6b21\u306b\u5916\u90e8\u304b\u3089\u547c\u3073\u51fa\u305b\u308b\u3088\u3046\u306bserver\u6a5f\u80fd\u3092\u6301\u305f\u305b\u308b\u3002\u5e97\u306e\u5916\u304b\u3089\u547c\u3073\u51fa\u3059\u8a08\u753b\u306e\u3067\u307e\u305a\u306fhttp\u3067\u305d\u306e\u307e\u307e\u5916\u304b\u3089\u3064\u306a\u3052\u3089\u308c\u308b\u3088\u3046\u3059\u308b\u3002\u305d\u306e\u3046\u3061\u30ea\u30d0\u30fc\u30b9\u30d7\u30ed\u30ad\u30b7\u306e\u5f8c\u308d\u306b\u96a0\u3059\u304b\u3082\u3057\u308c\u306a\u3044\u3051\u3069\u3068\u308a\u3042\u3048\u305a\u30eb\u30fc\u30bf\u30fc\u306bNAPT\u3067\u3055\u3070\u304b\u305b\u3066\u304a\u304f\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">wifi\u5468\u308a<\/h3>\n\n\n\n<p>\u30b9\u30de\u30fc\u30c8\u30b3\u30f3\u30d5\u30a3\u30b0\u4f7f\u304a\u3046\u304b\u3068\u8003\u3048\u305f\u3051\u3069\u3001ip\u6307\u5b9a\u3067\u8d77\u52d5\u3059\u308b\u3068\u304d\u306b\u30c7\u30d5\u30a9\u30b2\u3068\u30b5\u30d6\u30cd\u30c3\u30c8\u4e0e\u3048\u306a\u3044\u3068\u3044\u3051\u306a\u304b\u3063\u305f\u3002\u305d\u3044\u3064\u3089\u3092\u3057\u3063\u304b\u308a\u3068\u6e21\u3059\u3068\u306a\u308b\u3068\u5916\u304b\u3089\u4e0e\u3048\u3066\u30b9\u30de\u30fc\u30c8\u30b3\u30f3\u30d5\u30a3\u30b0\u306e\u610f\u5473\u306a\u304f\u306a\u308b\u304b\u3001\u4e00\u56de\u76ee\u306e\u63a5\u7d9a\u3067\u53d6\u308c\u305f\u5024\u3092\u4f7f\u7528\u3068\u9762\u5012\u306b\u306a\u308a\u305d\u3046\u3002\u3068\u3044\u3046\u308f\u3051\u3067\u304a\u3068\u306a\u3057\u304f\u660e\u793a\u7684\u306b\u6307\u5b9a\u3059\u308b\u3053\u3068\u306b\u3057\u305f\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-dark-gray-background-color has-text-color has-background has-link-color wp-elements-d9319a4f9e5fb2f5715dd063b152ea8a\"><code>#include &lt;WiFi.h&gt;\n\n\n\/\/ \u898b\u3048\u3066\u3044\u308b\u3051\u3069\u5e97\u306e\u516c\u958bwifi\u306a\u306e\u3067\u6c17\u306b\u3057\u306a\u3044\n#define STASSID \"rocher_guest\";\n#define STAPSK \"sd5ks86vn5nti\";\nconst char *ssid = STASSID;\nconst char *pass = STAPSK;\nconst IPAddress ip(192, 168, 11, 26);\nconst IPAddress gateway(192, 168, 11, 1);\nconst IPAddress subnet(255, 255, 255, 0);\n\n  WiFi.mode(WIFI_STA);\n\n  if (!WiFi.config(ip, gateway, subnet)) {\n    Serial.println(\"Fail WiFi.config\");\n    for (;;) { delay(1000); }\n  }\n\n  WiFi.begin(ssid, pass);\n\n  while (WiFi.status() != WL_CONNECTED) {\n    delay(500);\n    Serial.print(\".\");\n  }\n<\/code><\/pre>\n\n\n\n<p>\u3068\u3001\u30b5\u30f3\u30d7\u30eb\u306b\u3042\u308a\u305d\u3046\u306a\u3084\u3064\u305d\u306e\u307e\u307e<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">server\u5468\u308a<\/h3>\n\n\n\n<p>\u3053\u308c\u3082\u3088\u304f\u3042\u308a\u305d\u3046\u306a\u3084\u3064\u3002<\/p>\n\n\n\n<p>WebServer.h\u3064\u304b\u3063\u3066\u3001\u547c\u3073\u51fa\u3057\u51e6\u7406\u304c\u3042\u3063\u305f\u3089\u97f3\u58f0\u3092\u6d41\u3059\u51e6\u7406\u3092\u884c\u3046\u3002<\/p>\n\n\n\n<p>handleYobidashi\u306e\u4e2d\u3067\u3001speaker#stopVoice\/speaker#startVoice\u3092\u76f4\u63a5\u547c\u3093\u3067\u3044\u308b\u306e\u3067\u540c\u671f\u51e6\u7406\u306b\u306a\u3063\u3066\u3044\u308b\u3002\u97f3\u58f0\u304c\u6d41\u308c\u7d42\u308f\u3063\u3066\u304b\u3089\u547c\u3073\u51fa\u3057\u5074\u306b\u306f\u30ec\u30b9\u30dd\u30f3\u30b9\u8fd4\u308b\u3002\u4f7f\u3046\u30b1\u30fc\u30b9\u6b21\u7b2c\u3067\u306f\u975e\u540c\u671f\u547c\u3073\u51fa\u3057\u306b\u3059\u308b\u305f\u3081\u306b\u3055\u3089\u306b\u30b9\u30ec\u30c3\u30c9\u3092\u547c\u3076\u5f62\u306b\u3059\u308b\u65b9\u304c\u826f\u3044\u5834\u5408\u306f\u591a\u305d\u3046\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-dark-gray-background-color has-text-color has-background has-link-color wp-elements-d2888213b894ba2cd54899734d314d9a\"><code>#include &lt;WebServer.h&gt;\nWebServer server(80);\n\nvoid handleYobidashi() {\n  speaker.stopVoice();\n  speaker.startVoice(\"\/mp3\/010.mp3\");\n  server.send(200, \"text\/plain\", \"call shop!\");\n}\n\nvoid serverInit() {\n  server.on(\"\/yobidashi\", handleYobidashi);\n  server.onNotFound(&#91;]() {\n    server.send(404, \"text\/plain\", \"not found\");\n  });\n  server.begin();\n  Serial.println(\"server Init!\");\n}\n\nvoid setup() {\n  connectWifi();\n\n  serverInit();\n}\n\nvoid loop() {\n  server.handleClient();\n  delay(2);\n}<\/code><\/pre>\n\n\n\n<p><a href=\"http:\/\/\u81ea\u5b85\u7528\u901a\u77e5\u30de\u30b7\u30f3\u4f5c\u6210(5)\">\u7d9a\u304d<\/a>\u3000\u547c\u3073\u51fa\u3057\u5074\u306e\u81ea\u5b85\u7aef\u672b\u30d0\u30fc\u30b8\u30e7\u30f3\u30a2\u30c3\u30d7<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u97f3\u58f0\u95a2\u9023\u30af\u30e9\u30b9\u5316 \u898b\u901a\u3057\u304c\u60aa\u304f\u306a\u308a\u305d\u3046\u306a\u306e\u3067\u97f3\u58f0\u5468\u308a\u306f\u5225\u30af\u30e9\u30b9\u306b\u3002\u591a\u5206\u307e\u3060\u4e88\u60f3\u3057\u3066\u306a\u3044\u6539\u9020\u3092\u3057\u305d\u306a\u306e\u3067\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u6e21\u3059\u3068\u304b\u8003\u3048\u305a\u306b\u5358\u7d14\u306a\u5225\u30d5\u30a1\u30a4\u30eb\u5316\u3060\u3051\u3002\uff08StackSpeaker.h\uff09 \u547c\u3073\u51fa\u3057\u306f \u3057\u3066\u304a\u3044\u3066\u4f7f\u3044\u305f\u3044\u3068 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[117],"tags":[135,133],"class_list":["post-2039","post","type-post","status-publish","format-standard","hentry","category-117","tag-m5stack","tag-133"],"_links":{"self":[{"href":"https:\/\/www.rocher.kyoto.jp\/arbr\/index.php?rest_route=\/wp\/v2\/posts\/2039","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rocher.kyoto.jp\/arbr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rocher.kyoto.jp\/arbr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rocher.kyoto.jp\/arbr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rocher.kyoto.jp\/arbr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2039"}],"version-history":[{"count":5,"href":"https:\/\/www.rocher.kyoto.jp\/arbr\/index.php?rest_route=\/wp\/v2\/posts\/2039\/revisions"}],"predecessor-version":[{"id":2068,"href":"https:\/\/www.rocher.kyoto.jp\/arbr\/index.php?rest_route=\/wp\/v2\/posts\/2039\/revisions\/2068"}],"wp:attachment":[{"href":"https:\/\/www.rocher.kyoto.jp\/arbr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2039"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rocher.kyoto.jp\/arbr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2039"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rocher.kyoto.jp\/arbr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2039"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}