+ 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...
15 odpowiedzi
+ 3
This error means that your command value is "NONE"
Make sure your take_command() functions returns what it is supposed to.
+ 3
Can you please give the code that fix this problem
+ 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
+ 1
Ok wait
+ 1
Thank you so much
0
After this task operator function
0
Where is take_command() function? its the one that likely causes the problem.
0
Take command is named as recognise command
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.
0
Ok I will try
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..
0
Sure mate. Keep coding 😁
0
😊😊😊😊😊😊😊😊😊☺️☺️☺️☺️☺️☺️☺️☺️☺️☺️
- 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
- 2
Maybe if you send me full code i can fix it.