I am facing an issue that the agent voice is not w...
# ask-ai
s
I am facing an issue that the agent voice is not working on the browser in the following case, if i connectsfor the first time and browser prompts for the mic permissions it works, but if i disconnect and try again and the browser did not prompt for the permission it does not work. There is not any issues and i can hear the recording were both my voice and the agent is there. using livekit client https://www.npmjs.com/package/livekit-client
t
Thanks for reaching out, Youssef. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
It sounds like the issue you're facing might be connected to how the LiveKit client manages microphone permissions and restarts audio tracks after reconnecting. No worries—here are some steps that can help you sort this out: 1. First, make sure your LiveKit client is up-to-date since recent updates often include fixes for issues like this. You can update it easily with
yarn update livekit-client
. 2. Try explicitly stopping and restarting your audio tracks during reconnect. Here's an example:
Copy code
async function reconnect() {
  try {
    // Stop existing tracks if they exist
    const tracks = await room.localParticipant.getTracks();
    for (const track of tracks) {
      await track.stop();
    }

    // Then reconnect
    await room.reconnect();

    // Restart tracks after reconnect
    await room.localParticipant.setMicrophoneEnabled(true);
  } catch (error) {
    console.error("Reconnect error:", error);
  }
}
1. Also, it’s a good idea to handle permissions explicitly before accessing the microphone:
Copy code
async function checkPermissions() {
  try {
    const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
    // Stop the stream so the mic indicator doesn’t stay on unnecessarily
    stream.getTracks().forEach(t => t.stop());
  } catch (error) {
    if (error.name === "NotAllowedError") {
      alert("Microphone permission is needed. Please enable microphone access in your browser settings.");
    }
  }
}
One last tip: double-check that your browser allows microphone access for your site, and maybe try testing in different browsers to narrow down the cause. If you run into any more bumps or want a hand with this, just let me know—I’m here to help! Sources: src/room/Room.ts | quickstart/src/userfriendlyerror.js