This kind of error throwing AttributeError enter

0 votes

Traceback (most recent call last):
  File "c:/Users/User/Downloads/pyth/pm.py", line 49, in <module>
    takecommand()
  File "c:/Users/User/Downloads/pyth/pm.py", line 31, in takecommand
    with sr.Microphone as source:
AttributeError: __enter_
_

Plzzz Help to solve this error

Jul 5, 2020 in Python by APT
• 120 points
7,907 views

Hii  APT,

 Can you please provide more Information or paste your snippet here.

2 answers to this question.

0 votes

Hi, @APT,

You need to implement __enter__ in your class and return self in it. Could you please provide your code snippet so that we can dig further with your query. 

answered Jul 6, 2020 by Gitika
• 65,770 points
import pyttsx3

import speech_recognition as sr

import pyaudio

import datetime

import wikipedia

import webbrowser

engine = pyttsx3.init('sapi5')

voices = engine.getProperty('voices')

# print(voices[0].id)

engine.setProperty('voices', voices[0].id)

def speak(audio):

    engine.say(audio)

    engine.runAndWait()

def wishMe():

    hour =int(datetime.datetime.now().hour)

    if hour>=0 and hour<12:

        speak("Good Morning!")

    elif hour<12 and hour>18:

        speak("Good evening!")

    else:

        speak("Good afternoon!")

speak("lokesh, I am Jarvis, your assistant, I am ready, how may I help you?")

def takecommand():

    #it takes microphone input from the user and returns string output

    r = sr.Recognizer()

    with sr.Microphone as source:

        print("listening....")

        r.pause_threshold = 1

        audio = r.listen(source)

        try:

            print("recognising......")

            query = r.recognize_google(audio, language='en-in')

            print(f"user said: {query}/n")

        except Exception as e:

    # print(e)

            print("say that again please......")

            return "none"

            return query

if __name__ == '__main__':

    wishMe()

    while True:

        query = takecommand().lower()

        #logic on executive tasks based on queries

        if "wikipedia" in query:

            speak('searching wikipedia.......')

            query = query.replace("wikipedia","")

            results = wikipedia.summary(query, sentences=2)

            speak("according to wikipedia")

            print(results)

            speak(results)

        elif "open youtube" in query:

            webbrowser.open("youtube.com")

the above code when run shows an error:

Traceback (most recent call last):

  File "c:\Users\sonu\Desktop\New folder\jarvis.py", line 54, in <module>

    query = takecommand().lower()

  File "c:\Users\sonu\Desktop\New folder\jarvis.py", line 35, in takecommand

    with sr.Microphone as source:

AttributeError: __enter__

please tell me its solution..........

Hi, @Lokesh,

I guess you need to implement __enter__ in your class and return self in it.

+2 votes

I had recently found its solution and the solution is:

in case of this:

with sr.Microphone as source:

you should write this:

with sr.Microphone() as source:

the thing to do is just you have to add () after sr.microphone.

hope it works......

answered Jul 31, 2020 by lokesh
Hi @lokesh, thank you for your contribution to the Edureka Community.

Register/Sign up on the community to gain points for further contributions. You may ask questions, answer, comment, upvote, and downvote an answer. Each of these would fetch you points and you could be among the top contributors and win exciting merchandise from Edureka.

Cheers!

Related Questions In Python

+1 vote
1 answer
0 votes
1 answer

Getting this error Error sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type

Found out that the problem was that ...READ MORE

answered Oct 1, 2018 in Python by Priyaj
• 58,020 points
12,413 views
0 votes
1 answer

Using Python what kind of applications can be built?

http://en.wikipedia.org/wiki/List_of_Python_software  follow the link and You will see ...READ MORE

answered Nov 14, 2018 in Python by Theodor
• 740 points
839 views
+2 votes
10 answers

How to fix this? ValueError: invalid literal for int() with base 10 error in Python

The following are totally acceptable in python: passing ...READ MORE

answered Nov 16, 2018 in Python by Nymeria
• 3,560 points
409,222 views
0 votes
1 answer

Getting AttributeError: 'module' object (scipy) has no attribute 'misc' in Python. How to solve this?

>>> import scipy >>> scipy.misc Traceback (most recent call ...READ MORE

answered Dec 24, 2018 in Python by Nymeria
• 3,560 points
9,433 views
0 votes
2 answers

Python Pandas error: AttributeError: 'DataFrame' object has no attribute 'rows'

Try this: data=pd.read_csv('/your file name', delim_whitespace=Tru ...READ MORE

answered Dec 10, 2020 in Python by anonymous
• 82,840 points
132,572 views
0 votes
3 answers

TypeError: Index(...) must be called with a collection of some kind, 'Email' was passed

It is not working because your code ...READ MORE

answered May 13, 2020 in Python by anonymous

edited May 13, 2020 by Gitika 54,055 views
0 votes
1 answer
0 votes
1 answer

Python error "AttributeError: incompatible shape for a non-contiguous array"

It is not always possible to change ...READ MORE

answered May 29, 2019 in Python by Imran
2,050 views
0 votes
1 answer

Python error saying "AttributeError: can't set attribute"

change your code to the following: @x.setter def x(self, ...READ MORE

answered May 30, 2019 in Python by Imran
19,015 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP