B4J Tutorial [ABMaterial] Text2Speech

Ola

Been looking for this like forever...

Usage:

B4X:
MashSpeak(page,"I have been developing A.B.M. web apps for a while now. It's an enjoyable experience.",0.7)

B4X:
Sub MashSpeak(pg As ABMPage, msg As String, rate As Double)
    Dim script As String = $"var speech = new SpeechSynthesisUtterance();
    // Set the text and voice attributes.
    speech.text = "${msg}";
    speech.volume = 1;
    speech.rate = ${rate};
    speech.pitch = 1;
    window.speechSynthesis.speak(speech);"$
    pg.ws.Eval(script,Null)
    pg.ws.flush
End Sub

When this function is called, a robot voice will read out the given string, doing it's best human impression.


Now I just need a way to remove all HTML tags from my text for it to be read properly. The robots are taking over!! :D:D:D
Ta!
 
Last edited:

Mashiane

Expert
Licensed User
Longtime User
Hi Mashiane:MashSpeak is very good,Another feature is better SpeechRecognition, would like to quote but I will not use, the following URL reference: https://codepen.io/PJCHENder/pen/mMzYgO
thank you
Eish my friend, at the moment I am caught inbetween AskTeenCoach and Project.Show and only priority issues are taking up my space where ABM is concerned. I had featured these as I thought someone here will find it useful as I needed it for Bible.Show (still shelved). Thanks for the heads up anyway.
 

Anser

Well-Known Member
Licensed User
Longtime User
Observed the following.

On the phone, if the application is directly called from the Phone's internet browser, then it is audible.

I use a B4A app and then via WebView the ABM application URL is called. In this case it is not audible on the phone. So I believe that this is something to do with the B4A's Webview.

Any hint ?

EDIT:-

This is the DefaultWebChromeClient console message that I see on my B4A app
Uncaught ReferenceError: SpeechSynthesisUtterance is not defined
 
Last edited:

Mashiane

Expert
Licensed User
Longtime User
Observed the following.

On the phone, if the application is directly called from the Phone's internet browser, then it is audible.

I use a B4A app and then via WebView the ABM application URL is called. In this case it is not audible on the phone. So I believe that this is something to do with the B4A's Webview.

Any hint ?

EDIT:-

This is the DefaultWebChromeClient console message that I see on my B4A app
Uncaught ReferenceError: SpeechSynthesisUtterance is not defined
I guess if we follow AB's recommendations to rather develop an ABM Native app it would work. I haven't explored anything that far as yet and the only trial I did with the webview I didnt go as far as using speech.
 

Anser

Well-Known Member
Licensed User
Longtime User
Whatever the technology is used to create the Web application, finally it is HTML and that's the reason all other internet browser are playing the sound. Wonder why the Android WebView is not able to make it audible. May be there is some extra options available in the WebVew which we may not be aware of.
 

Mashiane

Expert
Licensed User
Longtime User
Whatever the technology is used to create the Web application, finally it is HTML and that's the reason all other internet browser are playing the sound. Wonder why the Android WebView is not able to make it audible. May be there is some extra options available in the WebVew which we may not be aware of.
Yes, I guess so, but then using a webview for ABM apps is something that I think AB is not recommending.
 

Beja

Expert
Licensed User
Longtime User
New
Hi Mashiane
Is ABMPage a library or you are calling a service? can you put together a simple project?

Thanks
 

Anser

Well-Known Member
Licensed User
Longtime User
If I am not wrong, ABMPage is included in the ABM Library itself. If you check ABMPageTemplate.bas you will find the following entry in Sub Class_Globals

B4X:
'Class module
Sub Class_Globals
    Private ws As WebSocket 'ignore
    ' will hold our page information
    Public page As ABMPage
       . . . . .
       . . . . .
 
Top