top

RECOGNITION

This class is used to subscribe for Voice Recognition events. You can configure event according to the voice commands through this class.

Add the following line for recognition class into a html file your own :

  script type="text/javascript" src="$MANAGER_WIDGET/Common/webapi/1.0/deviceapis.js">/script>

You can declare recognition class like this :

  ex) var recognition= deviceapis.recognition;


Constants

NameValueDescription
PL_RECOGNITION_TYPE_VOICE0defines the recognition type – VOICE
PL_RECOGNITION_TYPE_GESTURE1defines the recognition type – GESTURE
PL_RECOGNITION_TYPE_FACE2defines the recognition type – FACE(not using now)

Methods

GetCurrentVoiceLanguage

Description
The GetCurrentVoiceLanguage function gets the current voice recognition language.
Parameters
none
Return■LanguageCode
  - voice recognition language
   * ko : Korean
   * en : US English
   * en-GB : UK English
   * es-US : American Spanish
   * fr-US : Canadian French
   * pt-US : Brazilian Portuguese
   * cs : Czech
   * nl : Dutch
   * fi : Finnish
   * fr : French
   * de : German
   * el : Greek
   * hu : Hungarian
   * it : Italian
   * no : Norwegian
   * pl : Polish
   * pt : Portuguese
   * ru : Russian
   * es : Spanish
   * sv : Swedish
   * tr : Turkish
   * zh-CN : Chinese
   * zh-HK : HongKong
   * zh-TW : Taiwan
   * ar : Arabic
   * ja : Japanese
   * reference : http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
Emulator SupportY
SDK ConstraintNone
Example
deviceapis.recognition.GetCurrentVoiceLanguage();

HideVoiceHelpbar

Description
The HideVoiceHelpbar function hides the voice recognition helpbar.
Parameters
none
Return■Void
Emulator SupportY
SDK ConstraintNone
Example
deviceapis.recognition.HideVoiceHelpbar();

IsVoiceRecognitionEnabled

Description
The IsVoiceRecognitionEnabled function checks whether the voice recognition is enabled or disabled. Eventhough the returned result is false, the server guide mode is available. If you want to use the server guide mode, you must check to use IsVoiceServerLanguageSupported().
Parameters
none
Return■Number
  - 1 : enabled
    0 : disabled
Emulator SupportY
SDK ConstraintNone
Example
deviceapis.recognition.IsVoiceRecognitionEnalbed();

IsVoiceServerLanguageSupported

Description
IsVoiceServerLanguageSupported function checks whether the current recognition language mode is supported by server guide mode or not .
Parameters
none
Return■Number
  - 1 : supported by Server guide mode
    0 : not supported
Emulator SupportY
SDK ConstraintNone
Example
deviceapis.recognition.IsVoiceServerLanguageSupported();

SDKTest_GenerateExpectedResult

Description
The SDKTest_GenerateExpectedResult function generate results of the voice recognition as the user wants. And it returns results at regular intervals. When a user starts to use voice recognition(e.g. say “Hi TV”) and then says something, the function obtains user’s words as a result. This function is only for test in environment using SDK emulator . So this function code should be removed before uploading application to TV
Parameters
■number
  - Int
  - number of result
■resultList
  - String
  - use separator ‘&&’
   * “samsung&&smart&&TV”
■interval
  - Int
  - eturn result at regular intervals(seconds)
Return■Void
Emulator SupportY
SDK ConstraintNone
Example
function rCallback(result)
{
   var resultVal = result;
}

if(deviceapis.recognition.IsVoiceRecognitionEnalbed())
{
   deviceapis.recognition.SubscribeEvent(deviceapis.recognition.PL_RECOGNITION_TYPE_VOICE, 'smartTV', rCallback);
   deviceapis.recognition.SDKTest_GenerateExpectedResult(2, 'Hi&&samsung',3);
}

deviceapis.recognition.UnsubscribeEvent(deviceapis.recognition.PL_RECOGNITION_TYPE_VOICE, 'smartTV');

SetVoiceHelpbarInfo

Description
The SetVoiceHelpbarInfo function sets the helpbar information of voice recognition.
Parameters
■helpbarInfo
  - String
  - helpbarInfo to register
   * Parameter example 1: Embedded mode
   * Parameter example 2: ServerGuide mode
Return■Void
Emulator SupportY
SDK ConstraintNone
Example
* Parameter example 1
helpbarInfo = '{
    "helpbarType":"HELPBAR_TYPE_VOICE_CUSTOMIZE",
    "helpbarItemsList":[{
        "itemText":"Channel Up/Down",
        "commandList":[
            {"command":"Channel Up"},
            {"command":"Channel Down"}]
        },{
        "itemText":"Stop",
        "commandList":[
            {"command":"Stop"}]
        }
    ],
    "candidateList":[
        {"candidate":"Search"},
        {"candidate":"SearchAll"}
    ]
}';

* Parameter example 2
helpbarInfo = '{
    "helpbarType":"HELPBAR_TYPE_VOICE_SERVER_GUIDE",
    "guideText":"Say the word or phrase you wish to type"}';

* Usage example

var helpbarInfo = '{"helpbarType":"HELPBAR_TYPE_VOICE_CUSTOMIZE","helpbarItemsList":[{"itemText":"Channel", "commandList":[{"command":"Channel"}]},{"itemText":"Stop", "commandList":[{"command":"Stop"}]}],"candidateList":[{"candidate":"Search"},{"candidate":"SearchAll"}]}';

deviceapis.recognition.SetVoiceHelpbarInfo(helpbarInfo);

SetVoiceTimeout

Description
The SetVoiceTimeout function sets the displayed time of voice recognition helpbar.
Parameters
■msTime
  - Int
  - setting to show voice helpbar time
Return■Void
Emulator SupportY
SDK ConstraintNone
Example
deviceapis.recognition.SetVoiceTimeout(2000); //2sec.

ShowVoiceHelpbar

Description
This function shows VoiceHelpbar without speaking trigger word(e.g., "Hi TV") when user pressed voice recognition button on smart controller.
Parameters
none
Return■Void
Emulator SupportY
SDK ConstraintNone
Example
deviceapis.recognition.ShowVoiceHelpbar();

SubscribeExEvent

Description
The SubscribeExEvent function registers a type to receive callback. You must call UnsubscribeExEvent() when you finish using recognition feature.
Parameters
■type
  - PL_RECOGNITION_TYPE
  - type to register
■name
  - String
  - name to subscribe
■callback
  - Function
  - callback function to receive a result information 
   * result information
        resultInfo = {
        - recognitiontype : PL_RECOGNITION_TYPE,
        - eventtype : “EVENT_VOICE_BEGIN_MONITOR” //when you say trigger word. “EVENT_VOICE_BTSOUND_START” //when you press voice recognition button at Smart Control “EVENT_VOICE_RECOG_RESULT” //when voice recognition result is returned
        - result : when voice recognition result is returned, the result is string.
         }
Return■Void
Emulator SupportY
SDK ConstraintNone
Example
function rCallback(resultInfo)
{
    switch(resultInfo.eventtype){
        case 'EVENT_VOICE_BEGIN_MONITOR' :
        case 'EVENT_VOICE_BTSOUND_START' :
            var costomizeHelpbarInfo = '{"helpbarType":"HELPBAR_TYPE_VOICE_CUSTOMIZE","helpbarItemsList":[{"itemText":"Channel", "commandList":[{"command":"Channel"}]},{"itemText":"Stop", "commandList":[{"command":"Stop"}]}],"candidateList":[{"candidate":"Search"},{"candidate":"SearchAll"}]}';

            deviceapis.recognition.SetVoiceHelpbarInfo(costomizeHelpbarInfo);

        case 'EVENT_VOICE_RECOG_RESULT' :
            var recog_result = resultInfo.result;
}
if(deviceapis.recognition.IsRecognitionSupported())
{
    deviceapis.recognition.SubscribeExEvent(deviceapis.recognition.PL_RECOGNITION_TYPE_VOICE, 'testApp', rCallback);
}

UnsubscribeEvent

Description
The UnsubscribeEvent function unregisters a type in order to receive callback.
Parameters
■type 
  - PL_RECOGNITION_TYPE
  - type to unregister
■name 
  - String
  - name to unsubscribe. This name should be same with the name used at SubscribeEvent().
Return■Number
  - 1 : enabled,
    0 : not disabled,
    negative value : the function fails
Emulator SupportY
SDK ConstraintNone
Example
deviceapis.recognition.UnsubscribeEvent(deviceapis.recognition.PL_RECOGNITION_TYPE_VOICE, 'testApp');

UnsubscribeExEvent

Description
The UnsubscribeExEvent function unregisters a type in order to receive callback.
Parameters
■type 
  - PL_RECOGNITION_TYPE
  - Type to unregister
■name 
  - String
  - name to unsubscribe. This name should be same with the name used at SubscribeExEvent().
Return■Number
  - 1 : enabled,
    0 : not disabled
Emulator SupportY
SDK ConstraintNone
Example
deviceapis.recognition.UnsubscribeExEvent(deviceapis.recognition.PL_RECOGNITION_TYPE_VOICE, 'testApp');