Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: recording with already created stream #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 39 additions & 13 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15841,7 +15841,7 @@ var MicRecorder = function () {


createClass(MicRecorder, [{
key: 'addMicrophoneListener',
key: "addMicrophoneListener",
value: function addMicrophoneListener(stream) {
var _this = this;

Expand Down Expand Up @@ -15872,13 +15872,13 @@ var MicRecorder = function () {
this.microphone.connect(this.processor);
this.processor.connect(this.context.destination);
}
}, {
key: 'stop',


/**
* Disconnect microphone, processor and remove activeStream
*/

}, {
key: "stop",
value: function stop() {
if (this.processor && this.microphone) {
// Clean up the Web Audio API resources.
Expand All @@ -15887,7 +15887,7 @@ var MicRecorder = function () {

// If all references using this.context are destroyed, context is closed
// automatically. DOMException is fired when trying to close again
if (this.context && this.context.state !== 'closed') {
if (this.context && this.context.state !== "closed") {
this.context.close();
}

Expand All @@ -15901,14 +15901,14 @@ var MicRecorder = function () {

return this;
}
}, {
key: 'start',


/**
* Requests access to the microphone and start recording
* @return Promise
*/

}, {
key: "start",
value: function start() {
var _this2 = this;

Expand All @@ -15928,25 +15928,51 @@ var MicRecorder = function () {
});
});
}

/**
* Start recording with available stream from microphone
* @param {mediaSteam} stream
* @return Promise
*/

}, {
key: 'getMp3',
key: "startWithStream",
value: function startWithStream(stream) {
var _this3 = this;

var AudioContext = window.AudioContext || window.webkitAudioContext;
this.context = new AudioContext();
this.config.sampleRate = this.context.sampleRate;
this.lameEncoder = new Encoder(this.config);

return new Promise(function (resolve, reject) {
if (stream) {
_this3.addMicrophoneListener(stream);
resolve(stream);
} else {
reject(new Error("stream not found"));
}
});
}

/**
* Return Mp3 Buffer and Blob with type mp3
* @return {Promise}
*/

}, {
key: "getMp3",
value: function getMp3() {
var _this3 = this;
var _this4 = this;

var finalBuffer = this.lameEncoder.finish();

return new Promise(function (resolve, reject) {
if (finalBuffer.length === 0) {
reject(new Error('No buffer to send'));
reject(new Error("No buffer to send"));
} else {
resolve([finalBuffer, new Blob(finalBuffer, { type: 'audio/mp3' })]);
_this3.lameEncoder.clearBuffer();
resolve([finalBuffer, new Blob(finalBuffer, { type: "audio/mp3" })]);
_this4.lameEncoder.clearBuffer();
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions dist/index.min.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/index.min.js.map

This file was deleted.

Loading