alphacep / vosk-api

Offline speech recognition API for Android, iOS, Raspberry Pi and servers with Python, Java, C# and Node
Apache License 2.0
7.92k stars 1.1k forks source link

Modify for recognizing specific word #975

Open miziworld opened 2 years ago

miziworld commented 2 years ago

Hello, Your api is very useful. But I want to add a few more features, can you help?

  1. I want to print only when a specific word is recognized. For example, when the user says "red blue apple", I want to output the resulting text only when "blue" is included. ex) speak : red result : (nothing) speak : blue result : blue speak: red blue apple result: blue I am currently using test_microphone.py of the python example, and looking inside the code, the part that outputs the result seems to be the print(rec.Result()) part. Could you please tell me how to fix it?
nshmyrev commented 2 years ago

What is the specific usecase you have? Is it a homework?

miziworld commented 2 years ago

No, just for my personal experiment. I'll use this function on my robot or some devices that using the microphone on offline environment. Is it impossible to modify vosk-api for implementing that function...?

nshmyrev commented 2 years ago

You have to modify your code,not vosk api for that, like this:

result = json.loads(rec.Result())['text']
if "blue" in result:
     print ("blue")