@lls/lls-audio 0.0.64 → 0.0.66
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 -2
- package/recorder/AudioWorker.js +0 -1
- package/recorder/index.js +12 -10
- package/stories/wordDetector.js +18 -18
- package/wordDetector/index.js +85 -32
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lls/lls-audio",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.66",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"devDependencies": {
|
|
6
6
|
"@kadira/storybook": "2.21.0",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"conventional-changelog": "1.1.0",
|
|
16
16
|
"conventional-changelog-cli": "1.2.0",
|
|
17
17
|
"css-loader": "0.26.1",
|
|
18
|
-
"file-saver": "
|
|
18
|
+
"file-saver": "1.3.3",
|
|
19
19
|
"react": "15.3.1",
|
|
20
20
|
"react-dom": "15.3.1",
|
|
21
21
|
"release-it": "2.4.0",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"inline-worker": "1.1.0",
|
|
29
29
|
"is_js": "0.9.0",
|
|
30
30
|
"react-input-range": "0.9.3",
|
|
31
|
+
"react-speech-recognizer": "0.1.1",
|
|
31
32
|
"waveform-data": "2.0.0"
|
|
32
33
|
},
|
|
33
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
|
@@ -16,12 +16,6 @@ var _player2 = _interopRequireDefault(_player);
|
|
|
16
16
|
|
|
17
17
|
var _wordDetector = require('../wordDetector');
|
|
18
18
|
|
|
19
|
-
var _wordDetector2 = _interopRequireDefault(_wordDetector);
|
|
20
|
-
|
|
21
|
-
var _Visualizer = require('../recorder/Visualizer');
|
|
22
|
-
|
|
23
|
-
var _Visualizer2 = _interopRequireDefault(_Visualizer);
|
|
24
|
-
|
|
25
19
|
var _recorder = require('../recorder');
|
|
26
20
|
|
|
27
21
|
var _recorder2 = _interopRequireDefault(_recorder);
|
|
@@ -34,6 +28,12 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
|
|
|
34
28
|
|
|
35
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; }
|
|
36
30
|
|
|
31
|
+
var onRecordComplete = function onRecordComplete() {
|
|
32
|
+
return console.log("onRecordComplete");
|
|
33
|
+
};
|
|
34
|
+
var onNotAvailable = function onNotAvailable() {
|
|
35
|
+
return console.log("onNotAvailable");
|
|
36
|
+
};
|
|
37
37
|
var onError = function onError(e) {
|
|
38
38
|
return console.log("onError", e);
|
|
39
39
|
};
|
|
@@ -44,6 +44,12 @@ var onFailure = function onFailure(res, attempts) {
|
|
|
44
44
|
return console.log({ res: res, attempts: attempts });
|
|
45
45
|
};
|
|
46
46
|
|
|
47
|
+
var CONFIG = {
|
|
48
|
+
API_URL: 'http://localhost:3004/speechtotext'
|
|
49
|
+
|
|
50
|
+
// Instanciate component with config
|
|
51
|
+
};var WordDetectorComponent = (0, _wordDetector.createWordDetector)(CONFIG);
|
|
52
|
+
|
|
47
53
|
var WordDetectorExample = function (_Component) {
|
|
48
54
|
_inherits(WordDetectorExample, _Component);
|
|
49
55
|
|
|
@@ -55,18 +61,10 @@ var WordDetectorExample = function (_Component) {
|
|
|
55
61
|
_this.state = {
|
|
56
62
|
volume: 0
|
|
57
63
|
};
|
|
58
|
-
_this.setVolume = _this.setVolume.bind(_this);
|
|
59
64
|
return _this;
|
|
60
65
|
}
|
|
61
66
|
|
|
62
67
|
_createClass(WordDetectorExample, [{
|
|
63
|
-
key: 'setVolume',
|
|
64
|
-
value: function setVolume(volume) {
|
|
65
|
-
this.setState({
|
|
66
|
-
volume: volume
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
}, {
|
|
70
68
|
key: 'render',
|
|
71
69
|
value: function render() {
|
|
72
70
|
var volume = this.state.volume;
|
|
@@ -79,14 +77,16 @@ var WordDetectorExample = function (_Component) {
|
|
|
79
77
|
null,
|
|
80
78
|
'Say "Hello"'
|
|
81
79
|
),
|
|
82
|
-
_react2.default.createElement(
|
|
80
|
+
_react2.default.createElement(WordDetectorComponent, {
|
|
83
81
|
word: 'hello',
|
|
84
82
|
onVolumeChange: this.setVolume,
|
|
83
|
+
onNotAvailable: onNotAvailable,
|
|
85
84
|
onError: onError,
|
|
86
85
|
onSuccess: onSuccess,
|
|
87
|
-
onFailure: onFailure
|
|
88
|
-
|
|
89
|
-
|
|
86
|
+
onFailure: onFailure,
|
|
87
|
+
record: true,
|
|
88
|
+
onRecordComplete: onRecordComplete
|
|
89
|
+
})
|
|
90
90
|
);
|
|
91
91
|
}
|
|
92
92
|
}]);
|
package/wordDetector/index.js
CHANGED
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.createWordDetector = undefined;
|
|
7
|
+
|
|
8
|
+
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
|
6
9
|
|
|
7
10
|
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
8
11
|
|
|
@@ -22,6 +25,8 @@ var _fileSaver = require('file-saver');
|
|
|
22
25
|
|
|
23
26
|
var _fileSaver2 = _interopRequireDefault(_fileSaver);
|
|
24
27
|
|
|
28
|
+
var _reactSpeechRecognizer = require('react-speech-recognizer');
|
|
29
|
+
|
|
25
30
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
26
31
|
|
|
27
32
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
@@ -30,21 +35,20 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
|
|
|
30
35
|
|
|
31
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; }
|
|
32
37
|
|
|
33
|
-
var API_URL = 'http://localhost:3004/speechtotext';
|
|
34
38
|
var SIMILARITY_THRESHOLD = 0.8;
|
|
39
|
+
var isSpeechRecognitionAvailable = (0, _reactSpeechRecognizer.speechRecognitionAvailable)();
|
|
35
40
|
|
|
36
41
|
var debug = function debug(wav) {
|
|
37
42
|
_fileSaver2.default.saveAs(wav, 'test.wav');
|
|
38
43
|
};
|
|
39
44
|
|
|
40
|
-
var sendFileToSpeechToTextApi = function sendFileToSpeechToTextApi(wav) {
|
|
45
|
+
var sendFileToSpeechToTextApi = function sendFileToSpeechToTextApi(API_URL, wav) {
|
|
41
46
|
return new Promise(function (resolve, reject) {
|
|
42
47
|
var xhr = new XMLHttpRequest();
|
|
43
48
|
xhr.open('POST', API_URL, true);
|
|
44
49
|
|
|
45
50
|
xhr.onreadystatechange = function () {
|
|
46
51
|
if (xhr.readyState == 4 && xhr.status == 200) {
|
|
47
|
-
console.log('Speech to text: ', xhr.responseText);
|
|
48
52
|
resolve(xhr.responseText);
|
|
49
53
|
}
|
|
50
54
|
};
|
|
@@ -71,26 +75,38 @@ var WordDetector = function (_Component) {
|
|
|
71
75
|
var _this = _possibleConstructorReturn(this, (WordDetector.__proto__ || Object.getPrototypeOf(WordDetector)).call(this, props));
|
|
72
76
|
|
|
73
77
|
_this.state = {
|
|
74
|
-
attempts: 0
|
|
78
|
+
attempts: 0,
|
|
79
|
+
browserApiAvailable: true
|
|
75
80
|
};
|
|
76
81
|
_this.onError = _this.onError.bind(_this);
|
|
77
|
-
_this.
|
|
82
|
+
_this.onSuccess = _this.onSuccess.bind(_this);
|
|
83
|
+
_this.onFailure = _this.onFailure.bind(_this);
|
|
84
|
+
_this.onApiResult = _this.onApiResult.bind(_this);
|
|
78
85
|
_this.onRecordComplete = _this.onRecordComplete.bind(_this);
|
|
79
86
|
return _this;
|
|
80
87
|
}
|
|
81
88
|
|
|
82
89
|
_createClass(WordDetector, [{
|
|
83
|
-
key: '
|
|
84
|
-
value: function
|
|
85
|
-
var
|
|
90
|
+
key: 'onSuccess',
|
|
91
|
+
value: function onSuccess(res, attempts) {
|
|
92
|
+
var _props$onSuccess = this.props.onSuccess,
|
|
93
|
+
onSuccess = _props$onSuccess === undefined ? function () {} : _props$onSuccess;
|
|
86
94
|
|
|
87
|
-
|
|
95
|
+
this.setState({
|
|
96
|
+
attempts: attempts
|
|
97
|
+
});
|
|
98
|
+
onSuccess(res, attempts);
|
|
99
|
+
}
|
|
100
|
+
}, {
|
|
101
|
+
key: 'onFailure',
|
|
102
|
+
value: function onFailure(res, attempts) {
|
|
103
|
+
var _props$onFailure = this.props.onFailure,
|
|
104
|
+
onFailure = _props$onFailure === undefined ? function () {} : _props$onFailure;
|
|
88
105
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}).catch(function (e) {
|
|
92
|
-
_this2.onError(e);
|
|
106
|
+
this.setState({
|
|
107
|
+
attempts: attempts
|
|
93
108
|
});
|
|
109
|
+
onFailure(res, attempts);
|
|
94
110
|
}
|
|
95
111
|
}, {
|
|
96
112
|
key: 'onError',
|
|
@@ -101,39 +117,76 @@ var WordDetector = function (_Component) {
|
|
|
101
117
|
onError(e);
|
|
102
118
|
}
|
|
103
119
|
}, {
|
|
104
|
-
key: '
|
|
105
|
-
value: function
|
|
106
|
-
var
|
|
120
|
+
key: 'onApiResult',
|
|
121
|
+
value: function onApiResult(_ref) {
|
|
122
|
+
var _ref$transcript = _ref.transcript,
|
|
123
|
+
transcript = _ref$transcript === undefined ? '' : _ref$transcript;
|
|
107
124
|
var attempts = this.state.attempts;
|
|
108
125
|
var _props = this.props,
|
|
109
126
|
word = _props.word,
|
|
110
|
-
_props$onSuccess = _props.onSuccess,
|
|
111
|
-
onSuccess = _props$onSuccess === undefined ? function () {} : _props$onSuccess,
|
|
112
|
-
_props$onFailure = _props.onFailure,
|
|
113
|
-
onFailure = _props$onFailure === undefined ? function () {} : _props$onFailure,
|
|
114
127
|
_props$compare = _props.compare,
|
|
115
128
|
compare = _props$compare === undefined ? defaultCompare : _props$compare;
|
|
116
129
|
|
|
117
130
|
var incrementedAttempts = attempts + 1;
|
|
118
|
-
var success = compare(word,
|
|
119
|
-
this.
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
131
|
+
var success = compare(word, transcript);
|
|
132
|
+
var cb = success ? this.onSuccess : this.onFailure;
|
|
133
|
+
cb(transcript, incrementedAttempts);
|
|
134
|
+
}
|
|
135
|
+
}, {
|
|
136
|
+
key: 'onRecordComplete',
|
|
137
|
+
value: function onRecordComplete(wav) {
|
|
138
|
+
var _this2 = this;
|
|
139
|
+
|
|
140
|
+
//debug(wav)
|
|
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;
|
|
146
|
+
var API_URL = config.API_URL;
|
|
147
|
+
var browserApiAvailable = this.state.browserApiAvailable;
|
|
148
|
+
|
|
149
|
+
// Upload to Speech to text Api
|
|
150
|
+
|
|
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
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
onRecordComplete(wav);
|
|
125
164
|
}
|
|
126
165
|
}, {
|
|
127
166
|
key: 'render',
|
|
128
167
|
value: function render() {
|
|
129
|
-
var
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
+
);
|
|
133
181
|
}
|
|
134
182
|
}]);
|
|
135
183
|
|
|
136
184
|
return WordDetector;
|
|
137
185
|
}(_react.Component);
|
|
138
186
|
|
|
139
|
-
exports.default = WordDetector;
|
|
187
|
+
exports.default = WordDetector;
|
|
188
|
+
var createWordDetector = exports.createWordDetector = function createWordDetector(config) {
|
|
189
|
+
return function (props) {
|
|
190
|
+
return _react2.default.createElement(WordDetector, _extends({}, props, { config: config }));
|
|
191
|
+
};
|
|
192
|
+
};
|