@lls/lls-audio 0.0.69 → 0.0.71
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/recorder/index.js +16 -0
- package/wordDetector/index.js +29 -20
package/package.json
CHANGED
package/recorder/index.js
CHANGED
|
@@ -115,6 +115,7 @@ var Recorder = function (_Component) {
|
|
|
115
115
|
// Data
|
|
116
116
|
_this.recordStart = null;
|
|
117
117
|
_this.audioBuffer = [];
|
|
118
|
+
_this.audioStream = null;
|
|
118
119
|
|
|
119
120
|
// Methods
|
|
120
121
|
_this.init = _this.init.bind(_this);
|
|
@@ -127,6 +128,20 @@ var Recorder = function (_Component) {
|
|
|
127
128
|
value: function componentDidMount() {
|
|
128
129
|
this.init(this.props);
|
|
129
130
|
}
|
|
131
|
+
}, {
|
|
132
|
+
key: 'componentWillUnmount',
|
|
133
|
+
value: function componentWillUnmount() {
|
|
134
|
+
if (this.audioStream.getTracks) {
|
|
135
|
+
var tracks = this.audioStream.getTracks();
|
|
136
|
+
tracks.forEach(function (track) {
|
|
137
|
+
return track.stop();
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
this.audioStream.stop && this.audioStream.stop();
|
|
142
|
+
|
|
143
|
+
this.speechEvents.stop();
|
|
144
|
+
}
|
|
130
145
|
}, {
|
|
131
146
|
key: 'init',
|
|
132
147
|
value: function init(props) {
|
|
@@ -166,6 +181,7 @@ var Recorder = function (_Component) {
|
|
|
166
181
|
onRecordComplete = _ref4.onRecordComplete;
|
|
167
182
|
|
|
168
183
|
// Init worker that will do heavy calculation
|
|
184
|
+
this.audioStream = stream;
|
|
169
185
|
this.worker = initWorker({ onMessage: function onMessage(e) {
|
|
170
186
|
switch (e.data.command) {
|
|
171
187
|
case 'send_buffers':
|
package/wordDetector/index.js
CHANGED
|
@@ -87,8 +87,7 @@ var WordDetector = function (_Component) {
|
|
|
87
87
|
_createClass(WordDetector, [{
|
|
88
88
|
key: 'onSuccess',
|
|
89
89
|
value: function onSuccess(res, attempts) {
|
|
90
|
-
var
|
|
91
|
-
onSuccess = _props$onSuccess === undefined ? function () {} : _props$onSuccess;
|
|
90
|
+
var onSuccess = this.props.onSuccess;
|
|
92
91
|
|
|
93
92
|
this.setState({
|
|
94
93
|
attempts: attempts
|
|
@@ -98,8 +97,7 @@ var WordDetector = function (_Component) {
|
|
|
98
97
|
}, {
|
|
99
98
|
key: 'onFailure',
|
|
100
99
|
value: function onFailure(res, attempts) {
|
|
101
|
-
var
|
|
102
|
-
onFailure = _props$onFailure === undefined ? function () {} : _props$onFailure;
|
|
100
|
+
var onFailure = this.props.onFailure;
|
|
103
101
|
|
|
104
102
|
this.setState({
|
|
105
103
|
attempts: attempts
|
|
@@ -109,8 +107,7 @@ var WordDetector = function (_Component) {
|
|
|
109
107
|
}, {
|
|
110
108
|
key: 'onError',
|
|
111
109
|
value: function onError(e) {
|
|
112
|
-
var
|
|
113
|
-
onError = _props$onError === undefined ? function () {} : _props$onError;
|
|
110
|
+
var onError = this.props.onError;
|
|
114
111
|
|
|
115
112
|
onError(e);
|
|
116
113
|
}
|
|
@@ -122,8 +119,7 @@ var WordDetector = function (_Component) {
|
|
|
122
119
|
var attempts = this.state.attempts;
|
|
123
120
|
var _props = this.props,
|
|
124
121
|
word = _props.word,
|
|
125
|
-
|
|
126
|
-
compare = _props$compare === undefined ? defaultCompare : _props$compare;
|
|
122
|
+
compare = _props.compare;
|
|
127
123
|
|
|
128
124
|
var incrementedAttempts = attempts + 1;
|
|
129
125
|
var success = compare(word, transcript);
|
|
@@ -137,16 +133,17 @@ var WordDetector = function (_Component) {
|
|
|
137
133
|
|
|
138
134
|
//debug(wav)
|
|
139
135
|
var _props2 = this.props,
|
|
140
|
-
|
|
141
|
-
config = _props2
|
|
142
|
-
|
|
143
|
-
onRecordComplete = _props2$onRecordCompl === undefined ? function () {} : _props2$onRecordCompl;
|
|
136
|
+
alwaysUseApi = _props2.alwaysUseApi,
|
|
137
|
+
config = _props2.config,
|
|
138
|
+
onRecordComplete = _props2.onRecordComplete;
|
|
144
139
|
var API_URL = config.API_URL;
|
|
145
140
|
var browserApiAvailable = this.state.browserApiAvailable;
|
|
146
141
|
|
|
147
|
-
// Upload to Speech to text Api
|
|
148
142
|
|
|
149
|
-
|
|
143
|
+
var useHtmlDetector = isSpeechRecognitionAvailable && !alwaysUseApi;
|
|
144
|
+
|
|
145
|
+
// Upload to Speech to text Api
|
|
146
|
+
if (!useHtmlDetector) {
|
|
150
147
|
if (!API_URL) {
|
|
151
148
|
return this.onError(new Error('Missing API_URL in CONF'));
|
|
152
149
|
}
|
|
@@ -164,17 +161,17 @@ var WordDetector = function (_Component) {
|
|
|
164
161
|
key: 'render',
|
|
165
162
|
value: function render() {
|
|
166
163
|
var _props3 = this.props,
|
|
167
|
-
|
|
168
|
-
record = _props3$record === undefined ? false : _props3$record,
|
|
164
|
+
record = _props3.record,
|
|
169
165
|
word = _props3.word,
|
|
170
|
-
|
|
171
|
-
|
|
166
|
+
compare = _props3.compare,
|
|
167
|
+
alwaysUseApi = _props3.alwaysUseApi;
|
|
172
168
|
|
|
169
|
+
var useHtmlDetector = isSpeechRecognitionAvailable && !alwaysUseApi;
|
|
173
170
|
return _react2.default.createElement(
|
|
174
171
|
'div',
|
|
175
172
|
null,
|
|
176
|
-
|
|
177
|
-
|
|
173
|
+
useHtmlDetector ? _react2.default.createElement(_reactSpeechRecognizer.WordDetector, { word: word, compare: compare, onFailure: this.onFailure, onSuccess: this.onSuccess }) : _react2.default.createElement(_recorder2.default, { onError: this.onError, onRecordComplete: this.onRecordComplete }),
|
|
174
|
+
useHtmlDetector && record && _react2.default.createElement(_recorder2.default, { onError: this.onError, onRecordComplete: this.onRecordComplete })
|
|
178
175
|
);
|
|
179
176
|
}
|
|
180
177
|
}]);
|
|
@@ -182,6 +179,18 @@ var WordDetector = function (_Component) {
|
|
|
182
179
|
return WordDetector;
|
|
183
180
|
}(_react.Component);
|
|
184
181
|
|
|
182
|
+
WordDetector.defaultProps = {
|
|
183
|
+
alwaysUseApi: true,
|
|
184
|
+
config: {},
|
|
185
|
+
record: false,
|
|
186
|
+
word: '',
|
|
187
|
+
compare: defaultCompare,
|
|
188
|
+
onRecordComplete: function onRecordComplete() {},
|
|
189
|
+
onError: function onError() {},
|
|
190
|
+
onSucces: function onSucces() {},
|
|
191
|
+
onFailure: function onFailure() {}
|
|
192
|
+
};
|
|
193
|
+
|
|
185
194
|
exports.default = WordDetector;
|
|
186
195
|
var createWordDetector = exports.createWordDetector = function createWordDetector(config) {
|
|
187
196
|
return function (props) {
|