0

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!!

asked Jan 16, 2021 at 22:11

2 Answers 2

2

Here is the problem:

statement = print(x["text"])
return statement

You can try this :)

statement = x["text"]
return statement

Or just

return x["text"]
answered Jan 16, 2021 at 22:14
Sign up to request clarification or add additional context in comments.

Comments

1

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"])

answered Jan 16, 2021 at 22:15

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.