Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4834

MicroPython • Re: Building an Internet-Radio using a Pico W using just Python

$
0
0
I just tried the linked example code with adaptions to the Pico W (see below) and the Pimoroni Pico Audio Pack.
It works when using a 64 kbit/s audio stream delivered via HTTP (unencrypted).
Switching to a 128 kbit/s stream results in cracks and noises.

The connection seems to be unreliable but after reconnecting the replay restarts most of the time.

I am looking forward to trying this on a Pico 2 W.

Code:

# SPDX-FileCopyrightText: 2024 Jeff Epler for Adafruit Industries## SPDX-License-Identifier: MIT# Stream MP3 audio to I2S decoder## Tested with:##  * Adafruit Metro ESP32-S3#  * Adafruit Metro ESP32-S2#  * Adafruit Feather ESP32 V2import timeimport adafruit_connection_managerimport adafruit_requestsimport audiobusioimport audiomp3import boardimport wifiimport timemp3_buffer = bytearray(16384)mp3_decoder = audiomp3.MP3Decoder("/silence.mp3", mp3_buffer)pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio)ssl_context = adafruit_connection_manager.get_radio_ssl_context(wifi.radio)requests = adafruit_requests.Session(pool, ssl_context)#STREAMING_URL = "https://ice2.somafm.com/dronezone-128-mp3"#STREAMING_URL = "http://wdr-wdr5-live.icecast.wdr.de/wdr/wdr5/live/mp3/128/stream.mp3"STREAMING_URL = "http://wdr-wdr5-live.icecast.wdr.de/wdr/wdr5/live/mp3/64/stream.mp3"# pimoroni Pico Audio Pack #i2s = audiobusio.I2SOut(bit_clock=board.GP14, word_select=board.GP15, data=board.GP12)i2s = audiobusio.I2SOut(board.GP10, board.GP11, board.GP9)reconnects = 10while reconnects > 0:    reconnects -= 1    print("reconnects: ", reconnects)    with requests.get(STREAMING_URL, headers={"connection": "close"}, stream=True) as response:        print("socket: ", response.socket)        mp3_decoder.file = response.socket        i2s.play(mp3_decoder)        while i2s.playing:            print("playing: ", time.monotonic())            time.sleep(1)print("out")

Statistics: Posted by diereinegier — Sat Dec 21, 2024 3:03 pm



Viewing all articles
Browse latest Browse all 4834

Trending Articles