@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lls/lls-audio",
3
- "version": "0.0.65",
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.0.9",
30
+ "react-speech-recognizer": "0.1.1",
31
+ "similarity": "1.1.1",
32
32
  "waveform-data": "2.0.0"
33
33
  },
34
34
  "peerDependencies": {
@@ -56,7 +56,6 @@ var AudioWorker = function AudioWorker(self) {
56
56
  };
57
57
 
58
58
  var encodeWAV = function encodeWAV(samples) {
59
- console.log("samples", samples.length);
60
59
  var buffer = new ArrayBuffer(44 + samples.length * 2);
61
60
  var view = new DataView(buffer);
62
61
 
package/recorder/index.js CHANGED
@@ -99,14 +99,14 @@ var initSpeechEvents = function initSpeechEvents(_ref3) {
99
99
  return speechEvents;
100
100
  };
101
101
 
102
- var DesktopAudioRecorder = function (_Component) {
103
- _inherits(DesktopAudioRecorder, _Component);
102
+ var Recorder = function (_Component) {
103
+ _inherits(Recorder, _Component);
104
104
 
105
- function DesktopAudioRecorder(props) {
106
- _classCallCheck(this, DesktopAudioRecorder);
105
+ function Recorder(props) {
106
+ _classCallCheck(this, Recorder);
107
107
 
108
108
  // Instances
109
- var _this = _possibleConstructorReturn(this, (DesktopAudioRecorder.__proto__ || Object.getPrototypeOf(DesktopAudioRecorder)).call(this, props));
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(DesktopAudioRecorder, [{
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$onError = props.onError,
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
- onError(err);
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 DesktopAudioRecorder;
221
+ return Recorder;
220
222
  }(_react.Component);
221
223
 
222
- exports.default = DesktopAudioRecorder;
224
+ exports.default = Recorder;
@@ -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
  }
@@ -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 _props$config = this.props.config,
149
- config = _props$config === undefined ? {} : _props$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 (!API_URL) {
154
- return this.onError(new Error('Missing API_URL in CONF'));
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
- sendFileToSpeechToTextApi(API_URL, wav).then(function (res) {
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 _props2 = this.props,
167
- _props2$config = _props2.config,
168
- config = _props2$config === undefined ? {} : _props2$config,
169
- word = _props2.word,
170
- _props2$compare = _props2.compare,
171
- compare = _props2$compare === undefined ? defaultCompare : _props2$compare;
172
- var API_URL = config.API_URL;
173
- var browserApiAvailable = this.state.browserApiAvailable;
174
-
175
- return browserApiAvailable ? _react2.default.createElement(_reactSpeechRecognizer.WordDetector, { word: word, compare: compare, onNotAvailable: this.onNotAvailable, onFailure: this.onFailure, onSuccess: this.onSuccess }) : API_URL ? _react2.default.createElement(_recorder2.default, { onError: this.onError, onRecordComplete: this.onRecordComplete }) : null;
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