Skip to content

Instantly share code, notes, and snippets.

@PonDad
Created March 5, 2016 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PonDad/fe0a0e385f84524f490a to your computer and use it in GitHub Desktop.
Save PonDad/fe0a0e385f84524f490a to your computer and use it in GitHub Desktop.
Samuel L 9000 Raspberry Pi
<!DOCTYPE html>
<html lang="ja-JP">
<head>
<meta http-equiv="content-type"
content="text/html; charset=UTF-8">
<title><%=title %></title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" type="text/css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<style>
article{
margin: 20px;
}
</style>
</head>
<body>
<header>
<h1 class="text-center h2"><%=title %></h1>
</header>
<article>
<div id="buttons" class="text-center">
<button id="recBtn" class="btn btn-default btn-lg fa fa-microphone"> マイク 開始</button>
</div>
</article>
<script src="http://code.jquery.com/jquery-2.2.0.min.js"></script>
<script>
$(document).ready(function() {
var rec;
var nowRec = false;
var rec = new webkitSpeechRecognition();
rec.continuous = true;
rec.interimResults = false;
rec.lang = 'ja-JP';
rec.onresult = function(e) {
for (var i = e.resultIndex; i < e.results.length; ++i) {
if (e.results[i].isFinal) {
var msg = e.results[i][0].transcript;
msg = msg.replace(/^\s+/g, "");
console.log("Recognised :" + msg);
if(msg.indexOf('サミュエル') >= 0 | msg.indexOf('サミエル') >= 0 | msg.indexOf('samuel') >= 0){
$.get("http://192.168.0.12:3000/wakeup",{text:msg}, function(data){console.log('Send :' + data);});
 }else if(msg.indexOf('プレイ') >= 0 | msg.indexOf('play') >= 0){
$.get("http://192.168.0.12:3000/play",{text:msg}, function(data){console.log('Send :' + data);});
 }else if(msg.indexOf('ストップ') >= 0 | msg.indexOf('stop') >= 0){
$.get("http://192.168.0.12:3000/stop",{text:msg}, function(data){console.log('Send :' + data);});
}else if(msg.indexOf('チーズ') >= 0 | msg.indexOf('cheese') >= 0){
$.get("http://192.168.0.12:3000/cheese",{text:msg}, function(data){console.log('Send :' + data);});
}else if(msg.indexOf('マック') >= 0 | msg.indexOf('mac') >= 0){
$.get("http://192.168.0.12:3000/bigmac",{text:msg}, function(data){console.log('Send :' + data);});
}else if(msg.indexOf('ホワット') >= 0 | msg.indexOf('what') >= 0){
$.get("http://192.168.0.12:3000/ezeikil",{text:msg}, function(data){console.log('Send :' + data);});
}else{
$.get("http://192.168.0.12:3000/control",{text:msg}, function(data){console.log('Send :' + data);});
};
};
};
};
$("#recBtn").click(function() {
if(nowRec){
rec.stop();
$(this).attr("class","btn btn-default btn-lg fa fa-microphone");
$(this).text(" マイク 開始");
nowRec = false;
}else{
rec.start();
$(this).attr("class","btn btn-danger btn-lg fa fa-microphone");
$(this).text(" マイク 停止");
nowRec = true;
}
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment