Created
March 4, 2017 13:37
-
-
Save PonDad/1a79574369cf8491c1cf83dfec4ec9b8 to your computer and use it in GitHub Desktop.
fastTextで音声入力をネガポジ判定する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var app = express(); | |
var http = require('http').Server(app); | |
var io = require('socket.io')(http); | |
var exec = require('child_process').exec; | |
var five = require("johnny-five"); | |
var board = new five.Board(); | |
app.use(express.static('public')); | |
board.on("ready", function() { | |
var led_red = new five.Led(8); | |
var led_blue = new five.Led(7); | |
var servo_yes = new five.Servo(6); | |
var servo_no = new five.Servo(5); | |
io.sockets.on('connection', function(socket) { | |
socket.on('chat_message', function(data) { | |
exec('python3 ./tool/predict.py ' + data, (err, stdout, stderr) => { | |
if (err) { console.log(err); } | |
console.log(stdout); | |
if (stdout == 1) { | |
led_blue.on(); | |
setTimeout(function(){ | |
led_blue.off(); | |
},1000); | |
servo_no.to(60); | |
setTimeout(function(){ | |
servo_no.to(120); | |
},500); | |
setTimeout(function(){ | |
servo_no.center(); | |
},1000); | |
io.sockets.emit('msg', 'ネガティブ'); | |
}else if (stdout == 2) { | |
led_red.on(); | |
setTimeout(function(){ | |
led_red.off(); | |
},1000) | |
servo_yes.to(60); | |
setTimeout(function(){ | |
servo_yes.to(120); | |
},500); | |
setTimeout(function(){ | |
servo_yes.center(); | |
},1000); | |
io.sockets.emit('msg', 'ポジティブ'); | |
}; | |
}); | |
}); | |
}); | |
}); | |
var port = process.env.PORT || 3000; | |
http.listen(port, function() { | |
console.log('Server Running.'); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="ja"> | |
<head> | |
<meta http-equiv="content-type" | |
content="text/html; charset=UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=no"> | |
<title>PonBot</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"> | |
<link rel="stylesheet" href="style.css"> | |
<link href="https://fonts.googleapis.com/css?family=Orbitron|Roboto+Condensed" rel="stylesheet"> | |
<link rel="stylesheet" href="http://fonts.googleapis.com/earlyaccess/notosansjp.css"> | |
</head> | |
<body> | |
<header> | |
<h1 class="text-center h2">PonBot</h1> | |
</header> | |
<article> | |
<div class="spinner"> | |
<div class="dot1"></div> | |
<div class="dot2"></div> | |
</div> | |
<br> | |
<p id="messages"></p> | |
</article> | |
<script src="https://cdn.socket.io/socket.io-1.3.7.js"></script> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/annyang/2.4.0/annyang.min.js"></script> | |
<script src="http://code.responsivevoice.org/responsivevoice.js"></script> | |
<script src="main.js"></script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var socket = io(); | |
var commands = {'*i': function() {console.log("実行")}}; | |
annyang.addCommands(commands); | |
annyang.setLanguage('ja'); | |
annyang.start(); | |
console.log('録音開始'); | |
annyang.addCallback('resultMatch', function(userSaid) { | |
console.log('録音: ' + userSaid); | |
socket.emit('chat_message', userSaid); | |
}); | |
socket.on('msg', function(msg) { | |
console.log('返信: ' + msg); | |
say(msg); | |
}); | |
function say(msg, callback) { | |
console.log('発話: ' + msg); | |
document.getElementById('messages').textContent = msg; | |
annyang.abort(); | |
console.log('録音停止'); | |
responsiveVoice.speak(msg, 'Japanese Female', { | |
onend: function() { | |
annyang.start(); | |
console.log('録音再開'); | |
} | |
}); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import sys | |
import fasttext as ft | |
import subprocess as cmd | |
obj = sys.argv[1] | |
morp = cmd.getstatusoutput("echo " + obj + " | mecab -Owakati") | |
words = morp[1] | |
classifier = ft.load_model('/home/pon_dad/ponbot/tool/negaposi.bin') | |
estimate = classifier.predict([words], k=2) | |
if estimate[0][0] == "__label__1,": | |
print(1) | |
elif estimate[0][0] == "__label__2,": | |
print(2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* { | |
box-sizing: border-box; | |
} | |
html { | |
font-weight: 300; | |
-webkit-font-smoothing: antialiased; | |
} | |
html, input { | |
font-family: 'Noto Sans Japanese', 'Roboto Condensed', sans-serif; | |
} | |
body{ | |
height: 100%; | |
margin: 0; | |
padding: 0; | |
width: 100%; | |
background-color: #192224; | |
background: -webkit-gradient(linear, left top, left bottom,color-stop(0%, #192224), color-stop(100%, #21728b)); | |
color: #d7ecff; | |
text-shadow: 0 0 1px #fff, 0 0 5px #fff, 0 0 15px #228dff; | |
width: 100vw; | |
height: 100vh; | |
} | |
article{ | |
margin: 20px; | |
text-align: center; | |
} | |
header { | |
font-family: 'Orbitron', sans-serif; | |
font-size: 200%; | |
} | |
#caption{ | |
margin-top: 20px; | |
} | |
.spinner { | |
margin: 50px auto; | |
width: 40px; | |
height: 40px; | |
position: relative; | |
text-align: center; | |
-webkit-animation: sk-rotate 2.0s infinite linear; | |
animation: sk-rotate 2.0s infinite linear; | |
} | |
.dot1, .dot2 { | |
width: 60%; | |
height: 60%; | |
display: inline-block; | |
position: absolute; | |
top: 0; | |
background-color: #d7ecff; | |
box-shadow: 0 0 1px #fff, 0 0 5px #fff, 0 0 15px #228dff; | |
border-radius: 100%; | |
-webkit-animation: sk-bounce 2.0s infinite ease-in-out; | |
animation: sk-bounce 2.0s infinite ease-in-out; | |
} | |
.dot2 { | |
top: auto; | |
bottom: 0; | |
-webkit-animation-delay: -1.0s; | |
animation-delay: -1.0s; | |
} | |
@-webkit-keyframes sk-rotate { 100% { -webkit-transform: rotate(360deg) }} | |
@keyframes sk-rotate { 100% { transform: rotate(360deg); -webkit-transform: rotate(360deg) }} | |
@-webkit-keyframes sk-bounce { | |
0%, 100% { -webkit-transform: scale(0.0) } | |
50% { -webkit-transform: scale(1.0) } | |
} | |
@keyframes sk-bounce { | |
0%, 100% { | |
transform: scale(0.0); | |
-webkit-transform: scale(0.0); | |
} 50% { | |
transform: scale(1.0); | |
-webkit-transform: scale(1.0); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
├── node_modules | |
├── app.js | |
├── package.json | |
├── public | |
│ ├── index.html | |
│ ├── main.js | |
│ └── style.css | |
└── tool | |
├── negaposi.bin | |
└── negaposi.py |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment