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.

Home Page:https://github.com/edimuj/app-audioinput-demo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

unable to steam the audio through peerJS

subhashkLa opened this issue · comments

Hello, My name is Subhash, I'm new to Ionic I want to create a calling application where I have to stream the audio through PeerJs to establish communication. So currently I'm able to achieve Audio Steaming By using this code but the problem is not able to hear my audio and other than that audioProcess data is coming in zeros. My Microphone is connected It is showing a green dot on top of the mobile screen but not able to hear my audio is there something I'm missing in my code? And then also try to create noise in my speaker by manipulating "channelData" but still there is no sound

System:
Ionic ReactJS,
Capacitors: 5.0.4,
Platform: android

@edimuj will you please able to help me

  const init = async () => {
    // ...some code

    if ((window as any)?.audioinput) {
      // console.log("MIC", (window as any)?.audioinput.AUDIOSOURCE_TYPE.MIC);
      await (window as any)?.audioinput.start({
        streamToWebAudio: true,
        sampleRate: 48000,
        audioSourceType: (window as any)?.audioinput.AUDIOSOURCE_TYPE.MIC,
      });

      const audioContext = (window as any)?.audioinput.getAudioContext();
      const processorNode = audioContext.createScriptProcessor(2048, 1, 1);

      processorNode.addEventListener(
        "audioprocess",
        async function (event: any) {
          const inputBuffer = event.inputBuffer;
          if ((currentAudioRef as any).current) {
            const channelData = inputBuffer.getChannelData(0); // Access the audio data for channel 0

            // Check if channelData contains non-zero values
            const hasAudio = channelData.some((value) => value !== 0);

            if (hasAudio) {
              console.log("Microphone is capturing audio data");
            } else {
              console.log("Microphone is not capturing audio data");
            }

            audioContext.resume().then(() => {
              const audioDataArrayBuffer = channelData.buffer;

              const blob = new Blob([audioDataArrayBuffer], {
                type: "audio/mp3; codecs=opus",
              });
              // console.log("blob", blob);
              (currentAudioRef as any).current.src = URL.createObjectURL(blob);
            });
          }
        }
      );

      (window as any)?.audioinput.connect(processorNode);
      processorNode.connect(audioContext.destination);
    }

    // ...some code
  };

@edimuj will you be able to help me, I stuck for 4 days now