Skip to content

Latest commit

 

History

History
131 lines (115 loc) · 9.53 KB

README.md

File metadata and controls

131 lines (115 loc) · 9.53 KB

shazamPi

What is it?

  • In essence, shazamPi is a device to record, analyze and identify music, similar to the famous Shazam app for smartphones.

  • The code is entirely python-based and the device is fairly easy to build. No soldering is required.

Who is it for?

  • With its big red button, it is supposed to invite people to record snippets and tag tracks. All analysis results are sent out via eMail to as many people as you want.

  • In my opinion, the perfect application for this device is on a festival totem. You can paste all eMails of your crew members into shazampi.py before an event and everybody will be able to record snippets of a track they like by pressing the red button. At the end of the event, all analyzed track results are sent out to all eMail addresses, creating a shared experience for the whole group. Another fun idea would be to mount the device on one's desk in order to quickly tag a song whenever it comes up in a set, for example.

Context

This device is the next iteration of my initial shazamPi Zero Project. While the previous one was meant to be as small as possible to fit in a little bag and replace an app on a smartphone, I wanted this version to be about the community aspect of tagging tracks with your friends and sharing the results, so I enhanced the device by using a Raspberry Pi instead of a Pi Zero, equipped it with a bigger battery to last through a whole day, a USB microphone instead of a HAT, a small display for fun and a little bit of info, a huge red button with an LED and - on the software side of things - an audio equalizer in order to remove some of the unwanted bass in recordings to get better analysis results; I dare say better results than with my smartphone. In the end, I mounted the device onto a large pole that I took to various dancefloors on festivals and everybody could smash that big red button (which reads geiler Track = awesome track in German) to record a snippet and tag a track.

Hardware



The shazamPi in its natural habitat on a rainbow totem Close-up of the assembled device
Assembled device in airtight case (ready to be mounted) Red means recording



Functionality

  1. On booting up the device by switching on the power supply (in this case hooking up the powerbank):

    • Power-saving measures are activated.
    • The shazampi.py script is started.
    • Once everything is operational, the green LED on the Pi's board starts to blink slowly, signaling the device is 'ready to be used'.
    • The display either
      • a) reads "PUSH!" in case the device is not connected to the internet (= the user is away from home) or
      • b) shows your network IP, device name and how many tracks are ready to be analyzed in case the device is connected to the internet (= the user is home).
  2. On pushing the big red button, the device checks for an internet connection again.

    • If there is no internet connection (= the user is away from home):
      • An audio clip is recorded while a red LED illuminates the big red button and the display reads "RECORDING!" (as seen on the picture above).
      • After recording, the new file is stored on the microSD card.
      • The newly recorded file gets sent through an equalizer software in order to remove most of the bass, which improves analysis results and is saved to another folder.
      • Once finished, the device reverts back to the 'ready to be used' status, the button LED is switched off and the green LED on the Pi's board starts to blink slowly again.
    • If there is an internet connection (= the user is home):
      • All previously recorded and equalized clips are analyzed for artist and track name data while the display reads "TAGGING!".
      • All analysis results are stored in a log file and are then sent via eMail, if this is enabled within the global settings of shazampi.py.
      • All analyzed source clips are renamed to their respective tags and moved to a seperate directory on the microSD card, so they won't be analyzed a second time.
      • Once finished, the devices reverts back to the 'ready to be used' status (green LED on the Pi's board slowly blinking again).

Setup

  1. Assemble the hardware:
    • Put the case onto the Raspberry Pi
    • Hook up the microphone via USB
    • Push the mini display onto the respective GPIO pins
    • Connect the big red arcade button to the GPIO pins you intend to use. Personally, I used GPIO10 (Pin 19) and GND (Pin 9) for the button's trigger functionality as well as GPIO17 (Pin 11) and GND (Pin 14) for the button's LED functionality. Here, a GPIO Pin Map can help with navigating.
  2. Flash Pi OS Legacy Lite (the one that's based on Debian Bullseye) onto the microSD card (SSH enabled) and make the device connect to your WiFi.
  3. Update/upgrade with sudo apt-get update && sudo apt-get upgrade -y
  4. Install python3-pip via sudo apt-get install python3-pip -y
  5. Install required applications for the display
sudo apt install --upgrade python3-setuptools
sudo pip3 install adafruit-circuitpython-ssd1306
sudo apt-get install python3-pil
sudo apt-get install i2c-tools -y
  1. Install required applications for shazam functionality
sudo pip install shazamio
sudo apt-get install alsa-utils && sudo apt-get install libasound2-plugin-equal -y
sudo apt install ffmpeg -y
sudo apt-get install sox -y
  1. Create necessary folders. You can choose to place these elsewhere and edit global settings within shazampi.py accordingly, but this is the default configuration:
/var/shazampi
/var/shazampi/analysis_logs
/var/shazampi/old_recordings
/var/shazampi/old_recordings_posteq
/var/shazampi/new_recordings
/var/shazampi/new_recordings_posteq
  1. Transfer the display font (swift.ttf) and my script (shazampi.py) into /var/shazampi/. I always use FileZilla SSH for this, but there are many ways to do this.
  2. Edit access permissions for the shazampi folder and the system LED directory by entering the following. However, be careful as the ACT folder might differ in different PiOS versions.
sudo chmod -R 777 /var/shazampi
sudo chmod -R 777 /sys/class/leds/ACT
  1. Edit the global settings (like eMail configuration etc.) at the top of shazampi.py to your liking and save the file.
  2. Adjust the microphone input signal by executing sudo alsamixer if you plan on using the device in a very high volume environment.
    • After executing the command, you can select your USB microphone from as dropdown menu by hitting F6 and then adjust the capture volume after hitting F5. I used a dB gain of 18, which delivered satisfactory results.
    • Restore your alsamixer configuration automatically after reboot. How this is done is described here.
  3. Reduce power consumption of your device with these Instructions in order to maximize your runtime on battery:
  • Disable HDMI input/output
  • Disable bluetooth
  • You can also throttle the CPU, but I personally think this is only necessary if you have hard battery constraints
  1. Make shazampi.py execute on bootup. There are many ways to do this and one way can be achieved by creating a systemd service file:
  • Enter sudo nano /etc/systemd/system/shazampi.service.
  • Paste this:
    [Unit]
     Description=Shazampi Script
     After=network.target
    
     [Service]
     ExecStart=/usr/bin/python3 /var/shazampi/shazampi.py
     WorkingDirectory=/var/shazampi/
     StandardOutput=inherit
     StandardError=inherit
     Restart=always
     User=root
     Environment=PYTHONUNBUFFERED=1
    
     [Install]
     WantedBy=multi-user.target```
    
  • Enable and start the service by executing
    sudo systemctl daemon-reload
    sudo systemctl enable shazampi.service
    sudo systemctl start shazampi.service
    
  1. Reboot and verify. You're done.