May 11, 2020 Replies: 84 A better alternative for offline recognition is available here. With this, you can add speech recognition feature to your application without google speech recognition popup (check attached example), SpeechRecognitionNoUI Author: @Biswajit Version: 1.6 SpeechRecognitionNoUI Events: ReadyForSpeech Called when the endpointer is ready for the user to start speaking. BeginningOfSpeech The user has started to speak. EndOfSpeech The user stops speaking. Error (Msg As String) A network or recognition error occurred. PartialResults (Texts As List) Partial recognition results are available. Results (Texts As List) Recognition results are ready. RmsChanged (RmsValue As Int) The sound level in the audio stream has changed. There is no guarantee that this method will be called. BufferReceived(buffer() As Byte) The purpose of this function is to allow giving feedback to the user regarding the captured audio. There is no guarantee that this method will be called. Functions: NoRecognizerBeep As Boolean Set true if you dont want beep sound before and after speech recognition. Starting from Android 7+ this method will throw an exception if the user set the Do Not Disturb mode, unless your app has requested a special permission with NOTIFICATION_POLICY_ACCESS_SETTINGS. (Check example) Initialize (eventname As String, callback As Object) As Boolean IsInitialized As Boolean IsRecognitionAvailable As Boolean Check if Speech Recognition is available or not StartListening (LANGUAGE As String, PARTIAL_RESULTS As Boolean, PREFER_OFFLINE As Boolean) As String Start listening. LANGUAGE : Recognition language. IETF language tag (as defined by BCP 47), for example "en-US" PARTIAL_RESULTS : indicate whether partial results should be returned by the recognizer as the user speaks. PREFER_OFFLINE : indicate whether to only use an offline speech recognition engine. If false then either network or offline recognition engines may be used StopListening As String Here is the original thread. I took some ideas and codes to build this library. Note: Remember to INTERNET, RECORD_AUDIO and NOTIFICATION_POLICY_ACCESS_SETTINGS permission. For SDK v30: Add this following code to your project manifest. B4X: Copy AddManifestText( <queries> <intent> <action android:name="android.speech.RecognitionService" /> </intent> </queries>) Update 1.1: Added NoRecognizerBeep option. Set true if you don't want beep sound before and after speech recognition. Update 1.2: Added ReadyForSpeech event. Fixed recognition language problem Update 1.3: Fixed crashing issue in DND mode. Update 1.4: Added proper error handling and warning message for DND mode. (Check the example) Update 1.5: Added BufferReceived event. Update 1.6: Fixed an issue with the offline voice recognition. Attachments SpeechRecognitionNoUI_example.zip SpeechRecognitionNoUI_example.zip 10.5 KB · Views: 2,496 SpeechRecognitionNoUI_v1.6.zip SpeechRecognitionNoUI_v1.6.zip 7.5 KB · Views: 1,804 Last edited: Oct 5, 2021 Click to expand...
A better alternative for offline recognition is available here. With this, you can add speech recognition feature to your application without google speech recognition popup (check attached example), SpeechRecognitionNoUI Author: @Biswajit Version: 1.6 SpeechRecognitionNoUI Events: ReadyForSpeech Called when the endpointer is ready for the user to start speaking. BeginningOfSpeech The user has started to speak. EndOfSpeech The user stops speaking. Error (Msg As String) A network or recognition error occurred. PartialResults (Texts As List) Partial recognition results are available. Results (Texts As List) Recognition results are ready. RmsChanged (RmsValue As Int) The sound level in the audio stream has changed. There is no guarantee that this method will be called. BufferReceived(buffer() As Byte) The purpose of this function is to allow giving feedback to the user regarding the captured audio. There is no guarantee that this method will be called. Functions: NoRecognizerBeep As Boolean Set true if you dont want beep sound before and after speech recognition. Starting from Android 7+ this method will throw an exception if the user set the Do Not Disturb mode, unless your app has requested a special permission with NOTIFICATION_POLICY_ACCESS_SETTINGS. (Check example) Initialize (eventname As String, callback As Object) As Boolean IsInitialized As Boolean IsRecognitionAvailable As Boolean Check if Speech Recognition is available or not StartListening (LANGUAGE As String, PARTIAL_RESULTS As Boolean, PREFER_OFFLINE As Boolean) As String Start listening. LANGUAGE : Recognition language. IETF language tag (as defined by BCP 47), for example "en-US" PARTIAL_RESULTS : indicate whether partial results should be returned by the recognizer as the user speaks. PREFER_OFFLINE : indicate whether to only use an offline speech recognition engine. If false then either network or offline recognition engines may be used StopListening As String Here is the original thread. I took some ideas and codes to build this library. Note: Remember to INTERNET, RECORD_AUDIO and NOTIFICATION_POLICY_ACCESS_SETTINGS permission. For SDK v30: Add this following code to your project manifest. B4X: Copy AddManifestText( <queries> <intent> <action android:name="android.speech.RecognitionService" /> </intent> </queries>) Update 1.1: Added NoRecognizerBeep option. Set true if you don't want beep sound before and after speech recognition. Update 1.2: Added ReadyForSpeech event. Fixed recognition language problem Update 1.3: Fixed crashing issue in DND mode. Update 1.4: Added proper error handling and warning message for DND mode. (Check the example) Update 1.5: Added BufferReceived event. Update 1.6: Fixed an issue with the offline voice recognition.
C Cesaral Member Jan 22, 2023 #81 I have tested the App and the library and they work well except that the Sub sr_PartialResults(Texts As List) is never called and I need it... What could be the cause? Would it be possible to have the source code of this library to investigate the cause? Thanks!
I have tested the App and the library and they work well except that the Sub sr_PartialResults(Texts As List) is never called and I need it... What could be the cause? Would it be possible to have the source code of this library to investigate the cause? Thanks!
Biswajit Active Member Licensed User Longtime User Jan 22, 2023 #82 Cesaral said: I have tested the App and the library and they work well except that the Sub sr_PartialResults(Texts As List) is never called and I need it... What could be the cause? Would it be possible to have the source code of this library to investigate the cause? Thanks! Click to expand... It's not related to the library source code. The event will be triggered by the system. Try to set partial_result = true when calling StartListening or try on another device once.
Cesaral said: I have tested the App and the library and they work well except that the Sub sr_PartialResults(Texts As List) is never called and I need it... What could be the cause? Would it be possible to have the source code of this library to investigate the cause? Thanks! Click to expand... It's not related to the library source code. The event will be triggered by the system. Try to set partial_result = true when calling StartListening or try on another device once.
C Cesaral Member Jan 22, 2023 #83 Biswajit said: It's not related to the library source code. The event will be triggered by the system. Try to set partial_result = true when calling StartListening or try on another device once. Click to expand... Yes, I already did that with: StartListening("en_US", true, false) But it does not give partial results. Thanks
Biswajit said: It's not related to the library source code. The event will be triggered by the system. Try to set partial_result = true when calling StartListening or try on another device once. Click to expand... Yes, I already did that with: StartListening("en_US", true, false) But it does not give partial results. Thanks
Biswajit Active Member Licensed User Longtime User Nov 21, 2024 #84 hesam98 said: dear Biswajit farsi : sr.StartListening("fa",True,False) does not work and return english , thank you for helping Click to expand... You must also mention the region and the language code, like fa-IR. Also, check whether the language model is downloaded in your device for this specific language or not. You can find the language code here, https://simplelocalize.io/data/locales/
hesam98 said: dear Biswajit farsi : sr.StartListening("fa",True,False) does not work and return english , thank you for helping Click to expand... You must also mention the region and the language code, like fa-IR. Also, check whether the language model is downloaded in your device for this specific language or not. You can find the language code here, https://simplelocalize.io/data/locales/
Nerdworld Member Licensed User Longtime User Jan 22, 2025 #85 Just a quick addition: the correct signature for the RmsChanged event is "RmsChanged(RmsValue as Float"), not int. Thanks for this great library!
Just a quick addition: the correct signature for the RmsChanged event is "RmsChanged(RmsValue as Float"), not int. Thanks for this great library!