-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgxyAudioTensorFlow.js
More file actions
101 lines (89 loc) · 3.71 KB
/
gxyAudioTensorFlow.js
File metadata and controls
101 lines (89 loc) · 3.71 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
let recognizer;
function predictWord() {
// Array of words that the recognizer is trained to recognize.
const audioBlob = new Blob(audioChunks);
const audioUrl = URL.createObjectURL(audioBlob);
const audio = new Audio(audioUrl);
console.log('Stopped recording');
audio.play();
const words = recognizer.wordLabels();
alert('Just before listening');
alert(words);
recognizer.listen(({ scores }) => {
alert('Listening');
// Turn scores into a list of (score,word) pairs.
var init = new Date();
scores = Array.from(scores).map((s, i) => ({ score: s, word: words[i] }));
// Find the most probable word.
scores.sort((s1, s2) => s2.score - s1.score);
alert(scores[0].word);
alert(new Date() - init);
}, { probabilityThreshold: 0.75 });
}
function app() {
recognizer = speechCommands.create('BROWSER_FFT');
new Promise((resolve, reject) => {
resolve(recognizer.ensureModelLoaded());
}).then(() => {
predictWord();
alert('Called predictWord');
});
}
app();
// var client = new Paho.MQTT.Client('192.168.1.2', 3000, "web_" + parseInt(Math.random() * 100, 10));
// client.onConnectionLost = onConnectionLost;
// client.onMessageArrived = onMessageArrived;
// // connect the client
// client.connect({ onSuccess: onConnect });
// var m_battery = {};
// var m_cpu = {};
// // called when the client connects
// function onConnect() {
// // Once a connection has been made, make a subscription and send a message.
// console.log("onConnect");
// client.subscribe("watch1/start");
// client.subscribe("watch1/kill");
// var message = new Paho.MQTT.Message("Watch ready!");
// message.destinationName = "watch1/connect";
// client.send(message);
// }
// // called when the client loses its connection
// function onConnectionLost(responseObject) {
// if (responseObject.errorCode !== 0) {
// console.log("onConnectionLost:" + responseObject.errorMessage);
// }
// }
// // called when a message arrives
// function onMessageArrived(message) {
// console.log('Message Received' + message);
// if (message.destinationName == 'watch1/start') {
// console.log('Received message to start..');
// var msg = JSON.parse(message.payloadString);
// FREQUENCY = msg.frequency;
// if (msg.test_type == 'baseline') {
// alert('Baseline Run!');
// setInterval(function () {
// tizen.systeminfo.getPropertyValue('BATTERY', function (battery) {
// // console.log(properties);
// tizen.systeminfo.getPropertyValue('CPU', function (cpu) {
// init = new Date();
// time = new Date().getTime();
// m_battery = Object.assign(battery);
// m_cpu = Object.assign(cpu);
// var message = new Paho.MQTT.Message(JSON.stringify({
// hrm: heartRateData,
// time: time,
// battery: battery,
// cpuLoad: cpu,
// totalMemory: tizen.systeminfo.getTotalMemory(),
// av_Mem: tizen.systeminfo.getAvailableMemory()
// }));
// message.destinationName = "watch1/finaldata";
// client.send(message);
// console.log('Message sent');
// });
// });
// }, FREQUENCY);
// }
// }
// }