-
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
0 parents
commit f9a070c
Showing
18 changed files
with
1,792 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# ignore Cordova/PhoneGap CLI directories | ||
# in essence, everything but *.xdk file and www directory | ||
/* | ||
!/www | ||
!/docs | ||
!/demo | ||
!/src | ||
!/config.xml | ||
!/README.md | ||
!/LICENSE.md | ||
!/LICENSE | ||
!/package.json | ||
!/.gitignore | ||
!/plugin.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016 Exelerus | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
# cordova-plugin-audioinput | ||
|
||
Cordova plugin which provides real-time audio data capture from the device's microphone. | ||
It can be used for apps that apply effects to microphone input using for example the HTML5 Web Audio API. | ||
|
||
Since 'Navigator.getUserMedia()' isn't supported by all browsers, this plugin enables similar functionality by forwarding raw audio data to the HTML5 app using continuous callbacks. | ||
|
||
It adds the following `window` events: | ||
|
||
* audioinput | ||
* audioinputerror | ||
|
||
## Installation | ||
|
||
``` | ||
cordova plugin add cordova-plugin-audioinput | ||
``` | ||
|
||
or | ||
|
||
``` | ||
cordova plugin add https://github.com/edimuj/cordova-plugin-audioinput.git | ||
``` | ||
|
||
## Supported Platforms | ||
|
||
* Android | ||
* iOS | ||
|
||
## Basic Usage Example | ||
|
||
```javascript | ||
|
||
// Start with default values and let the plugin handle conversion from raw data to web audio and will not send any events. | ||
audioinput.start({ | ||
streamToWebAudio: true | ||
}); | ||
|
||
// Connect the audioinput to the device speakers in order to hear the captured sound. If an audio context is not provided, the plugin will create one for you. | ||
audioinput.connect(audioinput.getAudioContext().destination); | ||
|
||
// Remember that this will create an audio feedback loop so lower the volume! | ||
|
||
``` | ||
|
||
## Advanced Usage Example - Events | ||
|
||
Use this event based method if you want more control over the capture process. | ||
|
||
Define a callback function to subscribe to `audioinput` events. | ||
The callback function will continuously be called during capture, allowing your application to receive chunks of raw audio data. | ||
You can also subscribe to error events `audioinputerror` as seen in the example below. | ||
|
||
```javascript | ||
function onAudioInput(evt) { | ||
|
||
// 'evt.data' is an integer array containing normalized audio data. | ||
// | ||
console.log("Audio data received: " + evt.data.length + " samples"); | ||
|
||
// ... do something with the evt.data array ... | ||
} | ||
|
||
// Listen to audioinput events. | ||
window.addEventListener("audioinput", onAudioInput, false); | ||
|
||
var onAudioInputError = function(error) { | ||
alert("onAudioInputError event recieved: " + error); | ||
}; | ||
|
||
// Listen to audioinputerror events. | ||
window.addEventListener("audioinputerror", onAudioInput, false); | ||
|
||
``` | ||
|
||
After the Cordova `deviceready` event has fired: | ||
|
||
```javascript | ||
var captureCfg = { | ||
sampleRate: 44100, | ||
bufferSize: 8192, | ||
channels: 1, | ||
format: 'PCM_16BIT' | ||
}; | ||
|
||
// Start capturing audio from the microphone | ||
audioinput.start(captureCfg); | ||
|
||
// Stop capturing audio input | ||
audioinput.stop() | ||
``` | ||
|
||
## Demo | ||
The `demo` folder contains examples showing both basic and advanced usage, where the captured microphone audio data is used to playback the audio to the device speaker using the Web Audio API. | ||
|
||
## API | ||
Start capturing audio from the microphone: | ||
|
||
```javascript | ||
audioinput.start( captureCfg ); | ||
``` | ||
|
||
Where `captureCfg` can contain any of the following parameters (Please note that not all audio configurations are supported by all devices): | ||
|
||
```javascript | ||
var captureCfg = { | ||
sampleRate: 44100, // The Sample Rate in Hz. Default: 44100. | ||
bufferSize: 8192, // Maximum size in bytes of the capture buffer. Default: 16384. | ||
channels: 1, // The number of channels to use: Mono (1) or Stereo (2). Default: 1. | ||
format: 'PCM_16BIT' // The audio format. Currently PCM_16BIT and PCM_8BIT are supported. Default: 'PCM_16BIT'. | ||
normalize // Specifies if the audio data should be normalized or not. Default: true. | ||
normalizationFactor // Specifies the factor to use when normalization is performed. Default: 32767.0. | ||
streamToWebAudio // If set to true, the plugin will handle all conversion of the data to web audio. The audioplugin can then act as an AudioNode that can be connected to your web audio node chain. Default: false | ||
audioContext // Used in conjunction with streamToWebAudio. If no audioContext is given, one will be created by the plugin. | ||
concatenateMaxChunks // Defines how many chunks will be merged each time, a low value means lower latency but requires more CPU resources. Default: 10. | ||
}; | ||
``` | ||
|
||
Stop capturing audio from the microphone: | ||
|
||
```javascript | ||
audioinput.stop(); | ||
``` | ||
|
||
Check if the audioinput plugin is capturing, i.e. started or not: | ||
|
||
```javascript | ||
audioinput.isCapturing(); | ||
``` | ||
|
||
Get the current configuration from the audioinput plugin: | ||
|
||
```javascript | ||
audioinput.getCfg(); | ||
``` | ||
|
||
When using `streamToWebAudio` you can connect the audioinput plugin to your web audio node chain: | ||
|
||
```javascript | ||
audioinput.connect( audioNode ); | ||
``` | ||
|
||
When using `streamToWebAudio` you can disconnect the previously connected audioinput plugin from your your web audio node chain: | ||
|
||
```javascript | ||
audioinput.disconnect(); | ||
``` | ||
|
||
When using `streamToWebAudio`, and have not supplied the audioinput plugin with an audio context, the following method is used to get the internally created audio context: | ||
|
||
```javascript | ||
audioinput.getAudioContext(); | ||
``` | ||
|
||
##Credits | ||
|
||
The plugin is created and maintained by Edin Mujkanovic. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<!DOCTYPE html> | ||
|
||
<head> | ||
<title>Cordova Plugin AudioInput Demo</title> | ||
<meta name="format-detection" content="telephone=no"> | ||
<meta name="msapplication-tap-highlight" content="no"> | ||
<meta name="viewport" | ||
content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width"> | ||
<link rel="stylesheet" href="http://www.w3schools.com/lib/w3.css"> | ||
<link rel="stylesheet" href="style.css"> | ||
</head> | ||
|
||
<body> | ||
<div class="w3-center"> | ||
<h3>Cordova AudioInput Plugin<br> | ||
Advanced Demo</h3> | ||
<div id="infoTimer"></div> | ||
<div id="infoMessage">Not ready</div> | ||
<br> | ||
<form class="w3-container"> | ||
<label for="sampleRate">SampleRate</label> | ||
<input id="sampleRate" type="number" value="44100" style="width: 5em;" size="5"/> Hz | ||
<br> | ||
<label for="bufferSize">BufferSize</label> | ||
<input id="bufferSize" type="number" value="16384" style="width: 5em;" size="5"/> bytes | ||
<br> | ||
<label for="channelsMono">Channels</label> | ||
<input type="radio" id="channelsMono" name="channels" value="1" checked> Mono | ||
<input type="radio" id="channelsStereo" name="channels" value="2"> Stereo | ||
<br> | ||
<label for="format8">Format</label> | ||
<input type="radio" id="format8" name="format" value="PCM_8BIT"> PCM 8BIT | ||
<input type="radio" id="format16" name="format" value="PCM_16BIT" checked> PCM 16BIT<br> | ||
<br> | ||
<a class="w3-btn w3-green" href="#" id="startCapture">Start Capture</a> | ||
<a class="w3-btn w3-red" href="#" id="stopCapture">Stop Capture</a> | ||
</form> | ||
<br> | ||
<a class="w3-btn" href="basicdemo.html">Open the Basic Demo</a> | ||
</div> | ||
</body> | ||
|
||
<script type="text/javascript" src="utils.js"></script> | ||
<script type="text/javascript" src="cordova.js"></script> | ||
<script type="text/javascript" src="advanceddemo.js"></script> |
Oops, something went wrong.