You are going to need an internet connection, an OS, (I suggest Raspbian) and a microphone.
The first step is to get the microphone set-up. Start by opening a terminal window and running lusb. This lists all of the USB devices connected to the Pi and the microphone should show up.
Next the volume for the mic needs to be set to high, so run alsamixer. You will see a GUI interface pop-up, select your mic by pressing F6 and choosing it from the list. Use the up arrow key to increase the volume. (You can always go back and change the volume at a later date by following this set of insturctions again).
With the mic set-up we are going to need some voice recognition software, I'm going to outline the steps to install some software that uses Google's API. So, it should be fairly accurate.
wget --no-check-certificate “https://doc-0c-2o-docs.googleusercontent.com/docs/securesc/ha0ro937gcuc7l7deffksulhg5h7mbp1/icp2b3rhg6kd6a8prrnb26rt0nk03vme/1496138400000/08464976839983055227/*/0B0nujpNS8bIxUFJpWXIzd19CXzg?e=download” -O PiAUISuite.tar.gz
tar -xvzf PiAUISuite.tar.gz
cd PiAUISuite/Install/
sudo ./InstallAUISuite.sh
The commands above need to run one after the other in that order. (Don't start the next one running until the one before it has finished).
There are lots of different options during the installation process. For more information on those see here.
The software is set continuously running, if the following command is executed:
sudo voicecommand -c
The keyword for activating it is Pi, I suggest changing it to something more distinct as Pi sounds very similar to hi. To fix this run:
voicecommand -e
You will see an option in there for changing the keyword.
There are some voice commands in the file by default, you can however add your own:
Check internet==ping google.com
The section of code before the == is the voice command, the section of code after the == is the action the Pi will perform upon hearing the voice command. In the example above saying check internet will cause the Pi to ping google.com.
This is the bit where you can get really creative and setup different commands for various voice commands.
Edit 1:
Running voicecommand -e or sudo voicecommand -e might give an empty file. In which case edit the file so it contains the following:
#This is the default config file
#These are the special options you can set (remove the #)
#!verify==1
#!keyword==pi
#!thresh==0.7
#!continuous==1
#!response==Yes Sir?
#!quiet==0
#!ignore==0
#!filler==0
#!duration==2
#!com_dur==3
#!hardware==plughw:1,0
#Here are the commands:
Check internet==ping google.com
Below #here are the commands: I have included an example voice command, you can add your own voice commands below the example one.
Edit 2:
The method I listed above is just one way of implementing voice control. For Python there is the SpeakPython library. The person who created has confirmed that it works well on the Pi.
Alternatively there is the SpeechRecognition library which was developed by Python. You can find lots of example pieces of code and tutorials on the site I have linked above. However, I'll post one of the example pieces of code here just to give you an idea:
#!/usr/bin/env python3
# NOTE: this example requires PyAudio because it uses the Microphone class
import speech_recognition as sr
# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
print("Say something!")
audio = r.listen(source)
# recognize speech using Sphinx
try:
print("Sphinx thinks you said " + r.recognize_sphinx(audio))
except sr.UnknownValueError:
print("Sphinx could not understand audio")
except sr.RequestError as e:
print("Sphinx error; {0}".format(e))
# recognize speech using Google Speech Recognition
try:
# for testing purposes, we're just using the default API key
# to use another API key, use `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`
# instead of `r.recognize_google(audio)`
print("Google Speech Recognition thinks you said " + r.recognize_google(audio))
except sr.UnknownValueError:
print("Google Speech Recognition could not understand audio")
except sr.RequestError as e:
print("Could not request results from Google Speech Recognition service; {0}".format(e))