+ 2

How to fix type error , none type is not iterable ?

When I am making a voice assistant , in the task operator function.... def Task_operator(): Command = take_command() If 'hello' in command: Speak('Hello') Else: Speak('couldn't recognize your voice') Here I am getting error - type error None Type is not iterable.....Can you please say how to fix this ..🙄plssss...

26th Jul 2021, 4:59 AM
Sai Charan Vengala
Sai Charan Vengala - avatar
15 Answers
+ 3
This error means that your command value is "NONE" Make sure your take_command() functions returns what it is supposed to.
26th Jul 2021, 5:05 AM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
+ 3
Can you please give the code that fix this problem
26th Jul 2021, 5:17 AM
Sai Charan Vengala
Sai Charan Vengala - avatar
+ 2
import pyttsx3 import datetime from time import sleep import spepy import speech_recognition as sr listener = sr.Recognizer() assistant_name = 'Jarvis' boss_name = 'Sai Charan' def speak(text): speaker = pyttsx3.init() speaker.say(text) print(text) speaker.runAndWait() def recognize_command(): with sr.Microphone() as source: listener.adjust_for_ambient_noise(source, duration=1) print('Listening...') listener.pause_threshold = 1 audio = listener.listen(source) try: print("Recognizing...") command = listener.recognize_google(audio) print(f"User said: {command}\n") except Exception as e: speak('Unable to Recognize your voice , please repeat it boss') pass def start_up(): speak('Loading Requirements...') speak('Activating Jarvis...') print('(Loading...)') sleep(3) speak('Jarvis is Initialized...') def wish_boss(): hour = int(datetime.datetime.now().hour) if hour >= 0 and hour < 12
26th Jul 2021, 5:30 AM
Sai Charan Vengala
Sai Charan Vengala - avatar
+ 1
Ok wait
26th Jul 2021, 5:20 AM
Sai Charan Vengala
Sai Charan Vengala - avatar
+ 1
Thank you so much
26th Jul 2021, 6:36 AM
Sai Charan Vengala
Sai Charan Vengala - avatar
0
After this task operator function
26th Jul 2021, 5:31 AM
Sai Charan Vengala
Sai Charan Vengala - avatar
0
Where is take_command() function? its the one that likely causes the problem.
26th Jul 2021, 5:34 AM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
0
Take command is named as recognise command
26th Jul 2021, 5:35 AM
Sai Charan Vengala
Sai Charan Vengala - avatar
0
Then in recognize_command() you do not return "command". But in Task_operator() you do commmand=recognize_command(), so your "command" variable ends up unassigned. Try returning your "command" variable in recognize_command() function.
26th Jul 2021, 5:41 AM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
0
Ok I will try
26th Jul 2021, 6:26 AM
Sai Charan Vengala
Sai Charan Vengala - avatar
0
It's working I am following you... If I get any doubt ,, I will try to post...please help at that time... I am beginner of python..
26th Jul 2021, 6:37 AM
Sai Charan Vengala
Sai Charan Vengala - avatar
0
Sure mate. Keep coding 😁
26th Jul 2021, 6:44 AM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
0
😊😊😊😊😊😊😊😊😊☺️☺️☺️☺️☺️☺️☺️☺️☺️☺️
26th Jul 2021, 6:53 AM
Sai Charan Vengala
Sai Charan Vengala - avatar
- 1
Command must be a list, tuple, set, dictionary or string, in other words iterables in python Notice that a function without a return sends None
27th Jul 2021, 3:55 PM
Hansley LOVINCE
Hansley LOVINCE - avatar
- 2
Maybe if you send me full code i can fix it.
26th Jul 2021, 5:19 AM
Aleksei Radchenkov
Aleksei Radchenkov - avatar