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

The plugin isn't working #109

Closed Taxi4you closed 1 year ago

Taxi4you commented 4 years ago

On the first time it asks for permission, I give and then nothing merges in events. In the second time, after already granted permissions, it just says:

We already have permission to record.

This is the code:

function StartRecord() {
  // 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.")
        }
      })
    }
  })
  function startCapture() {
    audioinput.start({
      streamToWebAudio: true
    })
  }
}

function StopRecord() {
  audioinput.stop()
}

window.addEventListener( "audioinput", evt => {
  console.log( "Audio data received: " + evt.data.length + " samples" )
}, false )

window.addEventListener( "audioinputerror", err => {
  console.log(`onAudioInputError event recieved:`, err)
}, false )

Some questions:

  1. Why doesn't it working?
  2. What the raw data means? I get chunks that I send to server and then other people can play it with the web audio api, just like image buffer?

Please give me some info about how to handle this plugin and how to send the recorded raw data to the server using HTTP requests.

Thanks.

san40511 commented 4 years ago

console log function can be invisible inside native plugin function if you're using web inspector. Check the xCode log window. About raw data you can open wikipedia and figure out what does it mean. but yes after some manipulation you can use it with html5 api but not on mobile device because if raw data will be too big your app will crash. Things like raw data handling always should do on server side, this plugin you need only for audio streaming that's all.

san40511 commented 4 years ago

try with this options const options = { sampleRate: 16000, bufferSize: 16384, format: 'PCM_16BIT', channels: 1, concatenateMaxChunks: 20, audioSourceType: 0 };

Taxi4you commented 4 years ago

I succeed handle the basic usage and got audioinput event with the chunks. But what can I do with them now? Should I pass them to server using HTTP request and from there send them to other clients and in other clients apps to play them?

BTW, the audioinput stop callback returns with OK in the url instead of a real URL, howcome?

edimuj commented 1 year ago

I would suggest that you check out the demo project: https://github.com/edimuj/app-audioinput-demo It contains some basic functionality for creating files and such.