When I first noticed Expand Your Senses challenge on Hackster, I told myself, this is a perfect marriage - sensory substitution with artificial intelligence!
Well, what is sensory substitution? In simple words, it's a technique to supplement the lost of one sense by feeding it's information from another channel. For example, when a person goes blind, generally does not lose the ability to see, they simply lose their ability to transmit the sensory signals from the retina to brain. Since the vision processing pathways are still intact, a person who has lost the ability to retrieve data from the retina can still see subjective images by using data gathered from other sensory modalities such as touch or audio. [Source wiki]
Neuroplasticity or Brain plasticity makes this happen by remapping pathways.
What is Neosensory Buzz?When we become fluent in a language, learn to ride a bike, or refine our bat swing, we form associations with patterns of information from our physical world. Buzz is a wearable device that produces vibrational patterns on the skin. With practice, these associations become automatic and a new sense is born.
Well, with the promise of Buzz and Edge Impulse, I don't want to build just a feedback or alert system which would be super under utilization of such an advanced products. Microcontrollers with sensors and mobile apps are best suited for such applications. Buzz can produce haptic feedback which should be used for a bigger cause such as substituting lost senses or create new senses which humans don't have organically.
In the past, it was believed that human brain does not grow or change after a certain age, acts like static organ but recent study and research has proved that neural network changes over time, creating new pathways and deleting old pathways. This is called brain-plasticity. Researchers have studied drivers brain before and after taking taxi-driving test in London city and they observed new neural pathways developed in brain after the test.
Similarly, haptic feedback can be used to send some visual signal or audio signal to brain using regular visual or audio neural pathways. Over the time and practice, brain will accept haptic feedback and process them as if they are received from retina or ears, substituting a lost sense.
It's also proven that new senses can be developed. For example we don't usually feel anything except smell while in deep sleep but can train our brain to respond to some haptic feedback even while we are in sleep, creating new senses.
There are lot of areas where sensory substitution can be used along with ML & AI. After doing few weeks of study I chose few use-cases which I felt very very common and can provide a better living.
1. Emotion interpretation for ASDPeople suffering with autism spectrum disorder (ASD) often struggle to interpret different emotional reactions from other people. Ears or Eyes are not able to send correct electro-chemical signal to brain. This is a good use-case for sensory substitution. I have developed a machine learning model using Edge Impulse studio which classifies different speeches or words into predefined labels such as greeting, happy, angry, sad etc. Based on the classified label, device sends a predefined frame set to Buzz. With training and practice people can learn the meaning of different vibration pattern. New wiring will be created in human brain and people can see or hear the vibration.
2. Sign Language InterpretationThis is another very useful use case for people suffering with autism spectrum disorder (ASD). They often struggle to recognize different sign languages. This use case if very useful for visually impaired persons as well. I have developed another ML model using EI studio to classify different American sign languages (ASL) from images taken from Raspberry Pi camera. I have trained "Thank you", "Please", "Sleep" and "Drink" as proof of concept.
3. Reduce Snore And Sleep BetterSnoring once in a while isn't usually a serious problem. It's mostly a nuisance for your bed partner. But if you're a long-term snorer, you not only disrupt the sleep patterns of those close to you, you hurt your own sleep quality. Snoring can itself be a symptom of a health problem like obstructive sleep apnea. When we fall asleep, our neck and throat muscles relax which tightens our airways and causes the vibrations in our throat. I have developed a ML model to classify snore and other background noise. When snoring is detected throughout the night, device sends haptic feedback to the Buzz. With practice, your brain will rewire pathways in your brain and you can feel snore even while you are sleep and you can change your sleeping posture to reduce snore.
4. General Purpose, Touch The SoundFinally, this use case can be useful for different purposes, specially for people with visually impaired. ML model can classify different objects and animals such as Dog, Television, Cars etc. Device will send pictures every seconds and send to the classifier. Once object is detected, device will send haptic feedback This is a perfect example of sensory substitution.
Demo Video.
Boon Mobile AppI have created a simple but powerful iOS mobile app where you can see the connected Buzz and information related to the Buzz such as Device ID, Serial No and remaining battery life.
Along with this, you can select different modes as I explained earlier to turn the same device into multiple products.
There is a training screen where you can train yourself with different modes and activities to recognize Buzz vibration pattern. Soon your brain wiring will recognize the patterns and vibration can be felt as you are hearing or seeing.
The DeviceArchitecture is very simple. Keeping "separation of concerns" in mind, I have used ESP32 module with BLE only to interface with Neosensory Buzz. ESP32 module does not take any decision, it only connects to the Buzz and sends motor vibration frames as it receives from Raspberry Pi or Mobile app over MQTT.
On the other hand, the Boon module is comprised of a Raspberry Pi 4, Pi Camera and a microphone. I have used RaspiAudio as it was laying on my desk but you can use any USB microphone as well. All the EI inference engine and live streaming code runs on Raspberry Pi. Device management is done through Balena Cloud as it provides the ability to deploy code remotely and also provides a public URL which you can use to stream live video from anywhere.
I have a plan to remove ESP32 from the hardware stack and replace BLE capabilities with Raspberry Pi BLE and write a NodeJS library for the Buzz. This will allow me to remove MQTT from software stack as well making the device working without internet connection. Stay tuned.
Update: 01/22/2021
Making a good progress on python based neosensory library on balenaOS. You can see in below screenshot that I was able to make connection to the buzz from Rpi4 deployed on Balena cloud. I still have some issues such as - sometimes it does not connect, sometimes it can't pair. Few restart fixes the issue but I am not convinced yet to share with the community.
ESP32
I chose ESP32 to interface with Buzz as it's very low cost and has in-built BLE and WiFi module. I have written a library for ESP32 which you can use to connect your Buzz quite easily. Only role of ESP32 in this project is - connect to Buzz and vibrate motors. It's connected to Raspberry Pi and Mobile phone over MQTT. ESP32 receives request from inference engine running on Raspberry Pi (NodeJS service) or from Mobile app during training. Frames are separated by semicolon. First number represents number of frames and next 4 numbers represent frequency of four motors.
35,0,40,80,100;
35,100,60,80,40;35,0,40,80,100;
In above example, ESP32 will send 3 different frame sets to Buzz as you can see in below log.
Buzz Frames
Message arrived in topic: /neoosensory/boon/01/rx/buzz
Message:35,0,40,80,100;35,100,60,80,40;35,0,40,80,100;
-----------------------
BUZZ Requested
Processing frame : 35,0,40,80,100
No of frames 35
Frame is {0, 40, 80, 100}
motors vibrate ADNNXAAzTVwAM01cADNNXAAzTVwAM01cADNNXAAzTVwAM01cADNNXAAzTVwAM01cADNNXAAzTVwAM01cADNNXAAzTVwAM01cADNNXAAzTVwAM01cADNNXAAzTVwAM01cADNNXAAzTVwAM01cADNNXAAzTVwAM01cADNNXAAzTVwAM01cADNNXAAAAAA=
ble_cli:~$ Processing frame : 35,100,60,80,40
No of frames 35
Frame is {100, 60, 80, 40}
motors vibrate XD9NM1w/TTNcP00zXD9NM1w/TTNcP00zXD9NM1w/TTNcP00zXD9NM1w/TTNcP00zXD9NM1w/TTNcP00zXD9NM1w/TTNcP00zXD9NM1w/TTNcP00zXD9NM1w/TTNcP00zXD9NM1w/TTNcP00zXD9NM1w/TTNcP00zXD9NM1w/TTNcP00zXD9NMwAAAAA=
ble_cli:~$ Processing frame : 35,0,40,80,100
No of frames 35
Frame is {0, 40, 80, 100}
motors vibrate ADNNXAAzTVwAM01cADNNXAAzTVwAM01cADNNXAAzTVwAM01cADNNXAAzTVwAM01cADNNXAAzTVwAM01cADNNXAAzTVwAM01cADNNXAAzTVwAM01cADNNXAAzTVwAM01cADNNXAAzTVwAM01cADNNXAAzTVwAM01cADNNXAAzTVwAM01cADNNXAAAAAA=
Follow the library github page to get started with ESP32 library and then upload the sketch ( check code section below) to your ESP32 dev board.
Edge ImpulseI have used Edge Impulse Studio to build my ML models. Altogether I have created four different projects in EI Studio, one each for each of the use cases described above. ASD emotion interpretation and snoring uses voice based ML and other two uses image based ML.
For voice based ML, I have captured audio of 4 seconds through phone. For detail tutorial on audio classification, checkout this tutorial.
For snoring, I have captured around 5 minutes of snore sound taken from different sources such as youtube and 5 minutes of background noise such as music, baby crying, breathing etc.
And sliced them into 2s clips with increase window of 300ms. In the end, I got around 85% confidence level.
Once your model is ready, build "Web Assembly" from "Deployment" page. It will download a zip file containing one JS file and one WASM file. You don't need them now as Balena will download them from EI calling API. You need to copy the project ID and generate one API key for the project.
Head over to "Dashboard" page and under "Project Info", you will find your project Id. Next, click on "Keys" tab and generate API key. Copy both of them somewhere as you will need them while deploying balena project.
Similarly I have created a project for ASD emotion interpretation. I have classified only "happy", "greeting" and "unknown" for now due to time constraint.
For sign language, I have classified 4 labels - please, sleep, thank you and drink. Follow this tutorial on EI website to better understand image classification.
Honestly, my model is not trained properly yet and I am working on it to make it more efficient by capturing lot more images.
Why Balena OS?1. OTA Firmware Updates
I chose Balena OS as it's based on docker containers and you can simply deploy to different devices such as RPI 3 or 4 or zero. You don't need to deal with custom software installations and configurations which are real pain for any raspberry pi based projects. Moreover you can deploy changes remotely. For any ML project, you keep on training your model, so over the air update (OTA) is very important consideration while making such device. Using balena OS and EI API, we can seamlessly achieve this. On start of the docker container, I am downloading EI web assembly package ( javascript and wasm file ) which makes sure your device is always running latest inference engine.
#!/bin/sh
#This script downloads WASM classifier using Edge Impulse API
# API Key and Project ID are defined as environment variables in BalenaCloud
# Download Autism Sound classifier
AUTISM_SOUND_EI_API_KEY=xxx
AUTISM_SOUND_EI_PROJECT_ID=xxx
curl --request GET \
--url "https://studio.edgeimpulse.com/v1/api/$AUTISM_SOUND_EI_PROJECT_ID/deployment/download?type=wasm" \
--header "accept: application/zip" \
--header "x-api-key: $AUTISM_SOUND_EI_API_KEY" --output wasm.zip
unzip -o wasm.zip && rm wasm.zip
mv ./edge-impulse-standalone.js ./autism-sound/edge-impulse-standalone.js
mv ./edge-impulse-standalone.wasm ./autism-sound/edge-impulse-standalone.wasm
# Download Snoring Sound classifier
SNORE_SOUND_EI_API_KEY=xxx
SNORE_SOUND_EI_PROJECT_ID=xxx
curl --request GET \
--url "https://studio.edgeimpulse.com/v1/api/$SNORE_SOUND_EI_PROJECT_ID/deployment/download?type=wasm" \
--header "accept: application/zip" \
--header "x-api-key: $SNORE_SOUND_EI_API_KEY" --output wasm.zip
unzip -o wasm.zip && rm wasm.zip
mv ./edge-impulse-standalone.js ./snore-sound/edge-impulse-standalone.js
mv ./edge-impulse-standalone.wasm ./snore-sound/edge-impulse-standalone.wasm
# default WASM classifier will be loaded if curl request fails
exit 0
Though you don't need to install and configure softwares on your Raspberry Pi but you still need some configuration which you can done at fleet level, meaning all devices will automatically acquire those configurations.
2. Running multiple EI inference on same device.
As I my goal is to make one device which can be used for different purposes, I need to run multiple inference engine on same device. As Raspberry Pi is much powerful than Arduino Nano BLE sense or similar microcontrollers, it's quite positive to achieve this goal. I have deployed four different EI models in the same container and switching only one "on" based on users selection from mobile app.
Creating Balena Cloud projectHead over to my github repo https://github.com/just4give/neosensory-balena-ei and click on "Deploy with balena" button.
Once you deployed, head over to "Device configuration" and make changes as per above screen shot.
Make sure "audio" is "off" in DT Parameters.
Change DT Overlays to "googlevoicehat-soundcard".
BALENA_HOST_CONFIG_start_x = 1
BALENA_HOST_CONFIG_gpu_mem_256 = 192
BALENA_HOST_CONFIG_gpu_mem_512 = 256
BALENA_HOST_CONFIG_gpu_mem_1024 = 448
This is very important configuration based on DAC you are using. I have used "Raspiaudio". You may check this link for supported devices. https://sound.balenalabs.io/docs/audio-interfaces/
Next, head over to Service Variables and add above variables under "Voice" service. Copy Project IDs and API Keys from EI Studio.
Next, enable public device url and click on the link which will take you to live video stream.
Only your imagination is the limit. As you can classify audio and images using EI studio and you can send vibration frames to Neosensory Buzz, you can think about any use case to provide haptic feedback to users such as detecting fires, assist a blind person to walk on the road.
You can classify animal sounds such as dogs barking and send haptic feedback about what your furry dog wants. They make different sounds based on different situations, for example when they are scared, when they wants to play etc. This is going to be my next project.
I really like to use Neosensory buzz in my day to day life and I am sure with the power of brain-plasticity, I would develop a new sense to communicate with my dog :)
Comments