Hi, I'm new here. Help fix this python code.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DarlinRey
    New Member
    • May 2022
    • 1

    Hi, I'm new here. Help fix this python code.

    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.p y", line 56, in <module>
    query = takecommand().l ower()
    File "D:\alexa.p y", line 37, in takecommand
    with sr.Microphone() as source:
    File "C:\Users\(redacted)\PycharmProject s\pythonProject 8\venv\lib\site-packages\speech _recognition\__ init__.py", line 86, in __init__
    device_info = audio.get_devic e_info_by_index (device_index) if device_index is not None else audio.get_defau lt_input_device _info()
    File "C:\Users\(redacted)\PycharmProject s\pythonProject 8\venv\lib\site-packages\pyaudi o.py", line 949, in get_default_inp ut_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 Edition 2021.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. Please help me complete this project.
    Last edited by zmbd; May 18 '22, 10:37 PM. Reason: [Z{Please use the [CODE/] button to format posted script and formatted text - Please read the FAQ}][Z{Moved thread to thePython forum}][z{redacted user name from paths}]
Working...