Skip to content

Commit

Permalink
1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
einazare committed Jan 9, 2023
1 parent 5ca2095 commit 14a97ab
Show file tree
Hide file tree
Showing 4 changed files with 226 additions and 216 deletions.
2 changes: 1 addition & 1 deletion dist/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# @vatis-tech/asr-client-js

![version](https://img.shields.io/badge/version-1.3.1-blue.svg)
![version](https://img.shields.io/badge/version-1.5.0-blue.svg)
![license](https://img.shields.io/badge/license-MIT-blue.svg)
![GitHub issues open](https://img.shields.io/github/issues/Vatis-Tech/asr-client-js.svg)
![GitHub issues closed](https://img.shields.io/github/issues-closed-raw/Vatis-Tech/asr-client-js.svg)
Expand Down
150 changes: 74 additions & 76 deletions dist/cjs/components/MicrophoneGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,84 +81,82 @@ var MicrophoneGenerator = /*#__PURE__*/function () {
var _init = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
var _this = this;
return _regenerator["default"].wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
this.logger({
currentState: "@vatis-tech/asr-client-js: Initializing the \"MicrophoneGenerator\" plugin.",
description: "@vatis-tech/asr-client-js: The MicrophoneGenerator will request for the user's microphone."
});
_context.next = 3;
return navigator.mediaDevices.getUserMedia({
video: false,
audio: true
}).then(function (stream) {
_this.stream = stream;
var options = {
mimeType: "audio/webm",
bitsPerSecond: 128000,
audioBitrateMode: "constant"
while (1) switch (_context.prev = _context.next) {
case 0:
this.logger({
currentState: "@vatis-tech/asr-client-js: Initializing the \"MicrophoneGenerator\" plugin.",
description: "@vatis-tech/asr-client-js: The MicrophoneGenerator will request for the user's microphone."
});
_context.next = 3;
return navigator.mediaDevices.getUserMedia({
video: false,
audio: true
}).then(function (stream) {
_this.stream = stream;
var options = {
mimeType: "audio/webm",
bitsPerSecond: 128000,
audioBitrateMode: "constant"
};
_this.mediaRecorder = new MediaRecorder(stream, options);
_this.mediaRecorder.addEventListener("dataavailable", function (e) {
var _this2 = this;
// Converting audio blob to base64
var reader = new FileReader();
reader.onloadend = function () {
// You can upload the base64 to server here.
_this2.onDataCallback({
data: reader.result.replace("data:audio/webm;codecs=opus;base64,", "").replace("data:audio/webm; codecs=opus;base64,", "").replace("data:audio/webm; codecs=opus; base64,", "")
});
};
_this.mediaRecorder = new MediaRecorder(stream, options);
_this.mediaRecorder.addEventListener("dataavailable", function (e) {
var _this2 = this;
// Converting audio blob to base64
var reader = new FileReader();
reader.onloadend = function () {
// You can upload the base64 to server here.
_this2.onDataCallback({
data: reader.result.replace("data:audio/webm;codecs=opus;base64,", "").replace("data:audio/webm; codecs=opus;base64,", "").replace("data:audio/webm; codecs=opus; base64,", "")
});
};
reader.readAsDataURL(e.data);
// if (e.data.size > 0) {
// if (this.blobState) {
// this.blobState = new Blob([this.blobState, e.data]);
// } else {
// this.blobState = e.data;
// }
// if (this.blobState.size > MICROPHONE_BIT_RATE_SAMPLES) {
// this.blobState.arrayBuffer().then((buffer) => {
// for (
// var i = 0;
// i <
// Math.trunc(
// this.blobState.size / MICROPHONE_BIT_RATE_SAMPLES
// );
// i++
// ) {
// let dataSamples = buffer.slice(
// i * MICROPHONE_BIT_RATE_SAMPLES,
// MICROPHONE_BIT_RATE_SAMPLES +
// i * MICROPHONE_BIT_RATE_SAMPLES
// );
// // this.onDataCallback(new Int32Array(dataSamples));
// this.onDataCallback(base64ArrayBuffer(dataSamples));
// }
// this.blobState = this.blobState.slice(
// i * MICROPHONE_BIT_RATE_SAMPLES,
// this.blobState.size
// );
// });
// }
// }
}.bind(_this));
_this.mediaRecorder.start(_this.microphoneTimeslice);
_this.logger({
currentState: "@vatis-tech/asr-client-js: Initialized the \"MicrophoneGenerator\" plugin.",
description: "@vatis-tech/asr-client-js: The MicrophoneGenerator was successful into getting user's microphone, and will start sending data each ".concat(_this.microphoneTimeslice, " miliseconds.")
});
})["catch"](function (err) {
_this.logger({
currentState: "@vatis-tech/asr-client-js: Could not initilize the \"MicrophoneGenerator\" plugin.",
description: "@vatis-tech/asr-client-js: " + err
});
_this.errorHandler(err);
reader.readAsDataURL(e.data);
// if (e.data.size > 0) {
// if (this.blobState) {
// this.blobState = new Blob([this.blobState, e.data]);
// } else {
// this.blobState = e.data;
// }
// if (this.blobState.size > MICROPHONE_BIT_RATE_SAMPLES) {
// this.blobState.arrayBuffer().then((buffer) => {
// for (
// var i = 0;
// i <
// Math.trunc(
// this.blobState.size / MICROPHONE_BIT_RATE_SAMPLES
// );
// i++
// ) {
// let dataSamples = buffer.slice(
// i * MICROPHONE_BIT_RATE_SAMPLES,
// MICROPHONE_BIT_RATE_SAMPLES +
// i * MICROPHONE_BIT_RATE_SAMPLES
// );
// // this.onDataCallback(new Int32Array(dataSamples));
// this.onDataCallback(base64ArrayBuffer(dataSamples));
// }
// this.blobState = this.blobState.slice(
// i * MICROPHONE_BIT_RATE_SAMPLES,
// this.blobState.size
// );
// });
// }
// }
}.bind(_this));
_this.mediaRecorder.start(_this.microphoneTimeslice);
_this.logger({
currentState: "@vatis-tech/asr-client-js: Initialized the \"MicrophoneGenerator\" plugin.",
description: "@vatis-tech/asr-client-js: The MicrophoneGenerator was successful into getting user's microphone, and will start sending data each ".concat(_this.microphoneTimeslice, " miliseconds.")
});
})["catch"](function (err) {
_this.logger({
currentState: "@vatis-tech/asr-client-js: Could not initilize the \"MicrophoneGenerator\" plugin.",
description: "@vatis-tech/asr-client-js: " + err
});
case 3:
case "end":
return _context.stop();
}
_this.errorHandler(err);
});
case 3:
case "end":
return _context.stop();
}
}, _callee, this);
}));
Expand Down
2 changes: 1 addition & 1 deletion dist/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vatis-tech/asr-client-js",
"version": "1.4.1",
"version": "1.5.0",
"description": "JavaScript client for Vatis Tech ASR services.",
"main": "cjs/index.js",
"scripts": {
Expand Down
Loading

0 comments on commit 14a97ab

Please sign in to comment.