{"id":685,"date":"2022-12-15T14:28:29","date_gmt":"2022-12-15T06:28:29","guid":{"rendered":"http:\/\/wordpress.loc\/?p=685"},"modified":"2022-12-15T14:29:09","modified_gmt":"2022-12-15T06:29:09","slug":"esp32_ch3-3","status":"publish","type":"post","link":"https:\/\/www.nmking.io\/index.php\/2022\/12\/15\/685\/","title":{"rendered":"ESP8266 mp3 player \u97f3\u6a02\u64ad\u653e\u5668"},"content":{"rendered":"\n<figure class=\"wp-block-pullquote\"><blockquote><p>\u4e00\u500b\u5925\u4f34\u50b3\u4f86\u4e00\u500b\u7528esp8266\u64ad\u653emp3\u7684\u67b6\u69cb\uff0c\u8981\u6211\u5e6b\u5fd9\u6539\u6210ESP32\u7248\u672c<\/p><\/blockquote><\/figure>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-ht-block-toc is-style-rounded htoc htoc--position-wide toc-list-style-plain\" data-htoc-state=\"expanded\"><span class=\"htoc__title\"><span class=\"ht_toc_title\">Table of Contents<\/span><span class=\"htoc__toggle\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"16\" height=\"16\"><g fill=\"#444\"><path d=\"M15 7H1c-.6 0-1 .4-1 1s.4 1 1 1h14c.6 0 1-.4 1-1s-.4-1-1-1z\"><\/path><path d=\"M15 1H1c-.6 0-1 .4-1 1s.4 1 1 1h14c.6 0 1-.4 1-1s-.4-1-1-1zM15 13H1c-.6 0-1 .4-1 1s.4 1 1 1h14c.6 0 1-.4 1-1s-.4-1-1-1z\"><\/path><\/g><\/svg><\/span><\/span><div class=\"htoc__itemswrap\"><ul class=\"ht_toc_list\"><li class=\"\"><a href=\"#htoc-\">\u5be6\u505a\u8aaa\u660e<\/a><\/li><li class=\"\"><a href=\"#htoc-1\">\u4e00\u3001\u6750\u6599\u6e96\u5099<\/a><\/li><li class=\"\"><a href=\"#htoc-11\">\u4e8c\u3001\u786c\u9ad4\u63a5\u7dda<\/a><\/li><li class=\"\"><a href=\"#htoc-111\">\u4e09\u3001\u7a0b\u5f0f\u8a2d\u8a08<\/a><\/li><\/ul><\/div><\/div>\n\n\n\n<p>\u6211\u7684ESP32\u5be6\u505a\u66f8\u7c4d\uff1a<a rel=\"noreferrer noopener\" href=\"https:\/\/www.nmking.io\/index.php\/2022\/11\/10\/esp32_ch1-2\/\" target=\"_blank\">\u6211\u51fa\u66f8\u4e86 ESP32 \u7269\u806f\u7db2\u5c08\u984c<\/a><br>\u535a\u5ba2\u4f86\u7db2\u5740\uff1a<a rel=\"noreferrer noopener\" href=\"https:\/\/www.books.com.tw\/products\/0010901195\" target=\"_blank\">https:\/\/www.books.com.tw\/products\/0010901195<\/a><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"htoc-\">\u5be6\u505a\u8aaa\u660e<\/h2>\n\n\n\n<p>\u4e00\u500b\u5925\u4f34\u50b3\u4f86\u4e00\u500b\u7528esp8266\u64ad\u653emp3\u7684\u67b6\u69cb\uff0c\u8981\u6211\u5e6b\u5fd9\u6539\u6210ESP32\u7248\u672c\uff0c\u539f\u672c\u6211\u4e00\u76f4\u4ee5\u70ba\u5b83\u662f\u7528dfplayer\u7684\uff0c\u6c92\u60f3\u5230\u7adf\u7136\u662f\u76f4\u63a5\u63a5\u5728esp8266\u7684rx\u8173\u4f4d\u64ad\u653e\uff0c\u9664\u4e86SD\u5361\u5916\uff0c\u6c92\u6709\u5916\u52a0\u4efb\u4f55\u88dd\u7f6e\uff0c\u9760\u8457\u7684\u662f\u8edf\u9ad4Lib dac\u505amp3\u89e3\u78bc\u3002<\/p>\n\n\n\n<p>\u67e5\u4e86\u4e00\u4e0b\u662f\u63a1\u7528esp8266audio\u9019\u500blib(\u9019\u500blib\u540c\u6642\u9069\u7528esp32)\uff0c\u5728\u6b64\u501f\u82b1\u737b\u4f5b\u5148\u63d0\u4f9b8266\u7684\u7a0b\u5f0f\u78bc\u53ca\u63a5\u7dda\u65b9\u5f0f\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"htoc-1\">\u4e00\u3001\u6750\u6599\u6e96\u5099<\/h2>\n\n\n\n<p>1.ESP8266\u4efb\u610f\u7248\u672c\u7686\u53ef<\/p>\n\n\n\n<p>2.SPI\u754c\u9762SD\u8b80\u5361\u6a5f\u53ca\u4e00\u7247SD\u5361\uff0c\u50cf\u9019\u6b3e\uff1a <a href=\"https:\/\/goods.ruten.com.tw\/item\/show?21652913575950\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/goods.ruten.com.tw\/item\/show?21652913575950<\/a><\/p>\n\n\n\n<p>3.\u5167\u5efa\u64f4\u5927\u5668\u5587\u53ed\uff0c\u50cf\u662f\u4e00\u822c\u7684\u96fb\u8166\u7528\u5587\u53ed\u5373\u53ef\uff0c\u4e3b\u8981\u662f\u56e0\u70barx\u8173\u4f4d\u672c\u8eab\u6c92\u6709\u96fb\u58d3\u8f38\u51fa\uff0c\u6240\u4ee5\u4e0d\u80fd\u4f7f\u75288\u6b50\u59c6\u90a3\u7a2e\u6c92\u6709\u5167\u5efa\u64f4\u5927\u5668\u7684speaker<\/p>\n\n\n\n<p>4.\u5404\u5f0f\u675c\u90a6\u7dda\u6578\u689d<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"htoc-11\">\u4e8c\u3001\u786c\u9ad4\u63a5\u7dda<\/h2>\n\n\n\n<p>1.\u5148\u5c07SD\u8b80\u5361\u6a5f\u63a5\u5728ESP8266\u7684SPI\u8173\u4f4d(CS, MISO, MOSI, SCK)<\/p>\n\n\n\n<p>2.\u5c07\u64f4\u5927\u5668\u5587\u53ed\u7684\u97f3\u6e90\u6b63\u8ca0\u6975\u540c\u6642\u63a5\u5728rx\u4e0a<\/p>\n\n\n\n<p>3.\u518d\u6b21\u63d0\u9192\uff0c\u8981\u4f7f\u7528\u6709\u64f4\u5927\u5668\u7684\u5587\u53ed\uff0c\u5c07\u5587\u53ed\u63a5\u4e0a\u96fb\u6e90<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1583771877-2875630206_n.png?resize=839%2C580&#038;ssl=1\" alt=\"\" width=\"839\" height=\"580\"\/><figcaption class=\"wp-element-caption\">\u786c\u9ad4\u63a5\u7dda\u5716<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"htoc-111\">\u4e09\u3001\u7a0b\u5f0f\u8a2d\u8a08<\/h2>\n\n\n\n<p>\u9996\u5148\u81f3github\u4e0b\u8f09esp8266audio\u51fd\u5f0f\u5eab\uff1a <a href=\"https:\/\/github.com\/earlephilhower\/ESP8266Audio\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/earlephilhower\/ESP8266Audio<\/a><\/p>\n\n\n\n<p>\u9ede\u9078\u53f3\u4e0a\u89d2Clone or download\/Download Zip<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1583773041-544597436_n.png?resize=841%2C367&#038;ssl=1\" alt=\"\" width=\"841\" height=\"367\"\/><figcaption class=\"wp-element-caption\">github\u51fd\u5f0f\u5eab\u4e0b\u8f09\u4f4d\u7f6e<\/figcaption><\/figure>\n\n\n\n<p>\u4e0b\u8f09\u5b8c\u7562\u5f8c\uff0c\u9078\u64c7\u8349\u7a3f\u78bc\/\u532f\u5165\u7a0b\u5f0f\u5eab\/\u52a0\u5165.Zip\u7a0b\u5f0f\u5eab<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1583773179-259876887_n.png?resize=843%2C545&#038;ssl=1\" alt=\"\" width=\"843\" height=\"545\"\/><figcaption class=\"wp-element-caption\">\u532f\u5165\u7a0b\u5f0f\u5eab<\/figcaption><\/figure>\n\n\n\n<p>\u5728\u958b\u555f\u8996\u7a97\u4e2d\u9078\u64c7\u525b\u525b\u4e0b\u8f09\u7684ESP8266Audio-master.zip\uff0c\u518d\u9078\u958b\u555f\u5373\u53ef\u5b8c\u6210\u532f\u5165\u529f\u80fd\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1583773398-1702235938_n.png?resize=841%2C594&#038;ssl=1\" alt=\"\" width=\"841\" height=\"594\"\/><\/figure>\n\n\n\n<p>\u5b8c\u6210\u7a0b\u5f0f\u5eab\u532f\u5165\u5f8c\uff0c\u6211\u5011\u5c07\u4e00\u9996mp3\u6a94\u6848\u8907\u88fd\u5230sd\u5361\u6839\u76ee\u9304\u4e2d\u9032\u884c\u6e2c\u8a66\uff0c\u4e26\u547d\u540d\u70ba\u300cTRACK0.mp3\u300d\uff0c\u5f8c\u7e8c\u4f7f\u7528\u8005\u53ef\u81ea\u884c\u65bc\u7a0b\u5f0f\u4e2d\u66f4\u6539\u6a94\u6848\u540d\u7a31\u3002<\/p>\n\n\n\n<p>\u4ee5\u4e0b\u7bc4\u4f8b\u7a0b\u5f0f\u4fee\u6539\u65bc\u7bc4\u4f8b\u7a0b\u5f0f\uff0c\u958b\u6a5f\u5f8c\u6703\u76f4\u63a5\u958b\u555fTRACK0.mp3\u9032\u884c\u64ad\u653e\u3002<\/p>\n\n\n\n<p>\u7d50\u8ad6\u662f\uff1a\u97f3\u6548\u54c1\u8cea\u666e\uff0c\u5c0f\u8072\u4e0d\u66b4\u97f3\uff0c\u4f46\u5076\u723e\u6703\u6709\u96dc\u97f3<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include \"AudioFileSourceSD.h\"\n#include \"AudioFileSourceID3.h\"\n#include \"AudioGeneratorMP3.h\"\n#include \"AudioOutputI2SNoDAC.h\"\n#include \"SD.h\"\n#include \"SPI.h\"\n\nAudioGeneratorMP3 *mp3;\nAudioFileSourceSD *file;\nAudioOutputI2SNoDAC *out;\nAudioFileSourceID3 *id3;\nuint32_t Size = ESP.getFreeHeap();\nvoid setup() {\n  Serial.begin(115200);\n  delay(1000);\n  Serial.print(\"Initializing SD card...\");\n  if (!SD.begin(D3))\n  {\n    Serial.println(\"initialization failed!\");\n    return;\n  }\n  Serial.println(\"initialization done.\");\n  delay(100);\n  file = new AudioFileSourceSD(\"\/TRACK0.mp3\");\n\n  out = new AudioOutputI2SNoDAC();\n  mp3 = new AudioGeneratorMP3();\n  mp3->begin(file, out);  \n\n}\n\nvoid loop() {\n  if (mp3->isRunning()) {\n    if (!mp3->loop()) {\n        mp3->stop();\n        delete file;\n        delete mp3;\n        mp3 = new AudioGeneratorMP3();\n        file = new AudioFileSourceSD(\"\/TRACK0.mp3\");\n        mp3->begin(file, out);\n        Serial.println(Size);\n    }\n  } else {\n    Serial.printf(\"MP3 done\\n\");\n    delay(1000);\n  }\n\n}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"esp8266 audio mp3 player\" width=\"1290\" height=\"726\" src=\"https:\/\/www.youtube.com\/embed\/uD2wUDSCHMg?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u500b\u5925\u4f34\u50b3\u4f86\u4e00\u500b\u7528esp8266\u64ad\u653emp3\u7684\u67b6\u69cb\uff0c\u8981\u6211\u5e6b\u5fd9\u6539\u6210ESP32\u7248\u672c \u6211\u7684ESP32\u5be6\u505a\u66f8\u7c4d\uff1a\u6211\u51fa\u66f8\u4e86 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-685","post","type-post","status-publish","format-standard","hentry","category-esp32"],"blocksy_meta":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/posts\/685","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/comments?post=685"}],"version-history":[{"count":1,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/posts\/685\/revisions"}],"predecessor-version":[{"id":686,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/posts\/685\/revisions\/686"}],"wp:attachment":[{"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/media?parent=685"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/categories?post=685"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/tags?post=685"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}