-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
55 lines (52 loc) · 1.62 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
var flag_speech = false;
function vr_function(){
var recognition = new webkitSpeechRecognition();
recognition.lang = "ja";
recognition.continuous = true;
recognition.onsoundstart = function() {
// $("#rec_text").text("認識中...");
}
recognition.onnomatch = function() {
// $("#rec_text").text("もう一度試して下さい");
}
recognition.onerror = function(){
// $("#rec_text").text("エラー");
if(flag_speech == false){
vr_function();
}
}
recognition.onsoundend = function(){
// $("#rec_text").text("停止中");
vr_function();
}
recognition.onresult = function(event) {
var results = event.results;
for(var i = event.resultIndex; i < results.length; i++){
var recognized_text = results[i][0].transcript;
$.ajax("http://box.jnlp.org/text-simplifier/translate",
{
type: 'POST',
contentType: 'application/json',
data: JSON.stringify({input_text: recognized_text}),
dataType: 'json'
}).done(function(data){
var simplified_text = data["normal"];
var prepend_html = "<tr><td>" + recognized_text + "</td><td>" + simplified_text + "</td></tr>";
$(prepend_html).hide().prependTo("#talk_log tbody").fadeIn("slow");
var msg = new SpeechSynthesisUtterance(simplified_text);
msg.lang = 'ja-JP';
window.speechSynthesis.speak(msg);
// $("#rec_text").text("通訳を開始する");
vr_function();
});
}
}
flag_speech = false;
recognition.start();
}
$(function(){
$("#input_text").focus();
$("#rec_btn").click(function(){
vr_function();
});
});