1

I am using Ubuntu 20. I typed sudo nano /usr/share/alsa/alsa.conf and got the following output: output of the above command I don't know if there is something wrong with it, but whenever I try to run a speech recognition program in Python from Pycharm, I get the following errors: errors while running the code

My code is as follows:

import wikipedia
import speech_recognition as sr
import tkinter.messagebox
n=0
window= tkinter.Tk()
while True:
    r = sr.Recognizer()
    with sr.Microphone() as source:
        print('Speak Anything...')
        audio = r.listen(source)

        try:
            text = r.recognize_google(audio,language= 'En', show_all=True)
            if text=="Stop":
                break
            else:
                window.geometry("700x600")
                answer = wikipedia.summary(text)
                label1 = window.Label(window, justify="LEFT",compound="CENTER",padx=10,text=answer, font='times 15 bold')
                label1.pack()
                window.after(50000, lambda: window.destroy())
                window.mainloop()
        finally:
            answer = 'Sorry we cannot hear you.'
            print(answer)
vitaliis
  • 4,082
  • 5
  • 18
  • 40

1 Answers1

0

Even with these errors, the code works just fine. The problem is that its a bit too slow. I made some minor changes to the code. So, here's the code that worked:

import wikipedia
from tkinter import *
import speech_recognition as sr

while True:
    r = sr.Recognizer()
    with sr.Microphone() as source:
        print("Listening.....")
        audio = r.listen(source)
        try:
            print("Recognizing....")
            text = r.recognize_google(audio)
            print('You said: ' + text)
            if text == "stop":
                print("Program will exit.")
                break
            else:
                window = Tk()
                window.geometry("700x600")
                answer = wikipedia.summary(text, sentences = 5)
                print("Answer from Wikipedia:")
                print(answer)
                label1 = Label(window, justify=LEFT, wraplength=650, compound=CENTER, padx=10, text=answer, font='times 15 bold')
                label1.pack()
                window.after(500000, lambda: window.destroy())
                mainloop()

        except Exception as e:
            print(e)
            answer = "Sorry we can't hear you"
            print(answer)

Thank you!!:)