How to get the microphone to record sound with Google Speech recognition on Raspberry Pi 3?

17 Views Asked by At

I am using speech recognition for commands in a robot. However when i run the code, the microphone wont record and nothing I say gets printed. At the same time, every time I rerun the code I have to kill the terminal before the rerun because the code doesn't rerun.

import speech_recognition as sr 
import sounddevice

a = sr.Recognizer()

with sr.Microphone() as source:
    print("say something")
    audio = a.listen(source) #Lyden er recognizeren som hører på mikrofonen
    data = a.recognize_google(audio) #Audio har vår tale, altså data er vår lydfil
    print(data)

The result I get after running the code, despite saying something in the microphone:

say something

The result I get when rerunning the code without killing the terminal:

/bin/python /home/amaliako/PIPPI/AI/Stemmestyring.py

At first, I got a different error where I got the message of a wrong card being used and a lot of other files not being found. So I downloaded sounddevice through Linux and then used import sounddevice in my code. This got rid of the other error messages.

0

There are 0 best solutions below