0

I'm using PyAudio to make a speech recognition application with the SpeechRecognition library in Python 3.9.6, but when I try and execute the takeCommand function it gives me this error:

Traceback (most recent call last):
  File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1892, in __call__
    return self.func(*args)
  File "c:\Users\trevo\Google Drive\OmniPhi - TetraSystemSolutions\src\MainProgram\OmniMain.py", line 56, in activateOmni
    querycommand = om.takeCommand()
  File "c:\Users\trevo\Google Drive\OmniPhi - TetraSystemSolutions\src\MainProgram\OmniBot.py", line 24, in takeCommand
    with sr.Microphone() as source:
  File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\site-packages\speech_recognition\__init__.py", line 86, in __init__
    device_info = audio.get_device_info_by_index(device_index) if device_index is not None else audio.get_default_input_device_info()
  File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\site-packages\pyaudio.py", line 949, in get_default_input_device_info
    device_index = pa.get_default_input_device()
OSError: No Default Input Device Available

I wasn't able to find a whole lot on the problem I was having specifically. I have tried looking on posts such as <https://stackoverflow.com/questions/53058689/oserror-no-default-input-device-available> and <https://stackoverflow.com/questions/59013743/oserror-no-default-input-device-available-on-google-colab> but the former is related to Linux and not related to Windows and the latter is related to Google Collaboratory. I have also tried using other methods like getting the microphone device by using a function but that has failed as well.

Here is the main code with the two scripts, one with the takeCommand inside of itself and the other with the main class named OmniPhi:

import wolframalpha as wolf
import wikipedia as wiki
import pyttsx3
import speech_recognition as sr
from tkinter import *
import time
from OmniSecondMain import *


engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)



        

def omnispeak(audio):
    engine.say(audio)
    engine.runAndWait()

def takeCommand(ask=False):
    r = sr.Recognizer()
    with sr.Microphone() as source:
        if ask:
            gaiaspeak(ask)
        print('Say something')
        sr.adjust_for_ambient_noise(source)
        audio = r.listen(source)
        voice_data = ''
    try:
        voice_data = r.recognize_google(audio)
    except sr.UnknownValueError:
        print('Sorry, i did not get that.')
    except sr.RequestError:
        print('Sorry, my services are down.')
    return voice_data 

script 2: OmniMain.py

from tkinter import *
from tkinter.font import Font
import tkinter as tk
from tkinter import ttk
import os
import sys
import sqlite3 as sq
from PIL import ImageTk, Image
import wolframalpha as wolf
import OmniBot as om
import time




class OmniPhi(tk.Tk):
    def __init__(self):
        super().__init__()
        
        self.title('Welcome to OmniPhi!')
        self.geometry('1280x700')
        self.topFrame = tk.Frame(self, bg='#303098')
        self.topFrame.place(x=0, y=0)
        self.topFrame.config(height=700, width=1280)
        userText=tk.StringVar()
        
        userText.set('Weclome to Omni! your personal labratory assistant.')
        self.userFrame = Message(self, textvariable=userText, bg='#303098', fg='white')
        self.userFrame.config(font=("Century Gothic", 24, 'bold'))
        self.userFrame.place(x=500, y=200)
        self.startButton = tk.Button(self, text='Start Omni', bg='#303098', fg='white', font=('Century Gothic', 12, 'bold'), bd=0, command=self.activateOmni)
        self.startButton.place(x=600, y=500)
        self.loadButton = Button(self, text='Load Experiment File', bg='#303098', fg='white', font=('Century Gothic', 12, 'bold'), bd=0)
        self.loadButton.place(x=560, y=530)
        self.quitButton = Button(self, text='Quit', bg='#303098', fg='white', font=('Century Gothic', 12, 'bold'), bd=0)
        self.quitButton.place(x=625, y=560)
        #self.title = 'database'
        #self.create_database(self.title)
    def create_database(self, title):
        conn = sq.connect(title)
        c = conn.cursor()
        #c.execute("""CREATE TABLE""")

    def om_introduction(self):
        om.omnispeak(self, 'Hello my name is Omni! I will be your personal science testing robot, Lets get started.')
        qt = GaiaText(self)
        qt.pack(side='top', fill='both', expand=True)
        self.protocol("WM_DELETE_WINDOW", qt.onClosing)

   
        
    
    def activateOmni(self):
        om.omnispeak('Hello, I am Omni a robot who can test science experiments.')
        querycommand = om.takeCommand()
        
        #master = tk.Tk()
        #qt = om.GaiaText(master)
        #qt.pack(side='top', fill='both', expand=True)
        #self.protocol("WM_DELETE_WINDOW", qt.onClosing)
        #master.mainloop()

if __name__ == '__main__':
    phi = OmniPhi()
    phi.mainloop()

Any help would be greatly appreciated!

KronosHedronos2077
  • 884
  • 1
  • 5
  • 13

0 Answers0