The VoiceControl API provides interfaces and methods for recognizing voice command.
Voice control API offers functionality to recognize the voice and to send the result as predefined command.
Since: 4.0
Specifies the result event.
enum VoiceControlResultEvent {"SUCCESS", "FAILURE"};
The result events defined by this enumeration are:
Specifies command type.
enum VoiceControlCommandType {"FOREGROUND"};
The command type defined by this enumeration is:
The VoiceControlClientManagerObject interface defines what is instantiated in the Tizen object.
[NoInterfaceObject] interface VoiceControlClientManagerObject { readonly attribute VoiceControlClientManager voicecontrol; };
Tizen implements VoiceControlClientManagerObject;
The tizen.voicecontrol object provides access to the functionality of the voice control API.
Voice Control Client Manager
[NoInterfaceObject] interface VoiceControlClientManager { VoiceControlClient getVoiceControlClient() raises(WebAPIException); };
getVoiceControlClient
Requests voice control Client instance.
VoiceControlClient getVoiceControlClient();
Privilege level: public
Privilege: http://tizen.org/privilege/recorder
Remark : This method always returns the static voice control client object. That is, if you call a method using one of voice control client objects, it affects other objects.
Return value: VoiceControlClient The object to manage voice control
Exceptions:
Code example:
/* client1 and client2 refer the same object */ var client1 = tizen.voicecontrol.getVoiceControlClient(); var client2 = tizen.voicecontrol.getVoiceControlClient();
Voice Control Client
[NoInterfaceObject] interface VoiceControlClient { DOMString getCurrentLanguage() raises(WebAPIException); void setCommandList(VoiceControlCommand[] list, optional VoiceControlCommandType? type) raises(WebAPIException); void unsetCommandList(optional VoiceControlCommandType? type) raises(WebAPIException); long addResultListener(VoiceControlResultCallback listener) raises(WebAPIException); void removeResultListener(long id) raises(WebAPIException); long addLanguageChangeListener(VoiceControlLanguageChangeCallback listener) raises(WebAPIException); void removeLanguageChangeListener(long id) raises(WebAPIException); void release() raises(WebAPIException); };
getCurrentLanguage
Gets current language.
DOMString getCurrentLanguage();
A language is specified as an ISO 3166 alpha-2 two letter country-code followed by ISO 639-1 for the two-letter language code. For example, "ko_KR" for Korean, "en_US" for American English.
var client = tizen.voicecontrol.getVoiceControlClient(); var currentLanguage = client.getCurrentLanguage(); console.log("Current language is: " + currentLanguage);
Output example:
Current language is: en_US
setCommandList
Sets command list.
void setCommandList(VoiceControlCommand[] list, optional VoiceControlCommandType? type);
Parameters:
var client = tizen.voicecontrol.getVoiceControlClient(); var commands = [ new tizen.VoiceControlCommand("alpha"), new tizen.VoiceControlCommand("bravo"), new tizen.VoiceControlCommand("charlie")]; client.setCommandList(commands, "FOREGROUND");
unsetCommandList
Unsets command list.
void unsetCommandList(optional VoiceControlCommandType? type);
var client = tizen.voicecontrol.getVoiceControlClient(); var commands = [ new tizen.VoiceControlCommand("alpha"), new tizen.VoiceControlCommand("bravo"), new tizen.VoiceControlCommand("charlie")]; client.setCommandList(commands, "FOREGROUND"); client.unsetCommandList("FOREGROUND");
addResultListener
Registers a listener for getting recognition result.
long addResultListener(VoiceControlResultCallback listener);
Return value: long Identifier used to clear the watch subscription.
var client = tizen.voicecontrol.getVoiceControlClient(); var commands = [ new tizen.VoiceControlCommand("alpha"), new tizen.VoiceControlCommand("bravo"), new tizen.VoiceControlCommand("charlie")]; client.setCommandList(commands, "FOREGROUND"); var resultListenerCallback = function(event, list, result) { console.log("Result callback - event: " + event + ", result: " + result); } var id = client.addResultListener(resultListenerCallback); console.log("Result listener[" + id + "] is created");
Result listener[1] is created
/* (When a user says "alpha") */ Result callback - event: SUCCESS, result: alpha
removeResultListener
Unregisters the listener.
void removeResultListener(long id);
var client = tizen.voicecontrol.getVoiceControlClient(); var commands = [ new tizen.VoiceControlCommand("alpha"), new tizen.VoiceControlCommand("bravo"), new tizen.VoiceControlCommand("charlie")]; client.setCommandList(commands, "FOREGROUND"); var resultListenerCallback = function(event, list, result) { console.log("Result callback - event: " + event + ", result: " + result); } var id = client.addResultListener(resultListenerCallback); client.removeResultListener(id);
addLanguageChangeListener
Registers a callback function to be called when current language is changed.
long addLanguageChangeListener(VoiceControlLanguageChangeCallback listener);
var client = tizen.voicecontrol.getVoiceControlClient(); var languageChangeListenerCallback = function(previous, current) { console.log("Language change callback " + previous + "->" + current); } var id = client.addLanguageChangeListener(languageChangeListenerCallback); console.log("Language change listener[" + id + "] is created");
Language change listener[1] is created
/* (When language is changed) */ Language change callback en_US->ko_KR
removeLanguageChangeListener
Unregisters the callback function.
void removeLanguageChangeListener(long id);
var client = tizen.voicecontrol.getVoiceControlClient(); var languageChangeListenerCallback = function(previous, current) { console.log("Language change callback " + previous + "->" + current);; } var id = client.addLanguageChangeListener(languageChangeListenerCallback); client.removeLanguageChangeListener(id);
release
Releases all resources.
void release();
Releases listeners and disconnects voice control service. You should call this method when you do not want to use voice control client instance any more. It is necessary to create new voice control client instance, if you want to use more after release.
Remark : If you call this method, all other VoiceControlClient objects are also released.
/* Initialize the voice control client */ var client = tizen.voicecontrol.getVoiceControlClient(); var commands = [ new tizen.VoiceControlCommand("alpha"), new tizen.VoiceControlCommand("bravo"), new tizen.VoiceControlCommand("charlie")]; client.setCommandList(commands, "FOREGROUND"); var resultListenerCallback = function(event, list, result) { console.log("Result callback - event: " + event + ", result: " + result); } var id = client.addResultListener(resultListenerCallback); /* Deinitialize the voice control client */ client.removeResultListener(id); client.unsetCommandList("FOREGROUND"); /* After release() voice control does not work */ /* If you want to use voice control after release(), you should initialize the client again */ client.release();
The VoiceControlCommand defines interface used to create command you want to be recognized.
[Constructor(DOMString command, optional VoiceControlCommandType? type)] interface VoiceControlCommand { attribute DOMString command; attribute VoiceControlCommandType type; };
Command constructor
VoiceControlCommand(DOMString command, optional VoiceControlCommandType? type);
Called when default language is changed.
[Callback=FunctionOnly, NoInterfaceObject] interface VoiceControlLanguageChangeCallback { void onlanguagechanged (DOMString previous, DOMString current); };
onlanguagechanged
void onlanguagechanged(DOMString previous, DOMString current);
Called when client gets the recognition result.
[Callback=FunctionOnly, NoInterfaceObject] interface VoiceControlResultCallback { void onresult(VoiceControlResultEvent event, VoiceControlCommand[] list, DOMString results); };
onresult
void onresult(VoiceControlResultEvent event, VoiceControlCommand[] list, DOMString results);
You can check if this API is supported with tizen.systeminfo.getCapability() and decide enable/disable codes that need this API.
To guarantee that the voice control application runs on a device with speech control feature, declare the following feature requirements in the config file:
To guarantee that the voice control application runs on a device with microphone feature, declare the following feature requirements in the config file:
For more information, see Application Filtering.
module VoiceControl { enum VoiceControlResultEvent {"SUCCESS", "FAILURE"}; enum VoiceControlCommandType {"FOREGROUND"}; [NoInterfaceObject] interface VoiceControlClientManagerObject { readonly attribute VoiceControlClientManager voicecontrol; }; Tizen implements VoiceControlClientManagerObject; [NoInterfaceObject] interface VoiceControlClientManager { VoiceControlClient getVoiceControlClient() raises(WebAPIException); }; [NoInterfaceObject] interface VoiceControlClient { DOMString getCurrentLanguage() raises(WebAPIException); void setCommandList(VoiceControlCommand[] list, optional VoiceControlCommandType? type) raises(WebAPIException); void unsetCommandList(optional VoiceControlCommandType? type) raises(WebAPIException); long addResultListener(VoiceControlResultCallback listener) raises(WebAPIException); void removeResultListener(long id) raises(WebAPIException); long addLanguageChangeListener(VoiceControlLanguageChangeCallback listener) raises(WebAPIException); void removeLanguageChangeListener(long id) raises(WebAPIException); void release() raises(WebAPIException); }; [Constructor(DOMString command, optional VoiceControlCommandType? type)] interface VoiceControlCommand { attribute DOMString command; attribute VoiceControlCommandType type; }; [Callback=FunctionOnly, NoInterfaceObject] interface VoiceControlLanguageChangeCallback { void onlanguagechanged (DOMString previous, DOMString current); }; [Callback=FunctionOnly, NoInterfaceObject] interface VoiceControlResultCallback { void onresult(VoiceControlResultEvent event, VoiceControlCommand[] list, DOMString results); }; };