Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Commit 1a15ccb

Browse files
author
Alexey Reznichenko
committed
Update readme
1 parent 058ec95 commit 1a15ccb

File tree

4 files changed

+54
-24
lines changed

4 files changed

+54
-24
lines changed

README.md

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,35 @@
1-
[![npm version](https://badge.fury.io/js/microsoft-speech-browser-sdk.svg)](https://www.npmjs.com/package/microsoft-speech-browser-sdk)
1+
[![npm version](https://badge.fury.io/js/microsoft-speech-browser-SDK.svg)](https://www.npmjs.com/package/microsoft-speech-browser-SDK)
22

33
## Background
44
Microsoft's Speech Service is a cloud-based platform that features the most advanced algorithms available for converting spoken audio to text. The Universal Speech Protocol allows you to integrate speech recognition into your application using the Microsoft Speech Service.
55

66
## Install
7-
To install [npm package](https://www.npmjs.com/package/microsoft-speech-browser-sdk) run
7+
To install [npm package](https://www.npmjs.com/package/microsoft-speech-browser-SDK) run
88
```
9-
npm install microsoft-speech-browser-sdk
9+
npm install microsoft-speech-browser-SDK
1010
```
1111

1212
## JavaScript SDK - Sample Usage
13-
[RequireJs](http://requirejs.org/) is a dependency. Make sure to reference it in your page before using the SDK.
13+
14+
### As a Node module
15+
16+
If you're building a node app and want to use the Speech SDK, all you need to do is add the following import statement:
1417

1518
```javascript
16-
// Resolve the SDK dependecy using RequireJs
17-
require(["Speech.Browser.Sdk"], function(SDK) {
18-
// Now start using the SDK
19-
});
19+
import * as SDK from 'microsoft-speech-browser-SDK';
20+
```
2021

21-
// Setup the recongizer
22+
<a name="reco_setup"></a>and setup the recognizer:
23+
24+
```javascript
2225
function RecognizerSetup(SDK, recognitionMode, language, format, subscriptionKey) {
2326
let recognizerConfig = new SDK.RecognizerConfig(
2427
new SDK.SpeechConfig(
2528
new SDK.Context(
2629
new SDK.OS(navigator.userAgent, "Browser", null),
2730
new SDK.Device("SpeechSample", "SpeechSample", "1.0.00000"))),
2831
recognitionMode, // SDK.RecognitionMode.Interactive (Options - Interactive/Conversation/Dictation)
29-
language, // Supported laguages are specific to each recognition mode. Refer to docs.
32+
language, // Supported languages are specific to each recognition mode Refer to docs.
3033
format); // SDK.SpeechResultFormat.Simple (Options - Simple/Detailed)
3134

3235
// Alternatively use SDK.CognitiveTokenAuthentication(fetchCallback, fetchOnExpiryCallback) for token auth
@@ -95,10 +98,30 @@ function RecognizerStop(SDK, recognizer) {
9598
}
9699
```
97100

98-
## ES6 Module Usage
99-
```javascript
100-
import * as SDK from 'microsoft-speech-browser-sdk';
101-
```
101+
102+
### In a Browser, as a native ES6 module
103+
104+
...in progress, check back a little later.
105+
106+
### In a Browser, using Webpack
107+
108+
Currently, the TypeScript code in this SDK is compiled using the default module system (CommonJS), which means that the compilation produces a number of distinct JS source files. To make the SDK usable in a browser, it first needs to be "browserified" (all the javascript sources need to be glued together). Towards this end, this is what you need to do:
109+
110+
1. Add `require` statement to you web app source file, for instance (take a look at [sample_app.js](samples/browser/sample_app.js)):
111+
112+
```javascript
113+
var SDK = require('<path_to_speech_SDK>/Speech.Browser.Sdk.js');
114+
```
115+
116+
2. Setup the recognizer, same a [above](#reco_setup).
117+
118+
3. Run your web-app through the webpack (see "bundle" task in [gulpfile.js](gulpfile.js), to execute it, run `npm run bundle`).
119+
120+
4. Add the generated bundle to your html page:
121+
122+
```
123+
<script src="../../distrib/speech.sdk.bundle.js"></script>
124+
```
102125

103126
## Try the sample out
104127
What to try the sample ? All you need is a subscription key. [Sign up](https://www.microsoft.com/cognitive-services/en-us/sign-up) to get one.
@@ -108,12 +131,12 @@ Here is a handy link to our [Sample](https://htmlpreview.github.io/?https://gith
108131
**Note:** Some browsers block microphone access on un-secure origin. So, it is recommended to host the 'sample'/'your app' on https to get it working on all supported browsers.
109132

110133
## Docs
111-
The sdk is a reference implementation for the speech websocket protocol. Check the [API reference](https://docs.microsoft.com/en-us/azure/cognitive-services/speech/api-reference-rest/bingvoicerecognition#websocket) and [Websocket protocol reference](https://docs.microsoft.com/en-us/azure/cognitive-services/speech/api-reference-rest/websocketprotocol) for more details.
134+
The SDK is a reference implementation for the speech websocket protocol. Check the [API reference](https://docs.microsoft.com/en-us/azure/cognitive-services/speech/API-reference-rest/bingvoicerecognition#websocket) and [Websocket protocol reference](https://docs.microsoft.com/en-us/azure/cognitive-services/speech/API-reference-rest/websocketprotocol) for more details.
112135

113136
## Browser support
114-
The SDK depends on WebRTC apis to get access to the microphone and read the audio stream. Most of todays browsers(Edge/Chrome/Firefox) support this. For more details about supported browsers refer to [navigator.getUserMedia#BrowserCompatibility](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/getUserMedia#Browser_compatibility)
137+
The SDK depends on WebRTC APIs to get access to the microphone and read the audio stream. Most of todays browsers(Edge/Chrome/Firefox) support this. For more details about supported browsers refer to [navigator.getUserMedia#BrowserCompatibility](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/getUserMedia#Browser_compatibility)
115138

116-
**Note:** The sdk currently depends on [navigator.getUserMedia](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/getUserMedia#Browser_compatibility) api. However this api is in process of being dropped as browsers are moving towards newer [MediaDevices.getUserMedia](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia) instead. The sdk will add support to the newer api soon.
139+
**Note:** The SDK currently depends on [navigator.getUserMedia](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/getUserMedia#Browser_compatibility) API. However this API is in process of being dropped as browsers are moving towards newer [MediaDevices.getUserMedia](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia) instead. The SDK will add support to the newer API soon.
117140

118141
## Contributing
119142
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.

gulpfile.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var versionBump = require('gulp-bump')
88
var tagVersion = require('gulp-tag-version');
99
var webpack = require('webpack-stream');
1010

11-
gulp.task("build", function() {
11+
gulp.task("build_ES5", function() {
1212
return gulp.src([
1313
"src/**/*.ts",
1414
"Speech.Browser.Sdk.ts"],
@@ -32,7 +32,10 @@ gulp.task("build", function() {
3232
.pipe(gulp.dest('distrib'));
3333
});
3434

35-
gulp.task("bundle", ["build"], function () {
35+
36+
gulp.task("build", ["build_ES5"]);
37+
38+
gulp.task("bundle", ["build_ES5"], function () {
3639
return gulp.src('samples/browser/sample_app.js')
3740
.pipe(webpack({
3841
output: {filename: 'speech.sdk.bundle.js'},

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/browser/sample-server.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ if (fs.existsSync(keyFile)) {
2626

2727
var port = 8765;
2828
var server = http.createServer(function(request, response){
29-
var respond = function(status, data) {
30-
response.writeHead(status);
29+
var respond = function(status, data, contentType) {
30+
if (typeof(contentType) === 'undefined') {
31+
contentType = 'text/plain';
32+
}
33+
response.writeHead(status, {'Content-Type': contentType});
3134
!!data && response.write(data);
3235
response.end();
3336
}
@@ -40,7 +43,7 @@ var server = http.createServer(function(request, response){
4043
respond(200, token);
4144
})
4245
} else if (path == '/') {
43-
respond(200, sample);
46+
respond(200, sample, 'text/html');
4447
} else {
4548
var pathExists = fs.existsSync(__dirname + '/../../'+path);
4649

@@ -49,7 +52,8 @@ var server = http.createServer(function(request, response){
4952
!path.endsWith('speech.sdk.bundle.js.map')) {
5053
respond(404);
5154
} else {
52-
respond(200, fs.readFileSync(__dirname+'/../../'+path, 'utf8'));
55+
var type = 'application/javascript';
56+
respond(200, fs.readFileSync(__dirname+'/../../'+path, 'utf8'), type);
5357
}
5458
}
5559
});

0 commit comments

Comments
 (0)