Open aidam38 opened 1 year ago
Hello aidam38, the problem is not the audio source. WiFi will work if you extend the example accordingly. The reason why I didn't include the opus decoder in audioI2S is the required size of the stack. audioI2S runs in the Arduino loop(). This is not sufficient for opus, too many recursions lead to a crash. The Arduino loop stack should be twice as big. How do you download audio streams from YouTuv'be. Do you have a premium account? And MP4 is not compatible with m4a.
You don't need YouTube Premium or any sort of authentication to get audio streams from YouTube. Personally I'm using this library https://www.npmjs.com/package/ytdl-core and this short js snippet to get audio-only streams:
const info = await ytdl.getInfo("https://www.youtube.com/watch?v=VYJtb2YXae8")
const formats = ytdl.filterFormats(info.formats, "audioonly")
but I assume there's some sort of official YouTube API behind this which allows a client to request audio stream links for YouTube URLs (the urls returned from ytdl
have an expiration and include the clients IP address in the query parameters; hence why I'm not including an example link here because it'd stop working in a day or so and I don't want to expose my IP).
The indicated mime types of the available streams are audio/mp4; codecs="mp4a.40.2"
and audio/webm; codecs="opus"
.
Thanks @schreibfaul1 for your libraries, which are extremely helpful. I am building a webradio/podcast player and really would like to have the capability to play OPUS podcasts from the web.
The reason why I didn't include the opus decoder in audioI2S is the required size of the stack. audioI2S runs in the Arduino loop(). This is not sufficient for opus, too many recursions lead to a crash. The Arduino loop stack should be twice as big.
Could we configure it to be twice as big? Would this help?
https://community.platformio.org/t/esp32-stack-configuration-reloaded/20994/4
In my audioI2S repository there is a test branch with this OPUS decoder but with a smaller stack, PSRAM is recommended. https://github.com/schreibfaul1/ESP32-audioI2S/tree/only_for_testing
Thanks for the test branch with this OPUS decoder. Unfortunately I don't have a PSRAM device at hand. On my a ESP32-PICO-KIT V4 with i2s DAC, using 70a1311 has the side effect that I can no longer play this stream in my sketch, which did play before:
http://188.40.97.185:8179/stream
Is this caused by unrelated changes or does merely adding the OPUS codec impact the ability to play other formats?
It'd absolutely awesome if this library also worked with remote host/url, like in https://github.com/schreibfaul1/ESP32-audioI2S. This would allow playing audio directly from youtube using the audio-only links generated by youtube-dl (the two audio codecs offered by youtube are opus and mp4a, I tried getting mp4a work with ESP32-audioI2S but ran into some issue, and I don't know if mp4a is compatible with m4a or aac anyway...).
I tried looking into implementing this myself, but it seems to be out of my abilities for now... Is there any chance you could take some time to implement this?