OneTok Titanium Module

Looking to include voice recognition in your Titanium app? You can use the OneTok service and the Titanium module to add this feature into your Titanium project in just a couple lines of code.

What is OneTok?

OneTok provides developers with a simple and flexible infrastructure for building voice recognition controls into mobile apps.

To learn more please visit them here OneTok.com and review their documentation here.

The Titanium Module

The Ti.OneTok module provides a wrapper around the OneTok SDK allowing you to call it from your Titanium Project.  The Ti.OneTok module is available for download from the github project.

You can download the compiled iOS module here.  Documentation is available for the iOS module here.

The Code

The complete code, documentation, and example app.js is available for download ongithub here.

Ti.OneTok is available under the Apache 2 license so feel free to fork, extended, and contribute.

An Example

A full demonstration app.js is available in the module’s example folder.

Below shows how to authenticate and tell OneTok which grammar to use.

//Sample demonstrating how to authenticate a Ti.OneTok Session
function authenticateSession(){
    
    function onError(e){
        //We encountered an error, provide the details
        Ti.API.info(e);
        alert('Errored on Authentication');
    };
    function onSuccess(e){
        //Login was successful
        alert('Authenticated Successfully');
    };
    
    if(!Ti.Network.online){
        alert("I'm sorry a network connection is needed to use this module");
    }else{
        oneTokSession.authenticate({
                hostName:"http://sandbox.onetok.com:8080",
                appID : "YOUR_APP_ID_GOES_HERE",
                appToken : "YOUR_APP_TOKEN_GOES_HERE",
                version : "0.1",
                onSuccess:onSuccess, //Called when authentication is successful
                onError:onError //Called on authentication error        
        });     
    }   
};

The below shows how to start recording.

function startRecording(){
    var oneTokOutput = [];
    
    //This method is called on error
    function onError(e){
        Ti.API.info(e);
        alert('Errored while recording');
    };
    
    //This method is called as OneTok processes your
    //speak results. This will be called several times before finish
    function onResults(e){
        Ti.API.info("results=" + JSON.stringify(e));
        //We add the pending results to be used later.
        oneTokOutput.push(e);
        //You can check the result_type to determine if 
        //a valid result has been returned
        if(e.result_type=='valid'){
            Ti.API.info("Valid Results=" + JSON.stringify(e));  
        }
    };
    
    //This method is called when the recording session has finished
    function onFinish(e){
        alert('Recording Completed');
        Ti.API.info(JSON.stringify(oneTokOutput));
    };
    
    if(!Ti.Network.online){
        alert("I'm sorry a network connection is needed to use this module");
    }else{      
        oneTokSession.startRecording({
                onResults:onResults, //Add callback to process results, called many times 
                onError:onError, //Add callback to handle error messages
                onFinish:onFinish  //Add callback to handle when recording has finished
        });
    }   
};

FAQ

  • Is there an Android version? – Coming soon
  • How do I start using OneTok? – OneTok requires an API key, please register at OneTok.com and follow their get started tutorial.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s