1

I'm creating a voice recognition system using Raspberry Pi 3 using Python and taking inputs (voice commands and audio sounds) through a microphone. I have been able to get voice input using the following code:

#Python 2.x program to transcribe an Audio file
import speech_recognition as sr
import os
import subprocess

print "Say something..."
subprocess.call(['arecord','-D','plughw:1,0','-d','5','myvoice.wav'],shell=False)
AUDIO_FILE = ("myvoice.wav")

# use the audio file as the audio source

r=sr.Recognizer()

with sr.AudioFile(AUDIO_FILE) as source:
   #reads the audio file. Here we use record instead of
   #listen
   audio=r.record(source)

try:
    print("The audio file contains:" + r.recognize_google(audio))
    if r.recognize_google(audio)=="open browser" or r.recognize_google(audio)=="Browser":
      subprocess.call(['chromium-browser'],shell=False)
    if r.recognize_google(audio)=="open incognito" or r.recognize_google(audio)=="go Incognito":
      subprocess.call(['chromium-browser','--incognito'],shell=False)
 except sr.UnknownValueError:
    print("Google Speech Recognition could not understand audio")

except sr.RequestError as e:
    print("Could not request result from Google Speech Recognition service; {0}".format(e))

The above code is for human speech. I'm trying to take input for audio samples of fire alarm and water leakages. I have the audio samples of fire alarm and water leakages downloaded from YouTube as .mp3 files and I will be storing these files in my Raspberry Pi. The objective is to play the audio sample to my microphone and if it matches with the audio sample stored in my system then it should send a notification to me via PushOver App (already have the codes to send a notification).
Sorry for the poor english as it is not my 1st language :D

migrated from askubuntu.com Apr 20 '18 at 8:23

This question came from our site for Ubuntu users and developers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy