Reputation: 113
I'm trying to return a value (spoken audio is successfully transcribed) from the following function:
def takeCommand():
model = Model("model")
rec = KaldiRecognizer(model, 16000)
p = pyaudio.PyAudio()
stream = p.open(format=pyaudio.paInt16, channels=1, rate=16000, input=True, frames_per_buffer=8000)
stream.start_stream()
while True:
data = stream.read(4000, exception_on_overflow=False)
if len(data) == 0:
break
if rec.AcceptWaveform(data):
x=json.loads(rec.Result())
print(x["text"])
statement = print(x["text"])
return statement
else:
#print(rec.PartialResult())
pass
#print(rec.FinalResult())
I can successfully see the text being transcribed through
print(x["text"])
However, return is giving me a NoneType error, as follows:
Traceback (most recent call last):
File "jarvis_vosk.py", line 116, in <module>
if "thank you" in statement or "ok bye" in statement or "stop" in statement:
TypeError: argument of type 'NoneType' is not iterable
So the function takeCommand() is empty and I can't understand why the return value isn't being passed on?
Your assistance it greatly appreciated!!
Upvotes: 0
Views: 163
Reputation: 113
Solved it... i just needed to change
statement = print(x["text"])
to take account of the statement being a string.... and not just printing it:
statement = str(x["text"])
Upvotes: 1
Reputation: 690
Here is the problem:
statement = print(x["text"])
return statement
You can try this :)
statement = x["text"]
return statement
Or just
return x["text"]
Upvotes: 2