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

Support recording directly to a given fileUrl #52

Merged
merged 18 commits into from
Nov 29, 2017
Merged

Conversation

robertfromont
Copy link
Contributor

As an alternative to event-based capture of audio data, these changes allow the plugin to save audio directly to a file.

To enable this option, add a fileUrl setting to the capture config passed into the start method - e.g.

var fileUrl = cordova.file.dataDirectory + "audio.wav";
var captureCfg = {
  sampleRate: 16000,
  bufferSize: 8192,
  channels: 1,
  format: audioinput.FORMAT.PCM_16BIT,
  audioSourceType: audioinput.AUDIOSOURCE_TYPE.DEFAULT,
  fileUrl: fileUrl
};
audioinput.start(captureCfg);

When stop is called, recording is stopped and the data written to the specified file, and then an 'audioinputfinished' event is raised, which includes the original file URL:

window.addEventListener('audioinputfinished', function(e) { 
  doSomethingWithFile(e.file);
}, false);

NB there is a request for saving audio input to files - these changes don't exactly fulfil this request, as here the audio is saved to a file instead of (rather than as well as) being passed in events, and the target format is not the requested M4A. I have tested these changes with WAV files, as this is what my project requires.

robertfromont and others added 18 commits January 31, 2017 17:40
(currently excludes original event based approach).
- if started before stopping previous recording, interrupt previous recording
- if stopped before starting, return error
…ording to a file, because it generates two "finished" events instead of one, and resets the recording when resuming, losing the first half of the recording (the OS appears to pause recording anyway)
…zation, and probing microphone access permissions.
… was called at start (regardless of whether there's been an intervening start call).
@edimuj edimuj merged commit b67c11d into edimuj:master Nov 29, 2017
@edimuj
Copy link
Owner

edimuj commented Nov 29, 2017

Thanks @robertfromont Nice work extending the plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants