Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unable to steam the audio through peerJS #128

Open
subhashkLa opened this issue Jun 22, 2023 · 1 comment
Open

unable to steam the audio through peerJS #128

subhashkLa opened this issue Jun 22, 2023 · 1 comment

Comments

@subhashkLa
Copy link

subhashkLa commented Jun 22, 2023

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
  };

@subhashkLa
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant