Вот так работало
def listen():
while True:
data =
stream.read(4000, exception_on_overflow=False)
if (rec.AcceptWaveform(data)) and (len(data) > 0):
answer = json.loads(rec.Result())
print(str('ок'))
if answer["text"]:
yield answer["text"]
if counter == 2:
pyperclip.copy(str(text))
keyboard.send('ctrl+v')
if answer["text"]:
yield answer["text"]
for text in listen():
if text == 'тестирую переменную':
sea()