-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtraining.html
More file actions
194 lines (149 loc) · 7.76 KB
/
Copy pathtraining.html
File metadata and controls
194 lines (149 loc) · 7.76 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JavaScript Speech Recognition - Keyword Spotting Demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="//fonts.googleapis.com/css?family=Raleway:400,300,600" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/skeleton.css">
<link rel="stylesheet" href="css/demos.css">
</head>
<body>
<!-- Include the WebRTC adapter -->
<script src="js/adapter.js"></script>
<!-- Include jquery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script src="js/JsSpeechRecognizer.js"></script>
<script>
// Load a notification sound
var notificationSound = new Audio("sounds/notification1.wav");
var speechRec = new JsSpeechRecognizer();
// Adjust the recognizer parameters
speechRec.numGroups = 60;
speechRec.groupSize = 5;
$(document).ready(function() {
speechRec.openMic();
// Add the handler for the button
$("#startStopRecordingButton").click(function() {
if (!speechRec.isRecording()) {
var word = $("#currentWordText").val();
speechRec.startTrainingRecording(word);
// Update the UI, and prevent the testing button from being pressed
$("#startStopRecordingButton").val("stop training");
document.getElementById("testingStartStopRecordingButton").disabled = true;
} else {
var recordingId = speechRec.stopRecording();
// Update the UI and re-enable testing button
$("#startStopRecordingButton").val("start training");
document.getElementById("testingStartStopRecordingButton").disabled = false;
// Append to the results area
var playbackDivId = "playbackResultId" + recordingId;
var playButtonId = "playRecordingButton" + recordingId;
var deleteButtonId = "deleteRecordingButton" + recordingId;
var appendHtml = '<div id=' + playbackDivId + '>recording #' + recordingId;
appendHtml += ' for word <b>' + $("#currentWordText").val() + '</b>';
appendHtml += '<input type="button" class="playDeleteButton" value="play" id="' + playButtonId + '"" />';
appendHtml += '<input type="button" class="playDeleteButton" value="delete" id="' + deleteButtonId + '" />';
appendHtml += '</div>';
$("#resultsDiv").append(appendHtml);
// Add the play click functionality
var finalPlaybackId = recordingId - 1;
$("#" + playButtonId).click(function() {
speechRec.playTrainingBuffer((finalPlaybackId));
});
// Add the delete click functionality
$("#" + deleteButtonId).click(function() {
$("#" + playbackDivId).hide();
speechRec.deleteTrainingBuffer(finalPlaybackId);
speechRec.generateModel();
});
// regenerate the model
speechRec.generateModel();
}
});
$("#testingStartStopRecordingButton").click(function() {
if (!speechRec.isRecording()) {
// Update the UI and prevent the training button from being pressed
$("#testingStartStopRecordingButton").val("stop testing");
document.getElementById("startStopRecordingButton").disabled = true;
speechRec.startKeywordSpottingRecording();
} else {
$("#testingStartStopRecordingButton").val("start testing");
document.getElementById("startStopRecordingButton").disabled = false;
speechRec.stopRecording();
}
});
// Update the confidence threshold
$("#confidenceThreshold").val(speechRec.keywordSpottingMinConfidence);
$("#confidenceThresholdOutput").val(speechRec.keywordSpottingMinConfidence);
$("#confidenceThreshold").on('change', function() {
$("#confidenceThresholdOutput").val($("#confidenceThreshold").val());
speechRec.keywordSpottingMinConfidence = $("#confidenceThreshold").val();
});
});
var updateKeywordSpotting = function(result) {
if ($("#playNotificationCheckbox").prop('checked')) {
// play the notification sound
notificationSound.pause();
notificationSound.currentTime = 0;
notificationSound.play();
}
var timeId = new Date().getTime();
var playbackDivId = "playbackKeywordSpotId" + timeId;
var playButtonId = "playKeywordSpotRecordingButton" + timeId;
var appendHtml = '<div id=' + playbackDivId + '>';
appendHtml += '<b>' + result.match + '</b> ';
appendHtml += '<input type="button" value="play" id="' + playButtonId + '" />';
appendHtml += '</div>';
$("#testingResultsDiv").append(appendHtml);
$("#" + playButtonId).click(function() {
speechRec.playMonoAudio(result.audioBuffer);
});
};
// Set the keyword spotting callback
speechRec.keywordSpottedCallback = updateKeywordSpotting;
</script>
<div class="section">
<div class="container" style="margin-top: 5%">
<h1 class="section-heading">JsSpeechRecognizer - Keyword Spotting</h1>
<p class="section-description">JavaScript Speech Recognition Keyword Spotting Demo</p>
<a href="https://github.com/dreamdom/JsSpeechRecognizer">JsSpeechRecognizer github page</a>
<ol style="margin-top:20px;">
<li>Train the keyword you would like to spot many times.</li>
<li>Test by pressing start testing. Say the keyword you trained.</li>
<li>For more detailed instructions, click <a href="https://github.com/dreamdom/JsSpeechRecognizer/tree/master/demos/keyword-spotting/">here</a>.</li>
</ol>
</div>
</div>
<div class="container">
<div class="row" style="margin-top: 5%">
<div class="one-half column">
<h2>Training</h2>
<div>
Word: <input id="currentWordText" type="text" value="" />
<input class="button-primary" id="startStopRecordingButton" type="button" value="start training" />
</div>
<div id="resultsDiv">
</div>
</div>
<div class="one-half column">
<h2>Testing</h2>
<div>
<label for="fader">Confidence Threshold</label>
<input type="range" min="0" max="1" value=".55" step=".05" id="confidenceThreshold" />
<output for="confidenceThreshold" id="confidenceThresholdOutput">.55</output>
</div>
<div>
<label><input type="checkbox" id="playNotificationCheckbox" checked="checked" /> Play notification sound</label>
</div>
<div>
<input class="button-primary" id="testingStartStopRecordingButton" type="button" value="start testing" />
</div>
<div id="testingResultsDiv">
</div>
</div>
</div>
</div>
</body>
</html>