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.
Prerequisites
- 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
sudo raspi-config
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.
vcgencmd get_camera
On my raspberry pi, I get the following output.
pi@glasses:~ $ vcgencmd get_camera
supported=1 detected=1
pi@glasses:~ $
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.
raspi-update
- 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.
Section "Monitor"
Identifier "Monitor0"
HorizSync 28.0-80.0
VertRefresh 48.0-75.0
# https://arachnoid.com/modelines/
# 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
EndSection
Section "Device"
Identifier "Card0"
Driver "dummy"
VideoRam 256000
EndSection
Section "Screen"
DefaultDepth 24
Identifier "Screen0"
Device "Card0"
Monitor "Monitor0"
SubSection "Display"
Depth 24
Modes "1920x1080_60.00"
EndSubSection
EndSection
- 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.
sudo reboot
- 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.
RPi-Distro
We are now ready to install v4l2loopback.
Please take the following steps.
- Ensure you are in your home directory by issuing the following command.
cd ~
- 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.
cd v4l2loopback
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.
modprobe v4l2loopback
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
v4l2loopback
- We need to specify options for v4l2 loopback. This is done By creating a file named v4l2loopback.conf in the following folder.
/etc/modprobe.d
- 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.
ls /dev/video*
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.
v4l2-ctl --list-device
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
bcm2835-codec-decode (platform:bcm2835-codec):
/dev/video10
/dev/video11
/dev/video12
bcm2835-isp (platform:bcm2835-isp):
/dev/video13
/dev/video14
/dev/video15
/dev/video16
mmal service 16.1 (platform:bcm2835-v4l2-0):
/dev/video0
vOICe" (platform:v4l2loopback-025):
/dev/video25
"ocr (platform:v4l2loopback-026):
/dev/video26
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.
#!/bin/bash
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.
/etc/systemd/system
The contents of my copycamerastream.service file are below.
[Unit]
Description=Run ffmpeg to copy the pi camera stream to virtual loop back devices
After=network.target
[Service]
ExecStart=/home/pi/scripts/copy_camera_stream.sh
WorkingDirectory=/home/pi/scripts
StandardOutput=inherit
StandardError=inherit
Restart=always
User=pi
[Install]
WantedBy=multi-user.target
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!
Leave a Reply