Skip to content

Commit 443f6a4

Browse files
committed
use bufferFrom instead of Buffer.from to support old environments.
Fixes #55
1 parent e1fabd1 commit 443f6a4

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@
4949
"webpack": "^2.2.1"
5050
},
5151
"dependencies": {
52+
"buffer-from": "^0.1.1",
5253
"clone": "^2.1.0",
5354
"defaults": "^1.0.3",
5455
"get-user-media-promise": "^1.1.0",
5556
"lodash.pullallwith": "^4.7.0",
56-
"microphone-stream": "^3.0.5",
57+
"microphone-stream": "^3.0.8",
5758
"nodeify-fetch": "^1.0.1",
5859
"object.assign": "^4.0.4",
5960
"object.pick": "^1.2.0",

speech-to-text/webaudio-l16-stream.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
var Transform = require('stream').Transform;
33
var util = require('util');
44
var defaults = require('defaults');
5+
// some versions of the buffer browser lib don't support Buffer.from (such as the one included by the current version of express-browserify)
6+
var bufferFrom = require('buffer-from');
57

68
var TARGET_SAMPLE_RATE = 16000;
79
/**
@@ -151,9 +153,9 @@ WebAudioL16Stream.prototype.floatTo16BitPCM = function(input) {
151153
var output = new DataView(new ArrayBuffer(input.length * 2)); // length is in bytes (8-bit), so *2 to get 16-bit length
152154
for (var i = 0; i < input.length; i++) {
153155
var multiplier = input[i] < 0 ? 0x8000 : 0x7fff; // 16-bit signed range is -32768 to 32767
154-
output.setInt16(i * 2, (input[i] * multiplier) | 0, true); // index, value, little edian
156+
output.setInt16(i * 2, (input[i] * multiplier) | 0, true); // index, value ("| 0" = convert to 32-bit int, round towards 0), littleEndian.
155157
}
156-
return Buffer.from(output.buffer);
158+
return bufferFrom(output.buffer);
157159
};
158160

159161
/**

0 commit comments

Comments
 (0)