edimuj / cordova-plugin-audioinput

This iOS/Android Cordova/PhoneGap plugin enables audio capture from the device microphone, by in near real-time forwarding audio to the web layer of your application. A typical usage scenario for this plugin would be to use the captured audio as source for a web audio node chain, where it then can be analyzed, manipulated and/or played.
https://github.com/edimuj/app-audioinput-demo
MIT License
161 stars 88 forks source link

Add getAudioMediaStream() function returning MediaStream #65

Open edimuj opened 6 years ago

edimuj commented 6 years ago

Some apps may need a MediaStream instead of an AudioNode or raw audio data.

It should therefore be possible to also get a MediaStream from the audioinput.

Should be implemented by returning the stream from a MediaStreamAudioDestinationNode.

This would enable you to do stuff like this:

var chunks = [];
audioinput.start({streamToWebAudio: true}); // Start the capture
var stream = audioinput.getAudioMediaStream(); // Create/get a stream destination
var mediaRecorder = new MediaRecorder(stream); // Create a MediaRecorder

mediaRecorder.ondataavailable = function(evt) {
    chunks.push(evt.data); // push each chunk (blobs) in an array
};

mediaRecorder.onstop = function(evt) {
    var blob = new Blob(chunks, { 'type' : 'audio/ogg; codecs=opus' }); // Create a blob
    document.querySelector("audio").src = URL.createObjectURL(blob); // <audio controls></audio>
};
edimuj commented 6 years ago

Reminder: MediaStream and CreateMediaStreamDestination isn't available in the iOS WebViews, the change should take this into account. Maybe using polyfills on platforms where these where they aren't available so that getAudioMediaStream returns an object implementing the major functionality that MediaStream normally offers would be a good approach?

projetoarduino commented 6 years ago

Hi i want implement this plugin in my cordova app. I want implement this in webRTC conection, but ios not have getUserMedia() function. Please you can me help ?

edimuj commented 6 years ago

Yes, the missing getUserMedia in the iOS webviews is one of the reasons that this plugin exists, but it isn't currently a complete implementation of getUserMedia (for example only audio input is supported).

But luckily there already exists a cordova plugin for using WebRTC on iOS: https://github.com/BasqueVoIPMafia/cordova-plugin-iosrtc

I would recommend you to look into that plugin instead.