alphacep / vosk-asterisk

Speech Recognition in Asterisk with Vosk Server
GNU General Public License v2.0
104 stars 41 forks source link

Custom Grammar Support #32

Open joeladria opened 1 year ago

joeladria commented 1 year ago

Any chance grammar loading will be implemented?

https://github.com/alphacep/vosk-asterisk/blob/f5f800cba19cf41ec649d4888d6778f3e4b7aada/res-speech-vosk/res_speech_vosk.c#L121

nshmyrev commented 1 year ago

It should be very easy to send a grammar message to configure the recognizer! Please submit a patch or let us know if you need help implementing it!

joeladria commented 1 year ago

I wish I could help out but my C experience isn't quite at that level unfortunately! I've only found the grammar implementation examples for Python so far... https://github.com/alphacep/vosk-api/blob/master/python/example/test_words.py

joeladria commented 1 year ago

Looking for some feedback, I tried my hand at making it work.

Asterisk res_speech specifies the loading of grammar files which are then named at load time and then unloaded. Does vosk support or implement these grammar files at all?

In my implementation I've simply used the "name" string as input with the array of words to pass to the model in JSON format. Works nicely, but a bit of a hack. What do you think?

https://github.com/joeladria/vosk-asterisk/commit/4d7e05b7288462ab53d1d0024680d561a09b020e

nshmyrev commented 1 year ago

Yup, something like this should work. It needs a bit more love though for full integration.