mute-assistant not working (web sdk)
# support
c
Hello, I'm trying to mute the assistant after the first message is said, but I'm unable to do so using the following
Copy code
vapiInstance.on('speech-end', () => {
        console.log('speech-end');
        setIsSpeaking(false);
        
        // Mute after the first speech ends
        vapiInstance.send({
          type: 'control',
          control: 'mute-assistant'
        });
      });
I'm not sure if I'm calling the send command in the right place, but my thought was that once the speech-end is triggered my mute-assistant command would run. I've also tried setting the send command outside of the .on method, but that doesn't work either I'm working with the web sdk and here are some call logs: - e45ad042-d13c-41a2-a5cc-6c0b0a19e009 - 75dd754b-455d-4d66-9b75-edab8959d1ca Any help would be appreciated.
k
Add a hasMuted flag to ensure mute-assistant is sent only once after the first speech-end event, like this: let hasMuted = false; vapiInstance.on('speech-end', () => { if (!hasMuted) { hasMuted = true; vapiInstance.send({ type: 'control', control: 'mute-assistant' }); } });
c
Thanks for the reply, but my issue is with the muting never occuring, not with the conditional logic that triggers the muting. I had purposely removed my conditional logic to make the point that the muting doesn't occur even in the most basic example. My goal is to have the assistant say its first message and then not speak again - even if the end user speaks. I essentially want the end user to leave a voicemail message after the assistant says something like "I'm not available right now, please leave a message". The end user will likely start the voicemail with "Hi [assistant name]...", but this is triggering the assistant to reply back. Just to check all the boxes I added your logic and I can see the "muting assistant" console log run after the assistant's first message, but the muting doesn't occur because when I start saying something like "Hey [assistant name], just calling to ..." the assistant will respond.
Copy code
let hasMuted = false;
  vapiInstance.on('speech-end', () => {
    console.log('speech-end');
    setIsSpeaking(false);
    if (!hasMuted) {
      console.log('muting assistant');
      vapiInstance.send({
        type: 'control',
        control: 'mute-assistant'
      })
      hasMuted = true;
    }
  });
Hope my intent is a bit more clear now
k
Use vapiInstance.say("I'm not available right now, please leave a message.", true); this ends the call after speaking, preventing further replies..
c
I don't want the call to end after the assistant says its first message which would be something like "I'm not available right now, please leave a message." I want the end user to be able to say something after the assistant's first message and then manually end the call. The call should consist of two messages: the assistant's first message and the user's response message
k
Use vapiInstance.say("I'm not available right now, please leave a message."); without ending the call, then listen for the user’s response with gather(), and manually end the call afterward with hangUp().
c
I'm not understanding what you mean by this. These seem to be methods related to workflows, which I am not using for my assistants. Also, aren't these methods being deprecated? https://discord.com/channels/1211482211119796234/1364673760514539652/1375904617388572713 I can get a somewhat working solution by forcing the call to end when the ai attempts to speak for the second time (after the user has spoken), but I am never able to get a Success Evaluation. There seems to be something on the vapi side that prevents Success Evalutions with only two messages (ai message and then user message)
Copy code
let speakerCount = 0;
  vapiInstance.on('speech-start', () => {
    console.log('speech-start');
    setIsSpeaking(true);
    if (speakerCount > 0) {
      console.log('ending call');
      vapiRef.current.stop();
    }
  });

  vapiInstance.on('speech-end', () => {
    console.log('speech-end');
    setIsSpeaking(false);
    speakerCount++;
  });
call ids for this approach: - 21448df5-2a15-4ac2-9961-529924be0fc5 - 5ff48c89-5211-43d7-afaa-8f74feab5901
@Kings_big💫 Any thoughts on this?
k
Define the tool and set the serverUrl, note that test suites won’t trigger real HTTP calls, and success evaluations likely require more than two exchanges, so test live and extend conversations for better results..
c
I'm not using tools or test suites, is this a requirement I'm unaware of? I'm creating assitants on the fly using the web sdk (non-persistant assistants). I have a serverUrl that is connected and works for any conversation that is longer than two messages. Does the success evaluation require more than two exchanges? If so, is there a setting I can turn off for this? Is there a way I can escalate this further? I really need a solution.
k
Looking into it
c
Thank you!
k
We are not receiving any mute event from your side, so most likely it's your code issue. Recheck your code again.
c
Not sure what changed between two days ago and today, but the same code I had then works now
Copy code
let speakerCount = 0;
  vapiInstance.on('speech-start', () => {
    console.log('speech-start');
    setIsSpeaking(true);
    if (speakerCount > 0) {
      console.log('ending call');
      vapiRef.current.stop();
    }
  });

  vapiInstance.on('speech-end', () => {
    console.log('speech-end');
    setIsSpeaking(false);
    speakerCount++;
  });
Appreciate the help, @Kings_big💫
k
Glad It fixed
2 Views