-
Notifications
You must be signed in to change notification settings - Fork 46
/
index.htm
185 lines (165 loc) · 6.57 KB
/
index.htm
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
<!--
Microsoft Speech SDK
====================
FEATURES
--------
* Short-form recognition.
* Long-form dictation.
* Recognition with intent.
* Integrated microphone support.
* External audio support.
LICENSE
-------
© 2015 Microsoft. All rights reserved.
This document is provided “as-is”. Information and views expressed in this document, including URL and other Internet Web site references, may change without notice.
Some examples depicted herein are provided for illustration only and are fictitious. No real association or connection is intended or should be inferred.
This document does not provide you with any legal rights to any intellectual property in any Microsoft product. You may copy and use this document for your internal, reference purposes. This
document is confidential and proprietary to Microsoft. It is disclosed and can be used only pursuant to a non-disclosure agreement.
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<script src="speech.1.0.0.js" type="text/javascript"></script>
<script type="text/javascript">
var client;
var request;
function useMic() {
return document.getElementById("useMic").checked;
}
function getMode() {
switch (document.getElementById("mode").value) {
case "longDictation":
return Microsoft.ProjectOxford.SpeechRecognition.SpeechRecognitionMode.longDictation;
default:
return Microsoft.ProjectOxford.SpeechRecognition.SpeechRecognitionMode.shortPhrase;
}
}
function getOxfordKey() {
return document.getElementById("oxfordkey").value;
}
function getLanguage() {
return "en-us";
}
function clearText() {
document.getElementById("output").value = "";
}
function setText(text) {
document.getElementById("output").value += text;
}
function getLuisConfig() {
var appid = document.getElementById("luis_appid").value;
var subid = document.getElementById("luis_subid").value;
if (appid.length > 0 && subid.length > 0) {
return { appid: appid, subid: subid };
}
return null;
}
function start() {
var mode = getMode();
var luisCfg = getLuisConfig();
clearText();
if (useMic()) {
if (luisCfg) {
client = Microsoft.ProjectOxford.SpeechRecognition.SpeechRecognitionServiceFactory.createMicrophoneClientWithIntent(
getLanguage(),
getOxfordKey(),
getOxfordKey(),
luisCfg.appid,
luisCfg.subid);
} else {
client = Microsoft.ProjectOxford.SpeechRecognition.SpeechRecognitionServiceFactory.createMicrophoneClient(
mode,
getLanguage(),
getOxfordKey(),
getOxfordKey());
}
client.startMicAndRecognition();
setTimeout(function () {
client.endMicAndRecognition();
}, 5000);
} else {
if (luisCfg) {
client = Microsoft.ProjectOxford.SpeechRecognition.SpeechRecognitionServiceFactory.createDataClientWithIntent(
getLanguage(),
getOxfordKey(),
getOxfordKey(),
luisCfg.appid,
luisCfg.subid);
} else {
client = Microsoft.ProjectOxford.SpeechRecognition.SpeechRecognitionServiceFactory.createDataClient(
mode,
getLanguage(),
getOxfordKey(),
getOxfordKey());
}
request = new XMLHttpRequest();
request.open(
'GET',
(mode == Microsoft.ProjectOxford.SpeechRecognition.SpeechRecognitionMode.shortPhrase) ? "whatstheweatherlike.wav" : "batman.wav",
true);
request.responseType = 'arraybuffer';
request.onload = function () {
if (request.status !== 200) {
setText("unable to receive audio file");
} else {
client.sendAudio(request.response, request.response.length);
}
};
request.send();
}
client.onPartialResponseReceived = function (response) {
setText(response);
}
client.onFinalResponseReceived = function (response) {
setText(JSON.stringify(response));
}
client.onIntentReceived = function (response) {
setText(response);
};
}
</script>
</head>
<body style="font-family:'Segoe UI', Tahoma, Geneva, Verdana, sans-serif">
<table width="100%">
<tr><td/><td><h1>Speech.JS</h1><h2>Microsoft Cognitive Services</h2></td></tr>
<tr>
<td align="right"/>
<td><input id="useMic" type="checkbox">Use Microphone</td>
</tr>
<tr>
<td align="right">Mode:</td>
<td>
<select id="mode">
<option selected="selected">shortPhrase</option>
<option>longDictation</option>
</select>
</td>
</tr>
<tr>
<td align="right"><A href="https://www.microsoft.com/cognitive-services/en-us/sign-up" target="_blank">Subscription</A>:</td>
<td><input id="oxfordkey" type="text" size="40"></td>
</tr>
<tr>
<td align="right">LUIS AppId:</td>
<td><input id="luis_appid" type="text" size="40"></td>
</tr>
<tr>
<td align="right">LUIS SubscriptionId:</td>
<td><input id="luis_subid" type="text" size="40"></td>
</tr>
<tr>
<td />
<td><button onclick="start()">Start</button></td>
</tr>
<tr><td/>
<td>
<textarea id="output" style='width:400px;height:200px'></textarea>
</td>
</tr>
<tr><td />
<td><a href="docs/speech.1.0.0.js/index.html" target="_blank">Speech.JS Documentation</a></td>
</tr>
</table>
</body>
</html>