473,387 Members | 1,540 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,387 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 6029

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! ...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.