@lls/lls-audio 0.0.65 → 0.0.67
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 +3 -3
- package/recorder/AudioWorker.js +0 -1
- package/recorder/index.js +12 -10
- package/stories/wordDetector.js +10 -1
- package/wordDetector/index.js +32 -27
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lls/lls-audio",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.67",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"devDependencies": {
|
|
6
6
|
"@kadira/storybook": "2.21.0",
|
|
@@ -19,7 +19,6 @@
|
|
|
19
19
|
"react": "15.3.1",
|
|
20
20
|
"react-dom": "15.3.1",
|
|
21
21
|
"release-it": "2.4.0",
|
|
22
|
-
"similarity": "1.1.1",
|
|
23
22
|
"style-loader": "0.13.1",
|
|
24
23
|
"superheroes": "1.0.0"
|
|
25
24
|
},
|
|
@@ -28,7 +27,8 @@
|
|
|
28
27
|
"inline-worker": "1.1.0",
|
|
29
28
|
"is_js": "0.9.0",
|
|
30
29
|
"react-input-range": "0.9.3",
|
|
31
|
-
"react-speech-recognizer": "0.
|
|
30
|
+
"react-speech-recognizer": "0.1.1",
|
|
31
|
+
"similarity": "1.1.1",
|
|
32
32
|
"waveform-data": "2.0.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
package/recorder/AudioWorker.js
CHANGED
package/recorder/index.js
CHANGED
|
@@ -99,14 +99,14 @@ var initSpeechEvents = function initSpeechEvents(_ref3) {
|
|
|
99
99
|
return speechEvents;
|
|
100
100
|
};
|
|
101
101
|
|
|
102
|
-
var
|
|
103
|
-
_inherits(
|
|
102
|
+
var Recorder = function (_Component) {
|
|
103
|
+
_inherits(Recorder, _Component);
|
|
104
104
|
|
|
105
|
-
function
|
|
106
|
-
_classCallCheck(this,
|
|
105
|
+
function Recorder(props) {
|
|
106
|
+
_classCallCheck(this, Recorder);
|
|
107
107
|
|
|
108
108
|
// Instances
|
|
109
|
-
var _this = _possibleConstructorReturn(this, (
|
|
109
|
+
var _this = _possibleConstructorReturn(this, (Recorder.__proto__ || Object.getPrototypeOf(Recorder)).call(this, props));
|
|
110
110
|
|
|
111
111
|
_this.worker = null;
|
|
112
112
|
_this.recorder = null;
|
|
@@ -122,7 +122,7 @@ var DesktopAudioRecorder = function (_Component) {
|
|
|
122
122
|
return _this;
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
_createClass(
|
|
125
|
+
_createClass(Recorder, [{
|
|
126
126
|
key: 'componentDidMount',
|
|
127
127
|
value: function componentDidMount() {
|
|
128
128
|
this.init(this.props);
|
|
@@ -132,7 +132,9 @@ var DesktopAudioRecorder = function (_Component) {
|
|
|
132
132
|
value: function init(props) {
|
|
133
133
|
var _this2 = this;
|
|
134
134
|
|
|
135
|
-
var _props$
|
|
135
|
+
var _props$onNotAvailable = props.onNotAvailable,
|
|
136
|
+
onNotAvailable = _props$onNotAvailable === undefined ? function () {} : _props$onNotAvailable,
|
|
137
|
+
_props$onError = props.onError,
|
|
136
138
|
onError = _props$onError === undefined ? function () {} : _props$onError,
|
|
137
139
|
_props$onVolumeChange = props.onVolumeChange,
|
|
138
140
|
onVolumeChange = _props$onVolumeChange === undefined ? function () {} : _props$onVolumeChange,
|
|
@@ -150,7 +152,7 @@ var DesktopAudioRecorder = function (_Component) {
|
|
|
150
152
|
onRecordComplete: onRecordComplete
|
|
151
153
|
});
|
|
152
154
|
}).catch(function (err) {
|
|
153
|
-
|
|
155
|
+
onNotAvailable(err);
|
|
154
156
|
});
|
|
155
157
|
}
|
|
156
158
|
}, {
|
|
@@ -216,7 +218,7 @@ var DesktopAudioRecorder = function (_Component) {
|
|
|
216
218
|
}
|
|
217
219
|
}]);
|
|
218
220
|
|
|
219
|
-
return
|
|
221
|
+
return Recorder;
|
|
220
222
|
}(_react.Component);
|
|
221
223
|
|
|
222
|
-
exports.default =
|
|
224
|
+
exports.default = Recorder;
|
package/stories/wordDetector.js
CHANGED
|
@@ -28,6 +28,12 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
|
|
|
28
28
|
|
|
29
29
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
|
30
30
|
|
|
31
|
+
var onRecordComplete = function onRecordComplete() {
|
|
32
|
+
return console.log("onRecordComplete");
|
|
33
|
+
};
|
|
34
|
+
var onNotAvailable = function onNotAvailable() {
|
|
35
|
+
return console.log("onNotAvailable");
|
|
36
|
+
};
|
|
31
37
|
var onError = function onError(e) {
|
|
32
38
|
return console.log("onError", e);
|
|
33
39
|
};
|
|
@@ -74,9 +80,12 @@ var WordDetectorExample = function (_Component) {
|
|
|
74
80
|
_react2.default.createElement(WordDetectorComponent, {
|
|
75
81
|
word: 'hello',
|
|
76
82
|
onVolumeChange: this.setVolume,
|
|
83
|
+
onNotAvailable: onNotAvailable,
|
|
77
84
|
onError: onError,
|
|
78
85
|
onSuccess: onSuccess,
|
|
79
|
-
onFailure: onFailure
|
|
86
|
+
onFailure: onFailure,
|
|
87
|
+
record: true,
|
|
88
|
+
onRecordComplete: onRecordComplete
|
|
80
89
|
})
|
|
81
90
|
);
|
|
82
91
|
}
|
package/wordDetector/index.js
CHANGED
|
@@ -36,6 +36,7 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
|
|
|
36
36
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
|
37
37
|
|
|
38
38
|
var SIMILARITY_THRESHOLD = 0.8;
|
|
39
|
+
var isSpeechRecognitionAvailable = (0, _reactSpeechRecognizer.speechRecognitionAvailable)();
|
|
39
40
|
|
|
40
41
|
var debug = function debug(wav) {
|
|
41
42
|
_fileSaver2.default.saveAs(wav, 'test.wav');
|
|
@@ -78,7 +79,6 @@ var WordDetector = function (_Component) {
|
|
|
78
79
|
browserApiAvailable: true
|
|
79
80
|
};
|
|
80
81
|
_this.onError = _this.onError.bind(_this);
|
|
81
|
-
_this.onNotAvailable = _this.onNotAvailable.bind(_this);
|
|
82
82
|
_this.onSuccess = _this.onSuccess.bind(_this);
|
|
83
83
|
_this.onFailure = _this.onFailure.bind(_this);
|
|
84
84
|
_this.onApiResult = _this.onApiResult.bind(_this);
|
|
@@ -87,13 +87,6 @@ var WordDetector = function (_Component) {
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
_createClass(WordDetector, [{
|
|
90
|
-
key: 'onNotAvailable',
|
|
91
|
-
value: function onNotAvailable() {
|
|
92
|
-
this.setState({
|
|
93
|
-
browserApiAvailable: false
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
}, {
|
|
97
90
|
key: 'onSuccess',
|
|
98
91
|
value: function onSuccess(res, attempts) {
|
|
99
92
|
var _props$onSuccess = this.props.onSuccess,
|
|
@@ -145,34 +138,46 @@ var WordDetector = function (_Component) {
|
|
|
145
138
|
var _this2 = this;
|
|
146
139
|
|
|
147
140
|
//debug(wav)
|
|
148
|
-
var
|
|
149
|
-
config =
|
|
141
|
+
var _props2 = this.props,
|
|
142
|
+
_props2$config = _props2.config,
|
|
143
|
+
config = _props2$config === undefined ? {} : _props2$config,
|
|
144
|
+
_props2$onRecordCompl = _props2.onRecordComplete,
|
|
145
|
+
onRecordComplete = _props2$onRecordCompl === undefined ? function () {} : _props2$onRecordCompl;
|
|
150
146
|
var API_URL = config.API_URL;
|
|
147
|
+
var browserApiAvailable = this.state.browserApiAvailable;
|
|
151
148
|
|
|
149
|
+
// Upload to Speech to text Api
|
|
152
150
|
|
|
153
|
-
if (!
|
|
154
|
-
|
|
151
|
+
if (!isSpeechRecognitionAvailable) {
|
|
152
|
+
if (!API_URL) {
|
|
153
|
+
return this.onError(new Error('Missing API_URL in CONF'));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
sendFileToSpeechToTextApi(API_URL, wav).then(function (res) {
|
|
157
|
+
_this2.onApiResult(res);
|
|
158
|
+
}).catch(function (e) {
|
|
159
|
+
_this2.onError(e);
|
|
160
|
+
});
|
|
155
161
|
}
|
|
156
162
|
|
|
157
|
-
|
|
158
|
-
_this2.onApiResult(res);
|
|
159
|
-
}).catch(function (e) {
|
|
160
|
-
_this2.onError(e);
|
|
161
|
-
});
|
|
163
|
+
onRecordComplete(wav);
|
|
162
164
|
}
|
|
163
165
|
}, {
|
|
164
166
|
key: 'render',
|
|
165
167
|
value: function render() {
|
|
166
|
-
var
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
word =
|
|
170
|
-
|
|
171
|
-
compare =
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
168
|
+
var _props3 = this.props,
|
|
169
|
+
_props3$record = _props3.record,
|
|
170
|
+
record = _props3$record === undefined ? false : _props3$record,
|
|
171
|
+
word = _props3.word,
|
|
172
|
+
_props3$compare = _props3.compare,
|
|
173
|
+
compare = _props3$compare === undefined ? defaultCompare : _props3$compare;
|
|
174
|
+
|
|
175
|
+
return _react2.default.createElement(
|
|
176
|
+
'div',
|
|
177
|
+
null,
|
|
178
|
+
isSpeechRecognitionAvailable ? _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 }),
|
|
179
|
+
isSpeechRecognitionAvailable && record && _react2.default.createElement(_recorder2.default, { onError: this.onError, onRecordComplete: this.onRecordComplete })
|
|
180
|
+
);
|
|
176
181
|
}
|
|
177
182
|
}]);
|
|
178
183
|
|