iOS Question offline iSpeechRecognition

Mike1970

Well-Known Member
Licensed User
Longtime User
Hi everyone, i'm programming an app where could be cool to support voice to text functionality.
I read (and noticed) that it works only when the phone is connected to the internet.
The tutorial is dated 2016. Is there a offline way to do it now?

Thanks in advance :D
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Internet connection is not required in iOS 13+ if the language data is available on the device.
It should happen automatically.

You can test whether it is available offline with:
B4X:
'based on the example code
If speech.SetLanguage(lang) = False Then
    TextView1.Text = "Speech Recognition not available."
Else
    TextView1.Text = "Ready!"
    If App.OSVersion >= 13 Then
        Dim no As NativeObject = speech
        Dim OfflineSupported As Boolean = no.GetField("recognizer").GetField("supportsOnDeviceRecognition").AsBoolean
        Log(OfflineSupported)
    End If
    SetState(True)
End If
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User
Internet connection is not required in iOS 13+ if the language data is available on the device.
It should happen automatically.

You can test whether it is available offline with:
B4X:
'based on the example code
If speech.SetLanguage(lang) = False Then
    TextView1.Text = "Speech Recognition not available."
Else
    TextView1.Text = "Ready!"
    If App.OSVersion >= 13 Then
        Dim no As NativeObject = speech
        Dim OfflineSupported As Boolean = no.GetField("recognizer").GetField("supportsOnDeviceRecognition").AsBoolean
        Log(OfflineSupported)
    End If
    SetState(True)
End If

IMG_6564.jpg


The Speech_AuthorizationStatusChanged is like so:

B4X:
Sub Speech_AuthorizationStatusChanged (Status As Int)
    If speech.IsAuthorized Then
        Dim lang As String
        If speech.SupportedLanguages.IndexOf(speech.DefaultLanguage) > -1 Then
            lang = speech.DefaultLanguage
        Else
            lang = "it"
        End If
     
'        If speech.SetLanguage(lang) = False Then
'            TextView1.Text = "Speech Recognition not available."
'        Else
'            TextView1.Text = "Ready!"
'            SetState(True)
'        End If
     
        'based on the example code
        If speech.SetLanguage(lang) = False Then
            TextView1.Text = "Speech Recognition not available."
        Else
            TextView1.Text = "Ready!"
            If App.OSVersion >= 13 Then
                Dim no As NativeObject = speech
                Dim OfflineSupported As Boolean = no.GetField("recognizer").GetField("supportsOnDeviceRecognition").AsBoolean
                Log(OfflineSupported)
            End If
            SetState(True)
        End If
    Else
        TextView1.Text = "Not authorized..."
    End If
End Sub

In airplane mode it says that is not available, i've the latest iOS installed.
OfflineSupported result is false :(
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User
This means that the offline data isn't available. It worked here with English language.

Worth testing twice with Sleep(1000) between:

i tried like so:

B4X:
            If App.OSVersion >= 13 Then
                Dim no As NativeObject = speech
                Dim OfflineSupported As Boolean = no.GetField("recognizer").GetField("supportsOnDeviceRecognition").AsBoolean
                Log(OfflineSupported)
               
                Sleep(5000)
               
                Dim no As NativeObject = speech
                Dim OfflineSupported As Boolean = no.GetField("recognizer").GetField("supportsOnDeviceRecognition").AsBoolean
                Log(OfflineSupported)
            End If

Still false both the time

i also found this:
Schermata 2021-05-10 alle 10.02.59.png

(p.s. the link is the same of the tweet of before)
 
Last edited:
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User
This means that the offline data isn't available.

today, by chance I was using whatsapp and I noticed that even in airplane mode the "voice to text" functionality of the keyboard worked ... so there are the features to do it offline.
IMG_6609.PNG
 
Upvote 0
Top