Voice control API offers functionality to recognize the voice and to send the result as predefined command.
Since: 4.0
enum VoiceControlResultEvent {"SUCCESS", "FAILURE"};
The result events defined by this enumeration are:
enum VoiceControlCommandType {"FOREGROUND"};
The command type defined by this enumeration is:
[NoInterfaceObject] interface VoiceControlClientManagerObject { readonly attribute VoiceControlClientManager voicecontrol; };
Tizen implements VoiceControlClientManagerObject;
The tizen.voicecontrol object provides access to the functionality of the voice control API.
[NoInterfaceObject] interface VoiceControlClientManager { VoiceControlClient getVoiceControlClient() raises(WebAPIException); };
getVoiceControlClient
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:
Exceptions:
with error type NotSupportedError, if this feature is not supported.
with error type SecurityError, if the application does not have the privilege to call this method.
with error type AbortError, if the operation cannot be finished properly.
Code example:
/* client1 and client2 refer the same object */ var client1 = tizen.voicecontrol.getVoiceControlClient(); var client2 = tizen.voicecontrol.getVoiceControlClient();
[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
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
void setCommandList(VoiceControlCommand[] list, optional VoiceControlCommandType? type);
Parameters:
with error type TypeMismatchError, if the input parameter is not compatible with the expected type.
with error type InvalidValuesError, if any of the input parameters contain an invalid value.
var client = tizen.voicecontrol.getVoiceControlClient(); var commands = [ new tizen.VoiceControlCommand("alpha"), new tizen.VoiceControlCommand("bravo"), new tizen.VoiceControlCommand("charlie")]; client.setCommandList(commands, "FOREGROUND");
unsetCommandList
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
long addResultListener(VoiceControlResultCallback listener);
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
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
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
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
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();
[Constructor(DOMString command, optional VoiceControlCommandType? type)] interface VoiceControlCommand { attribute DOMString command; attribute VoiceControlCommandType type; };
VoiceControlCommand(DOMString command, optional VoiceControlCommandType? type);
The command should be set as text you want to be recognized.
The default value is "FOREGROUND"
[Callback=FunctionOnly, NoInterfaceObject] interface VoiceControlLanguageChangeCallback { void onlanguagechanged (DOMString previous, DOMString current); };
onlanguagechanged
void onlanguagechanged(DOMString previous, DOMString current);
[Callback=FunctionOnly, NoInterfaceObject] interface VoiceControlResultCallback { void onresult(VoiceControlResultEvent event, VoiceControlCommand[] list, DOMString results); };
onresult
void onresult(VoiceControlResultEvent event, VoiceControlCommand[] list, DOMString results);
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); }; };