File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed
CircuitPython_MP3StreamPlayer Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ # SPDX-FileCopyrightText: 2024 Jeff Epler for Adafruit Industries
2+ #
3+ # SPDX-License-Identifier: MIT
4+
5+ # Stream MP3 audio to I2S decoder
6+ #
7+ # Tested with:
8+ #
9+ # * Adafruit Metro ESP32-S3
10+ # * Adafruit Metro ESP32-S2
11+ # * Adafruit Feather ESP32 V2
12+
13+ import time
14+
15+ import adafruit_connection_manager
16+ import adafruit_requests
17+ import audiobusio
18+ import audiomp3
19+ import board
20+ import wifi
21+
22+ mp3_buffer = bytearray (16384 )
23+ mp3_decoder = audiomp3 .MP3Decoder ("/silence.mp3" , mp3_buffer )
24+
25+ pool = adafruit_connection_manager .get_radio_socketpool (wifi .radio )
26+ ssl_context = adafruit_connection_manager .get_radio_ssl_context (wifi .radio )
27+ requests = adafruit_requests .Session (pool , ssl_context )
28+
29+ STREAMING_URL = "https://ice2.somafm.com/dronezone-128-mp3"
30+
31+ if "D27" in dir (board ):
32+ # Feather ESP32 V2 has D27 instead of D11
33+ i2s = audiobusio .I2SOut (bit_clock = board .D12 , word_select = board .D13 , data = board .D27 )
34+ else :
35+ i2s = audiobusio .I2SOut (bit_clock = board .D12 , word_select = board .D13 , data = board .D11 )
36+
37+ with requests .get (STREAMING_URL , headers = {"connection" : "close" }, stream = True ) as response :
38+ mp3_decoder .file = response .socket
39+ i2s .play (mp3_decoder )
40+ while i2s .playing :
41+ time .sleep (0.1 )
You can’t perform that action at this time.
0 commit comments