Skip to content

Commit

Permalink
some changes to README
Browse files Browse the repository at this point in the history
  • Loading branch information
edimuj committed Mar 28, 2018
1 parent 9a2d00d commit 8175fe6
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,34 @@ After the Cordova `deviceready` event has fired:
// raw data, and therefore will not send any audioinput events.
// If an audio context is not provided, the plugin will create one for you.``

audioinput.start({
streamToWebAudio: true
});

function startCapture() {
audioinput.start({
streamToWebAudio: true
});

// Connect the audioinput to the device speakers in order to hear the captured sound.
audioinput.connect(audioinput.getAudioContext().destination);
}

// Connect the audioinput to the device speakers in order to hear the captured sound.
// First check whether we already have permission to access the microphone.
window.audioinput.checkMicrophonePermission(function(hasPermission) {
if (hasPermission) {
console.log("We already have permission to record.");
startCapture();
}
else {
// Ask the user for permission to access the microphone
window.audioinput.getMicrophonePermission(function(hasPermission, message) {
if (hasPermission) {
console.log("User granted us permission to record.");
startCapture();
} else {
console.warn("User denied permission to record.");
}
});
}
});

audioinput.connect(audioinput.getAudioContext().destination);

```

Expand Down Expand Up @@ -81,7 +101,8 @@ window.addEventListener( "audioinputerror", onAudioInputError, false );

```

After the Cordova `deviceready` event has fired:
After the Cordova `deviceready` event has fired (don't forget to first check/get microphone permissions
as shown in the basic example above):
```javascript

// Start capturing audio from the microphone
Expand All @@ -95,7 +116,7 @@ audioinput.stop()

```

## Advanced Usage Example - saving to files
## Advanced Usage Example - Saving to files
Use `fileUrl` in the `captureCfg` if you want to save audio files directly to the file system.

This requires adding `cordova-plugin-file` to your project:
Expand All @@ -106,7 +127,7 @@ window.requestFileSystem(window.TEMPORARY, 5*1024*1024, function(fs) {
console.log("Got file system: " + fs.name);
fileSystem = fs;

// now you can initialis audio, telling it about the file system you want to use.
// Now you can initialize audio, telling it about the file system you want to use.
var captureCfg = {
sampleRate: 16000,
bufferSize: 8192,
Expand Down

0 comments on commit 8175fe6

Please sign in to comment.