-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
50 lines (47 loc) · 1.2 KB
/
index.js
File metadata and controls
50 lines (47 loc) · 1.2 KB
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
const recognition = new webkitSpeechRecognition();
recognition.continuous = true;
recognition.lang = "ja";
recognition.onresult = event => {
for (let i = event.resultIndex; i < event.results.length; ++i) {
if (event.results[i].isFinal) {
const word = hiraganaToKatakana(
removeSpace(event.results[i][0].transcript)
);
console.log(word);
if (word.match(/ハローココチャン/)) {
axios({
method: "get",
url: "http://localhost:3000/api/robots/servoBot/commands/move",
headers: { "Content-Type": "application/json" }
})
.then(function(response) {
console.log(response);
})
.catch(function(error) {
console.log(error);
});
}
}
}
};
recognition.error = e => {
console.error(e);
};
recognition.start();
/**
* ひらがな to カタカナ
* @param {String} str
*/
const hiraganaToKatakana = str => {
return str.replace(/[\u3041-\u3096]/g, function(match) {
const chr = match.charCodeAt(0) + 0x60;
return String.fromCharCode(chr);
});
};
/**
* 空白除去
* @param {String} str
*/
const removeSpace = str => {
return str.replace(/\s+/g, "");
};