0

I am working on a project to create a voice assistant using Python 3.10 in pycharm. When the program starts, an error appears:

Traceback (most recent call last):
File "D:\alexa.py", line 56, in <module>
query = takecommand().lower()
File "D:\alexa.py", line 37, in takecommand
with sr.Microphone() as source:
File "C:\Users\(redacted)\PycharmProjects\pythonProject8\venv\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\(redacted)\PycharmProjects\pythonProject8\venv\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

Process finished with exit code 1

Code:

import pyttsx3
import datetime
import speech_recognition as sr
import wikipedia
import webbrowser
import os.path



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



def speak(audio):
    engine.say(audio)



def wishme():
    hour = int(datetime.datetime.now().hour)
    if hour>=0 and hour<12:
        speak('Доброе утро')

    elif hour>12 and hour<18:
        speak('Добрый день')

    else:
        speak('Добрый вечер')

    speak(' Я Алекса, ваш голосовой помощник. Теперь многие вещи проще делать говоря со мной ')


def takecommand():
    r = sr.Recognizer()
    with sr.Microphone() as source:
        print('Слушаю...')
        r.pause_threshold = 2
        audio = r.listen(source)


try:
    print('Распознование...')
    query = r.recognize_google(audio,language = 'en-in')
    print(f'User said: {query}\n')

except Exception as e :
    print('Повторите это снова пожалуйста...')
    return 'Ничего'
return query

if __name__ == '__main__' :
    wishme()
    while True:
        query = takecommand().lower()



    if 'википедия' in query :
        speak('Поиск в Википедии....')
        query = query.replace('википедия','')
        results = wikipedia.summary(query, sentences = 5)
        print(results)
        speak(results)

    elif 'открой ютуб' in query :
        webbrowser.open('youtube.com')

    elif 'открой гугл' in query :
        webbrowser.open('google.com')

    elif 'открой вконтакте' in query:
        webbrowser.open('vk.com')

    elif 'открой почту' in query:
        webbrowser.open('mail.ru')

    elif 'время' in query :
        strtime = datetime.datetime.now().strftime('%H:%M:%S')
        speak(f'сейчас {strtime}')

    elif 'пайчарм' in query :
         codepath = 'C:\Program Files\JetBrains\PyCharm Community 
 Edition2021.3.2\bin\pycharm64'
        os.startfile(codepath)

    elif 'выход' in query:
        speak('хорошо, пожалуйста позовите меня если вам понадобиться моя помощь')
        quit()

I tried to fix the mistake, but nothing comes out. It's only clear to me that there is no default device available, but I still don't understand how to fix it, given that there is not only this error. What can I try next?

halfer
  • 19,824
  • 17
  • 99
  • 186
DarlinRey
  • 1
  • 1

1 Answers1

0

First take a look at this solution. And also (not sure about this) check if you have an audio device (like a microphone) installed and then check that device's driver is installed correctly.

Mohammad Alavi
  • 912
  • 1
  • 6
  • 16