question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make audio stream available when muted

See original GitHub issue

What are you trying to do?

When an attendee starts talking while muted I want to show a message saying “You are muted, please unmute yourself”. This means I want to “watch” the audiostream of the microphone when the attendee is muted and when it reaches a certain threshold (so it detects ‘speaking’) show the message.

What documentation have you looked at so far?

createAnalyserNodeForAudioInput() I have tried using the meetingSession.audioVideo.createAnalyserNodeForAudioInput(). The data is fine when the attendee is not muted, but from the moment the attendee is muted the data is always 0. Is there a different way to get the captured sound?

Any other documentation I couldn’t find anything in the documentation that is related to getting the audio (stream) other than the createAnalyserNodeForAudioInput().

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
simmkyucommented, Jul 18, 2020

When you mute the microphone using realtimeMuteLocalAudio(), SDK simply disables the media stream of the audio input device. createAnalyserNodeForAudioInput() uses this disabled stream, so it won’t help.


As a workaround, you might get the microphone’s stream yourself and create an AnalyserNode on it.

While in the meeting, try running this snippet in the browser console. Make sure to replace __your_device_id__ with the device ID of your muted microphone. You’ll see the non-zero percentage in the console while you speak.

(async function() {
  const stream = await navigator.mediaDevices.getUserMedia({
    audio: { deviceId: '__your_device_id__' }
  });

  // Some browsers have an implementation-defined maximum number of allowed AudioContext.
  // Try reusing the single AudioContext object in production.
  const audioContext = new (window.AudioContext || window.webkitAudioContext)();
  const analyserNode = audioContext.createAnalyser();
  audioContext.createMediaStreamSource(stream).connect(analyserNode);

  const data = new Uint8Array(analyserNode.fftSize);
  let frameIndex = 0;
  const analyserNodeCallback = () => {
    if (frameIndex === 0) {
      analyserNode.getByteTimeDomainData(data);
      const lowest = 0.01;
      let max = lowest;
      for (const f of data) {
        max = Math.max(max, (f - 128) / 128);
      }
      let normalized = (Math.log(lowest) - Math.log(max)) / Math.log(lowest);
      let percent = Math.min(Math.max(normalized * 100, 0), 100);
      console.log(percent); // <-- Use this value to detect "speaking"
    }
    frameIndex = (frameIndex + 1) % 2;
    requestAnimationFrame(analyserNodeCallback);
  };
  requestAnimationFrame(analyserNodeCallback);
})();

I used the startAudioPreview() in the SDK demo. I haven’t tested this code thoroughly, but hope you can get some ideas.

0reactions
blundercodecommented, Dec 14, 2022

Workaround works great still great job.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MediaStreamTrack.muted - Web APIs | MDN
The muted read-only property of the MediaStreamTrack interface returns a boolean value indicating whether or not the track is currently ...
Read more >
How to Appeal Muted Audio - Twitch
This article explains how to appeal muted audio in VODs. If you believe one of your videos has been incorrectly flagged by our...
Read more >
Audio is not available in the stream - Restream Help Center
In some cases your sound may not be available on stream. This is normally caused by broadcaster misconfiguration and is easily fixed on...
Read more >
how to mute the voice of the remote media stream?
Below is some snippet for audio muting. function toggleAudioMute() {. if (localStream.audioTracks.length === 0) {. console.log("No local audio available.");.
Read more >
Add a muted audio stream inside a filter_complex - Super User
So I can avoid to run two different commands to do what I need to. ffmpeg \ -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 \ -i ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found