markondej / fm_transmitter

Raspberry Pi as FM transmitter
1.3k stars 289 forks source link

How do I randomize playback in a specific folder? #167

Open Starlaw249 opened 2 years ago

Starlaw249 commented 2 years ago

How do I randomly select an audio track in a folder to loop playback (for example I have 5 songs that I want to play at random in a folder called "music")

BobHasNoSoul commented 2 years ago

this isnt really an issue with this project but i will try to help you random internet stranger

#!/bin/bash
for (( ; ; ))
do
    randsong="$(find '/mnt/Music' -type f -name '*.mp3' | shuf -n1)"
    echo "$randsong"
    sox "$randsong" -r 22050 -c 1 -b 16 -t wav - | sudo ./fm_transmitter -f 93.5  - }
done
;;

you will have to modify the folder locations and frequency listed but this will take your mp3s shuffle them and broadcast them over and over and over until you eventually want to curl up in a ball at disney world because the five nation army song just came on for the 200000000 time.

i got a little off topic there in short, use code above modify the folder from "/mnt/Music" to your music folder (yes nested work but may be slow on massive networked libraries) and modify the frequency as needed it is currently set in this post to 93.5mhz

hope this helps even though i am a little late to this thread

edit save the code above as a file named "shuffle.sh" then make it executable "chmod +x" and then you can run it with "./shuffle.sh"