escolha-speech
v1.0.0
Published
plugin para phonegap
Downloads
4
Readme
Start recognition
Show the recognition dialog and get the recognized sentences
SpeechRecognizer.startRecognize(success, error, maxMatches, promptString, language);
parameters
- success : The success callback. It provides a json array with all possible matches. Example: "[hello world,low world,hello walls]".
- error : The error callback.
- maxMaches : Maximum of returned possibles sentences matches.
- promptString : String shown below the Google logo and the microphone icon. Instruct the user of what to. Example: "Speak now"
- language : Language used by the speech recognition engine. Example: "en-US".
Supported languages
Get the list of supported languages codes
SpeechRecognizer.getSupportedLanguages(success, error);
parameters
- success : The success callback. It provides a json array of all the recognized language codes. Example: "[en-US,fr-FR,de-DE]".
- error : The error callback.
Full example
<!DOCTYPE html>
<html>
<head>
<title>Speech Recognition plugin demo</title>
<script type="text/javascript" src="cordova.js"></script>
</head>
<body>
<script type="text/javascript">
function onDeviceReady(){
console.log("Device is ready");
}
function recognizeSpeech() {
var maxMatches = 5;
var promptString = "Speak now"; // optional
var language = "en-US"; // optional
window.plugins.speechrecognizer.startRecognize(function(result){
alert(result);
}, function(errorMessage){
console.log("Error message: " + errorMessage);
}, maxMatches, promptString, language);
}
// Show the list of the supported languages
function getSupportedLanguages() {
window.plugins.speechrecognizer.getSupportedLanguages(function(languages){
// display the json array
alert(languages);
}, function(error){
alert("Could not retrieve the supported languages : " + error);
});
}
document.addEventListener("deviceready", onDeviceReady, true);
</script>
<button onclick="recognizeSpeech();">Start recognition</button>
<button onclick="getSupportedLanguages();">Get Supported Languages</button>
</body>
</html>