473,287 Members | 1,613 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

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.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

Expand|Select|Wrap|Line Numbers
  1. import pyttsx3
  2. import datetime
  3. import speech_recognition as sr
  4. import wikipedia
  5. import webbrowser
  6. import os.path
  7.  
  8.  
  9.  
  10. engine = pyttsx3.init('sapi5')
  11. voices = engine.getProperty('voices')
  12. engine.setProperty('voice',voices[1].id)
  13.  
  14.  
  15.  
  16. def speak(audio):
  17.     engine.say(audio)
  18.  
  19.  
  20.  
  21. def wishme():
  22.     hour = int(datetime.datetime.now().hour)
  23.     if hour>=0 and hour<12:
  24.         speak('Доброе утро')
  25.  
  26.     elif hour>12 and hour<18:
  27.         speak('Добрый день')
  28.  
  29.     else:
  30.         speak('Добрый вечер')
  31.  
  32.     speak(' Я Алекса, ваш голосовой помощник. Теперь многие вещи проще делать говоря со мной ')
  33.  
  34.  
  35. def takecommand():
  36.     r = sr.Recognizer()
  37.     with sr.Microphone() as source:
  38.         print('Слушаю...')
  39.         r.pause_threshold = 2
  40.         audio = r.listen(source)
  41.  
  42.  
  43.     try:
  44.         print('Распознование...')
  45.         query = r.recognize_google(audio,language = 'en-in')
  46.         print(f'User said: {query}\n')
  47.  
  48.     except Exception as e :
  49.         print('Повторите это снова пожалуйста...')
  50.         return 'Ничего'
  51.     return query
  52.  
  53. if __name__ == '__main__' :
  54.     wishme()
  55.     while True:
  56.         query = takecommand().lower()
  57.  
  58.  
  59.  
  60.         if 'википедия' in query :
  61.             speak('Поиск в Википедии....')
  62.             query = query.replace('википедия','')
  63.             results = wikipedia.summary(query, sentences = 5)
  64.             print(results)
  65.             speak(results)
  66.  
  67.         elif 'открой ютуб' in query :
  68.             webbrowser.open('youtube.com')
  69.  
  70.         elif 'открой гугл' in query :
  71.             webbrowser.open('google.com')
  72.  
  73.         elif 'открой вконтакте' in query:
  74.             webbrowser.open('vk.com')
  75.  
  76.         elif 'открой почту' in query:
  77.             webbrowser.open('mail.ru')
  78.  
  79.         elif 'время' in query :
  80.             strtime = datetime.datetime.now().strftime('%H:%M:%S')
  81.             speak(f'сейчас {strtime}')
  82.  
  83.         elif 'пайчарм' in query :
  84.             codepath = 'C:\Program Files\JetBrains\PyCharm Community Edition 2021.3.2\bin\pycharm64'
  85.             os.startfile(codepath)
  86.  
  87.         elif 'выход' in query:
  88.             speak('хорошо, пожалуйста позовите меня если вам понадобиться моя помощь')
  89.             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.
May 18 '22 #1
0 6008

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Aurélien Géron | last post by:
Hi, Does anyone know where I can find a lot of Python code snippets? I searched the Python wiki and Internet but could not find more than five or ten code snippets at a time. I'm looking...
0
by: Chris McKeever | last post by:
I am trying to modify the Mailman Python code to stop mapping MIME-types and use the extension of the attachment instead. I am pretty much clueless as to what I need to do here, but I think I have...
11
by: Brett C. | last post by:
For my thesis (once the bloody thing stops throwing bugs at me) I am going to need to collect stats on the frequency that atomic types in local variables are applied to various opcodes and methods....
9
by: F. GEIGER | last post by:
I've dev'ed a Python prototype of an app, that besides the internals making it up has a gui. While test-driven dev'ing the app's internals in Python is fun as usual, dev'ing the GUI is not so...
7
by: Hansan | last post by:
Hi all, I hope you have time to help me out a little. My problem is that I want to combine some python code I have made with some html templates, I found a tutorial at dev shed:...
6
by: planetthoughtful | last post by:
Hi All, I've written my first piece of practical Python code (included below), and would appreciate some comments. My situation was that I had a directory with a number of subdirectories that...
2
by: Andreas Røsdal | last post by:
Hi, I'm using the Python profiler to optimize a pathfinding algorithm of a game, and would like some help from someone who knows how to improve the performance of Python code. The algorithm is...
10
by: John Salerno | last post by:
Is it possible to construct a C# form (using Visual Studio) but write only Python code for the events? Is there some way to tell your program to run Python whenever code is run, since it will be...
64
by: Bayazee | last post by:
hi can we hide a python code ? if i want to write a commercial software can i hide my source code from users access ? we can conver it to pyc but this file can decompiled ... so ...!! do you...
2
by: Bo | last post by:
I want to port a Python project (about 10,000 line python code) to C+ +. Is there any automatically tool to do this kind of things? e.g., SWIG(http://www.swig.org/)? Any comment is welcome! ...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.