Last time, we did a tutorial on using old Android devices as video surveillance cameras. Now, if you still have any leftover Androids, you can use them as hidden microphones for noise detection, or even sound recording of your environment. This is a great addition to your DIY Home Security System that will allow you to have ears around the house.
No one pays attention anymore to a phone left on the table, or a phone on the ground charging, especially if that phone is an older model Android (some Android devices have terrible resale value). This means that these are the perfect devices to use for your home security. They have high tech software with access to a massive inventory of applications through Google Play Store, and they have great hardware like their cameras, sensors, and most important for this project, a good microphone.
I use an app called LANmic that allows me to record sound and stream it through HTTP requests. You can adjust the sample rate, the type of encoding, and can even decide to share it with different platforms like Bluetooth and Gmail. For my project, I used HTTP requests at a sample rate of 16000 with WAVE encoding to access this sound data remotely.
Next, you’ll need to process this data with the Python code found below. I used my Raspberry Pi to run the code.
You will need to download the following libraries first:
The first part of the code collects the streamed audio data as bytes from the URL generated by the LANmic app. Here, the data is periodically processed and recorded. The average amplitude/intensity, the most intense frequency, and that max intensity are then calculated from the data, and are what will be sent to the IoT platform! These data are useful in detecting any noise in your house, such as intruders or an unwanted party.
In this section, you will need to input the LANmicURL, the sample rate of the data, stream segment time length (which is also how often this program will do a POST request to the IoT service), and the file location where you store the recorded sound data. This is just in case you want to have a hard copy of the surrounding noise.
framerate = 8000
time_streaming = 5 #seconds
stream_length = time_streaming * 4
nframes = int(stream_length * framerate / 4)
file_location = "INSERT FILE DIRECTORY HERE"
The second part of the code sends this data in JSON format to an IoT platform using HTTP requests. You will need to include the Gateway URL provided by the IoT platform. You can also change the name of Device Friendly Name of your Android in case you add multiple devices to your DIY security system.
UBEAC_URL = 'hub.ubeac.io'
GATEWAY_URL = 'INSERT GATEWAY URL HERE'
DEVICE_FRIENDLY_NAME = 'Android Sound Detector'
Now that all the audio data is processed, send it to the same platform that you connected your Android Security Cameras: uBeac! Here you can track the audio with charts, or just see the real-time data through indicators, all on a simple easy to use IoT dashboard in uBeac’s Dashboard module. See our past article on OS monitoring to learn how to use uBeac and make that dashboard. You can also check out your past sound data in the Reports module in list or chart form. Below is an example of my noise detector system being tracked by uBeac.