JavaScript ion applications cannot recognize voice in Android Mobile
•
Android
I want to design an ion application that can listen for voice commands by following the tutorial here, but if I use VaR identification = new webkitspeechrecognition(); After the test, it seems that the application can recognize the voice command on the microphone. / / to the computer command. But when I see this post, I replace the command with
Var identification = new speechrecognition()// To device
But it doesn't seem to work on my Android device. Has anyone encountered the same problem as speechrecognition plugin? Please share your thoughts and comments... Thank you
resolvent:
The trick is to add Cordova media plugin
The working code is as follows:
index.html
<!DOCTYPE html>
<html>
<head>
<Meta name="format-detection" content="telephone=no">
<Meta name="msapplication-tap-highlight" content="no">
<Meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<link rel="stylesheet" type="text/css" href="css/index.css">
<title>Speech Recognition</title>
</head>
<body>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<form>
Click to speak <input type="button" value="speak" name="Download" id="speak" /> <br>
<input type="text" id="q" name="q" size=60>
</form>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/app.js"></script>
</body>
</html>
app.js
$(document).ready(function() {
document.addEventListener("deviceready", onDeviceReady, false);
});
var recognition;
function onDeviceReady() {
$('#speak').click( function() {
recognition = new SpeechRecognition();
recognition.onresult = function(event) {
if (event.results.length > 0) {
console.log(event.results[0][0].transcript);
q.value = event.results[0][0].transcript;
}
};
recognition.start();
});
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码