Back

CreateSpeechRec

Hello World
Content:
- Methods

The SpeechRec object can be used to listen for and recognize speech.

spr = app.CreateSpeechRec( options ) → app object: SpeechRec

Use the Recognize method of the SpeechRec object to tell it to start listening:
speech.Recognize();

When the SpeechRec object has started listening, the OnReady callback function will be called. Use the SetOnReady method to set the name of your OnReady callback function.

If the SpeechRec object recognizes speech, the OnResult callback function will be called. The results are passed to the OnResult callback function as an array, with the most probable result at the front. Use the SetOnResult method to set the name of your OnResult callback function.

If the SpeechRec object does not recognize anything, the OnError callback function will be called. Use the SetOnError method to set the name of your OnError callback function.

Example - Example

function OnStart()
{
    lay = app.CreateLayout( "linear", "VCenter,FillXY" );

    btn = app.CreateButton( "Talk To Me", 0.3, 0.1 );
    btn.SetOnTouch( btn_OnTouch );
    lay.AddChild( btn );

    app.AddLayout( lay );

    speech = app.CreateSpeechRec();
    speech.SetOnReady( speech_OnReady );
    speech.SetOnResult( speech_OnResult );
    speech.SetOnError( speech_OnError );
}

function btn_OnTouch()
{
    speech.Recognize();
}

function speech_OnReady()
{
    app.ShowPopup( "Listening...", "Short" );
}

function speech_OnResult( results )
{
    app.ShowPopup( results[0] );
}

function speech_OnError()
{
    app.ShowPopup( "Please speak more clearly!" );
}
    Copy     Copy All       Run      

Methods

The following methods are available on the SpeechRec object:

Cancel()
GetRMS() → number: float
GetType() → string: “SpeechRec”
IsListening() → boolean
Method( name, types, p1, p2, p3, p4 ) → all types
Stop()
string
string: comma “,” separated: “NoBeep”, “Partial”
list: boolean,char,byte,short,int,long,float,double,String,CharSequence,...
function( error )
function()
function( result )
spr.Cancel
Stop recognizing speech and break other processes.
spr.GetRMS
Returns the RMS value (Root Mean Square) from the audio recorder.
spr.GetType
Returns the control class name.
spr.IsListening
Check whether SpeechRec is currently listening.
spr.Method
Allows access to other functions defined on the object in Java via reflection.

Note: This function is a premium feature. Please consider subscribing to Premium to use this feature and support DroidScript in its further development.
spr.Recognize
Start recognizing speech.
spr.SetOnError
Define a callback function which is called when an error occured.
spr.SetOnReady
Define a callback function which is called when the SpeechRec object is ready for use.
spr.SetOnResult
Define a callback function which is called when a text was successfully recognized
spr.Stop
Stop speech recording and start recognizing.