I recently acquired a raspberry pi 4B with 8GB of ram along with a pi camera and other sensors. My first project is to build a robust platform on which I can run the vOICe.
It is possible to run the vOICe on the phone and on smart glasses and I do both. However, I want an inexpensive solution whose components can be easily replaced. Moreover, I want something where the software is being upgraded quickly and that is mainstream.
The raspberry pi fits the bill. It is mainstream, is being upgraded and the raspberry OS is a derivative of debian which works.
Moreover, the solution is accessible.
- A raspberry pi 4B, get either the 4GB or 8GB variants.
- A keyboard connected to the pi.
- A pi camera that is connected to the pi. You can use a USB webcam.
- A consistent power source
- Headphones or powered speakers connected to the 3.5MM jack of the pi or you need audio over HDMI
- A 32GB or greater sd card.
- The pi must have an internet connection via wireless or a wired LAN
- SSH must be enabled
- Use a distribution with a desktop such as the raspberry OS full or desktop distribution
Testing if everything is working
- At the console type
and check if audio out is set to your preferred device.
- Do enable the camera interface after which you may have to reboot the pi.
Testing if the camera is working
It is important to determine if the pi camera is connected correctly. The most accessible way to do this is as follows.
run the following command from within the console.
On my raspberry pi, I get the following output.
pi@glasses:~ $ vcgencmd get_camera
If you see that the detected camera is 0, then you need to check the wiring of the camera or something else. There is no point going beyond this step because you will not be able to get any output from the vOICe.
Getting the screen reader running
Raspberry OS has accessibility built-in. The problem is that the desktop needs a monitor connected before it launches. We are running the pi headless, therefore need to take additional steps to get the desktop running.
- Login into the pi and run the following commands.
sudo apt update
sudo apt upgrade -y
- Run the following command to determine if you can hear through your speakers and or headphones.
aplay /usr/share/sounds/alsa /Noise.wav
If you can here, then do not perform the next step. If you cannot, then continue with the subsequent step.
- Update the firmware of the pi to use a new alsa driver. Run the following program and follow the prompts.
- Repeat the test for the sounds. If you can hear some noise, then continue. If not, troubleshoot
- You need to install a dummy display driver otherwise, the graphical desktop will not launch.
- To install the dummy display driver, run the following command.
sudo apt install xserver-xorg-video-dummy -y
- You now need to add a configuration file so that the desktop uses the driver you have just installed.
sudo nano /etc/X11/xorg.conf
The file should contain the below entries. If the file is not there, then create a fresh file.
# 1920x1080 @ 60.00 Hz (GTF) hsync: 67.08 kHz; pclk: 172.80 MHz
Modeline "1920x1080_60.00" 172.80 1920 2040 2248 2576 1080 1081 1084 1118 -HSync +Vsync
- Save and close the file. If using nano, hit ctrl+x and follow the prompts.
- It is important to test sound once again. If you do not hear any sound, check that audio is set to the 3.5MM jack via raspi-config
- Reboot the pi by issuing the following command.
- The graphical desktop should load and you will hear a prompt to press control plus alt plus space to install orca.
- Hit the ctrl+ + alt + space keystroke on the attached keyboard attached to your pi and follow the prompts. You will need to reboot once orca is installed.
At this point, you will have a pi which will speak to you. The orca screen reader will be active.
Running the vOICe
Launch chromium from the Internet menu and navigate to the following link.
The vOICe web app
Once the page loads, you will need to approve the use of the camera. Hit f6 until you reach the address bar.
Tab until you reach the button labeled “Allow” and activate it.
You should hear the vOICe sounding.
Making the solution future ready
In Linux, it is possible to share the camera. This allows me to add other solutions to the pi such as OCR and run them when the vOICe is running. I am using a virtual loop back device via the v2l4loopback kernel module. The first step is to install this module.
On raspberry OS, this involves building the module manually. This is because as of this writing, it is not present for the very latest build of the kernel.
You must first install one dependency.
sudo apt install ncurses-dev -y
Once you have carried out the above step, you are ready to get the kernel headers. Once again, there is an installation package available but it is usually not updated to the very latest kernels which is why we are following a manual approach.
Please Follow the instructions at the below page.
We are now ready to install v4l2loopback.
Please take the following steps.
- Ensure you are in your home directory by issuing the following command.
- We clone the repository to our pi.
git clone https://github.com/umlaeute/v4l2loopback.git
- You have to build the module and add it to the kernal. Issue the following commands.
make && sudo make install
- If there were no errors, then run the following command.
sudo depmod -a
- Test the installation by running the following command.
If you do not see any errors, then the module has been loaded successfully. If there are errors, then please review the installation instructions.
We now need to make the loop back devices permanent.
I have created two loop back devices but you can create as many or as few as you like.
- We first load the module into memory.
edit the following file by running the below command.
sudo nano /etc/modules
at the end of this file, add the following entry
- We need to specify options for v4l2 loopback. This is done By creating a file named v4l2loopback.conf in the following folder.
- My v4l2loopback.conf file is below.
options v4l2loopback video_nr=25,26 card_label="vOICe","ocr" exclusive_caps=1,1
- Once you have saved this file, run the following command to commit the changes to the pi.
sudo update-initramfs -c -k $(uname -r)
Reboot the pi and check if the right video entries have been created in the folder
Use the following command.
On my raspberry pi, I see video25 and video26 which tells me that the loop back devices I want have been created.
You need to supply data to the loop back devices. I have done this via ffmpeg.
You first must determine which device is which. To do this, run the following command.
Your hardware camera should be usually at /dev/video1 or at /dev/video0
Here is the output of this command when it is run on my raspberry pi.
pi@glasses:~/scripts $ v4l2-ctl --list-device
mmal service 16.1 (platform:bcm2835-v4l2-0):
This means that /dev/video0 is my camera while /dev/video25 and /dev/video26 are my loop back devices.
I need the copying process running whenever I start the pi so I am going to put it into a script. My script is below.
ffmpeg -re -nostdin -i /dev/video0 -f v4l2 /dev/video25 -f v4l2 /dev/video26
I have called the script copy_camera_stream.sh
I have placed it in a sub directory called scripts under the pi user.
This becomes important because I will need to create a systemD unit file to run the script as a service.
Remember, once you have created the script, you must give it executable permission. From within the scripts folder, run the following command.
chmod +x ./copy_camera_stream.sh
Do test the file to ensure that there are no errors.
One way to test it is to use the screen program and run the file from within a screen session. You can then detach from the screen session, relaunch chromium and check the video source combo box of the vOICe web app to see if the video sources are working. Select the source you want to test and check if you hear the soundscapes.
It is time to create the unit file for systemD. This should be placed in the following folder.
The contents of my copycamerastream.service file are below.
Description=Run ffmpeg to copy the pi camera stream to virtual loop back devices
You can launch the service and enable it
sudo service copycamerastream enable
sudo service copycamerastream start
Reboot the pi and check if the vOICe is working.
If yes, then congratulations!