This is a wrapper of Acephei VOSK , With this, you can add continuous offline speech recognition feature to your application,
NOTE:
SpeechToText
Author: @Biswajit
Version: 1.5
Update:
If you like my work, please donate. Your donations will encourage me to add more features in the future.
NOTE:
- As it works offline the app should be complied with the voice model. It will increase the app size by 30-40Mb.
- The accuracy depends on the voice model. You can train your own voice model. For more details check the models download link below.
- Remember to add RECORD_AUDIO permission.
- Download the required voice model from here.
- Change the file name to a simple one like "model.zip"
- Copy it to the Files folder of your project.
- Now to use that model check the attached example.
SpeechToText
Author: @Biswajit
Version: 1.5
- SpeechToText
- Events:
- Error (message As String)
- FinalResult (text As String)
- MicrophoneBuffer (buffer() As Byte)
- PartialResult (text As String)
- Paused (paused As Boolean)
- ReadyToListen
- ReadyToListenEx new
- ReadyToRead
- Restarted
- Result (text As String)
- Fields:
- sampleRate As Int
Default 16000
- sampleRate As Int
- Functions:
- cancel As Boolean
Cancel microphone recognition. Do not post any new events, simply cancel processing.
Does nothing if recognition is not active.
Return type: @return:true if recognition was actually stopped - FeedExternalBuffer (ExBuffer As Byte()) new
For recognizing the external audio buffer, feed the buffer here.
ExBuffer: The external audio byte buffer. - Initialize (eventName As String, modelPath As String)
Initialize the object.
eventName: The event name prefix.
modelPath: The model folder path. - pause (pause As Boolean)
Pause microphone recognition.
pause: Pass true to pause and false to continue. - prepareAudioFile (audioPath As String, predefinedWords As String)
Prepare the audio file for recognition. On success Eventname_ReadyToRead event will be raised.
Call startReading to start reading the file.
audioPath: Audio file path.
predefinedWords: Add some predefined words/phrase as JSON string. Can be blank. - prepareListenerEx (predefinedWords As String) new
Prepare the listener for external audio buffer. On success Eventname_ReadyToListenEx event will be raised.
Call startListeningEx to start listening.
predefinedWords: Add some predefined words/phrase as JSON string. Can be blank. - prepareMicrophone (predefinedWords As String)
Prepare the microphone for listening. On success Eventname_ReadyToListen event will be raised.
Call startListening to start listening.
predefinedWords: Add some predefined words/phrase as JSON string. Can be blank. - reset
Resets microphone recognizer in a thread, starts microphone recognition over again - shutdown
Shutdown the microphone recognizer and release the recorder.
Call this on activity or service closing event. - startListening (timeout As Int) As Boolean
Starts microphone recognition. After specified timeout listening stops and the
endOfSpeech signals about that. Does nothing if recognition is active.
timeout: timeout in milliseconds to listen. -1 = infinite;
Return type: @return:true if recognition was actually started - startListeningEx As Boolean new
Starts external audio buffer recognition.
Return type: @return:true if recognition was actually started - startReading (timeout As Int) As Boolean
Starts file recognition. After specified timeout listening stops and the
endOfSpeech signals about that. Does nothing if recognition is active.
timeout: timeout in milliseconds to listen. -1 = infinite;
Return type: @return:true if recognition was actually started - stop As Boolean
Stops microphone/file recognition. Listener should receive final result if there is
any. Does nothing if recognition is not active.
Call this on activity or service closing event.
Return type: @return:true if recognition was actually stopped
- cancel As Boolean
- Events:
Update:
- Version 1.1:
- Added audio file to text functionality. (For now only WAV format is supported)
- Added predefined word/phrase detection functionality.
- Merged startListening and startListening2 together. Pass -1 for continuous recognition.
- Version 1.2:
- Added MicrophoneBuffer event where you will receive the microphone audio buffer while using voice recognition.
- Version 1.3:
- Added method to change the sampling rate.
- Version 1.4:
- Fixed the app crashing issue while calling shutdown without stating the recognizer
- Version 1.5:
- Added option to feed external audio buffer. Instead of using the internal audio recorder you can feed external audio buffer from another audio source.
(Check the latest example project) - Updated VOSK and JNA library. (Please delete old dependencies before coping the new ones.)
- Added option to feed external audio buffer. Instead of using the internal audio recorder you can feed external audio buffer from another audio source.
If you like my work, please donate. Your donations will encourage me to add more features in the future.
Last edited: