forked from Azure-Samples/cognitive-services-speech-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
57 lines (46 loc) · 1.8 KB
/
index.js
File metadata and controls
57 lines (46 loc) · 1.8 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
(function() {
"use strict";
// pull in the required packages.
var sdk = require("microsoft-cognitiveservices-speech-sdk");
var fs = require("fs");
var settings = require("./settings");
var speech = require("./speech");
var intent = require("./intent");
var translate = require("./translation");
function openPushStream(filename) {
// create the push stream we need for the speech sdk.
var pushStream = sdk.AudioInputStream.createPushStream();
// open the file and push it to the push stream.
fs.createReadStream(filename).on('data', function(arrayBuffer) {
pushStream.write(arrayBuffer.buffer);
}).on('end', function() {
pushStream.close();
});
return pushStream;
}
if (process.argv.length > 3) {
settings.filename = process.argv[3];
}
if (process.argv.length > 2) {
switch (process.argv[2]) {
case "intent":
console.log("Now recognizing intent from: " + settings.filename);
intent.main(settings, openPushStream(settings.filename));
break;
case "translate":
console.log("Now translating from: " + settings.filename);
translate.main(settings, openPushStream(settings.filename));
break;
case "speech":
default:
console.log("Now recognizing speech from: " + settings.filename);
speech.main(settings, openPushStream(settings.filename));
break;
}
}
else {
console.log("usage: index.js [speech|intent|translate] {filename}");
}
}());