If you want your own Jarvis from Ironman the first step is to have a computer that can listen to what you say and then talk back to you. The software for that is the hard part but with some AI and RNNs we can get some pretty good functionality. That comes later, so let's first start up with the microphone and audio. I am using a Raspberry Pi 3 and will now set these peripherals up.
Microphone
I bought a basic
USB microphone that cost me an outrageous $4.50. After plugging it into the Raspberry Pi, we can test and use it. First we see that it is there with:
pi@pi3:~ $ arecord -l
**** List of CAPTURE Hardware Devices ****
card 1: Device [USB PnP Sound Device], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0
To record something we will use this command to record 3 seconds of audio and take the input from the -D device plughw:1,0
arecord -D plughw:1,0 -d 3 test.wav
This will output the test.wav file. This file can now be played back when we setup our bluetooth speaker.
Bluetooth Speaker
My
bluetooth speaker was a pretty cool model I bought for tunes while working out. Turning it on and making sure its not connected to anything else I logged into the Raspberry Pi and entered the command:
sudo bluetoothctl
I then entered the 'scan on' command (but didn't have to) and a bunch of devices showed up. I picked the one I wanted and got its mac address:
32:D9:46:EE:D3:AF
I then ran the commands:
pair 32:D9:46:EE:D3:AF
connect 32:D9:46:EE:D3:AF
exit
The speaker then showed connected. Now we know its there let's try to set the system to use it. Running the command:
alsamixer -D bluealsa
We get:

This is great because it shows the speaker is connected and ready to work. Now we can play the wav file through this bluetooth speaker. The default audio of the Raspberry Pi is set to play out of the analog jack. So if we run:
aplay test.wav
It doesn't play anything. Changing the command we can specify the device to play through:
aplay -D bluealsa:HCI=hci0,DEV=32:D9:46:EE:D3:AF,PROFILE=a2dp test.wav
Here the mac address shown below is the mac address of the bluetooth device. It plays but it is really staticy, so the recording isn't may favorite. To determine if its the microphone or the audio we simply play another file:
aplay -D bluealsa:HCI=hci0,DEV=32:D9:46:EE:D3:AF,PROFILE=a2dp voice/foo.wav
We can simplify this device configuration by adding it to the /usr/share/alsa/alsa.conf.d/20-bluealsa.conf. We add the following at the end:
pcm.oontz {
type plug
slave.pcm {
type bluealsa
device "32:D9:46:EE:D3:AF"
profile "a2dp"
}
hint {
show on
description "OONTZ Angle 3 3AF"
}
}
In the above I've just named my device "oontz" and put in my own MAC address of the device as well as a description. Everything else should be the same for your setup. Then we can run:
aplay -D oontz voice/foo.wav
Now, to make this the default we can add a similar entry to the ~/.asoundrc file. Mine looks like this:
pcm.!default {
type plug
slave.pcm {
type bluealsa
device "32:D9:46:EE:D3:AF"
profile "a2dp"
}
}
It is similar to the previous entry, but we have named it pcm.!default. Now when we play the wav file it will use this as the default:
aplay voice/foo.wav
mplayer voice/foo.wav
Cool. Default sound setup for bluetooth. Persistent reconnect will be the next topic!