Skip to main content
Version: 0.0.x

Enable / Disable Mic - Python

Enabling and Disabling your microphone refers to turning your microphone on and off, respectively.

Disabling your microphone prevents the transmission of any sound from your microphone to other meeting participants, while Enabling allows them to hear you.

enable_mic()

  • By using the enable_mic() function, the local participant can publish their audio to other participants.

    • You can only call this method when the local participant is not broadcasting audio to others.
  • You can also pass a customised audio track in the enable_mic() method by using Custom Audio Track.

disable_mic()

  • By using the disable_mic() function, the local participant can stop publishing their audio to other participants.

  • You can only call this method when the local participant is broadcasting audio to others.

Example

main.py
import asyncio
from videosdk import MeetingConfig, VideoSDK

VIDEOSDK_TOKEN = "<TOKEN>"
MEETING_ID = "<MEETING_ID>"
NAME = "<NAME>"
loop = asyncio.get_event_loop()

async def main():
meeting_config = MeetingConfig(
meeting_id=MEETING_ID,
name=NAME,
mic_enabled=True,
webcam_enabled=True,
token=VIDEOSDK_TOKEN,
)
meeting = VideoSDK.init_meeting(**meeting_config)

print("joining into meeting...")

await meeting.async_join()

await asyncio.sleep(5)
print("disable mic...after 5 seconds...")

meeting.disable_mic()

await asyncio.sleep(5)
print("enable mic...after 5 seconds...")

meeting.enable_mic()

print("done")

if __name__ == "__main__":
loop.run_until_complete(main())
loop.run_forever()
note

To learn, how to render audio from any source in the meeting, follow this detailed guide.

Events associated with enable_mic

Events associated with disable_mic

participant_events.py
from videosdk import ParticipantEventHandler, Stream

class MyParticipantEventHandler(ParticipantEventHandler):
def __init__(self, participant_id:str):
super().__init__()
self.participant_id = participant_id
def on_stream_enabled(self, stream: Stream):
print("paricipant :: stream enabled", self.participant_id, stream.kind)

def on_stream_disabled(self, stream: Stream):
print("paricipant :: stream disabled", self.participant_id, stream.kind)

def on_media_status_changed(self, data):
print("paricipant :: media status changed", self.participant_id, data)

def on_video_quality_changed(self, data):
print("paricipant :: video quality changed", self.participant_id, data)

adding event listener for local participant.

main.py
    meeting = VideoSDK.init_meeting(**meeting_config)

# add event listener for participant here
local_participant = meeting.local_participant
local_participant.add_event_listener(MyParticipantEventHandler(
participant_id=local_participant.id
))

await meeting.async_join()
...

Output

tip

Stuck anywhere? Check out this example code on GitHub

API Reference

The API references for all the methods and events utilized in this guide are provided below.

Got a Question? Ask us on discord