# HandleVoiceInput call error

**URL:** <https://forum.convai.com/t/handlevoiceinput-call-error/1392>\
**Category:** Unity SDK\
**Tags:** question, webgl, unity\
**Created:** [August 8, 2024, 6:57am UTC](https://forum.convai.com/t/handlevoiceinput-call-error/1392 "2024-08-08T06:57:37Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![K3](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.convai.com/k3/32/2611_2.png) [@K3](https://forum.convai.com/u/K3)\
**Post date:** [August 8, 2024, 6:57am UTC](https://forum.convai.com/t/handlevoiceinput-call-error/1392/1 "2024-08-08T06:57:37Z")

</div>

**Original Discord Post by or\_rmo | 2024-08-08 06:57:37**

As you advised, I tried to apply HandleVoiceInput to a button using eventtrigger.

However, an error occurs.

I changed HandleVoiceInput to public in the player interaction manager and called it.

Please help me,

**Images:**

 ![20240808_155434.png](https://canada1.discourse-cdn.com/flex004/uploads/convai/original/2X/2/2b80f2cdfa555316f94434f7d429b3c9be9a811f.png)  
 ![20240808_155449.png](https://canada1.discourse-cdn.com/flex004/uploads/convai/original/2X/2/28e1901cc31fc90c4a4c12d0b4880c2c5d288b06.png)  
 ![20240808_155454.png](https://canada1.discourse-cdn.com/flex004/uploads/convai/original/2X/b/ba58b1ff9709e62ea050cf59a9e453d7f2dbf434.png)

---

<div class="post-metadata">

**Author:** ![K3](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.convai.com/k3/32/2611_2.png) [@K3](https://forum.convai.com/u/K3)\
**Post date:** [August 8, 2024, 8:03am UTC](https://forum.convai.com/t/handlevoiceinput-call-error/1392/2 "2024-08-08T08:03:42Z")

</div>

**Reply by k3kalinix | 2024-08-08 08:03:42**

Hello \<@684027455433998381\> 👋🏻

---

<div class="post-metadata">

**Author:** ![K3](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.convai.com/k3/32/2611_2.png) [@K3](https://forum.convai.com/u/K3)\
**Post date:** [August 8, 2024, 8:03am UTC](https://forum.convai.com/t/handlevoiceinput-call-error/1392/3 "2024-08-08T08:03:59Z")

</div>

**Reply by k3kalinix | 2024-08-08 08:03:59**

Is the Npc active?

---

<div class="post-metadata">

**Author:** ![K3](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.convai.com/k3/32/2611_2.png) [@K3](https://forum.convai.com/u/K3)\
**Post date:** [August 8, 2024, 8:07am UTC](https://forum.convai.com/t/handlevoiceinput-call-error/1392/4 "2024-08-08T08:07:40Z")

</div>

**Reply by or\_rmo | 2024-08-08 08:07:40**

Yes, it is activated.

---

<div class="post-metadata">

**Author:** ![K3](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.convai.com/k3/32/2611_2.png) [@K3](https://forum.convai.com/u/K3)\
**Post date:** [August 8, 2024, 8:08am UTC](https://forum.convai.com/t/handlevoiceinput-call-error/1392/5 "2024-08-08T08:08:48Z")

</div>

**Reply by or\_rmo | 2024-08-08 08:08:48**

**Images:**

 ![image.png](https://canada1.discourse-cdn.com/flex004/uploads/convai/original/2X/2/2a886a0e3142b986e13366efa521abf8a505ad75.png)

---

<div class="post-metadata">

**Author:** ![K3](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.convai.com/k3/32/2611_2.png) [@K3](https://forum.convai.com/u/K3)\
**Post date:** [August 8, 2024, 8:09am UTC](https://forum.convai.com/t/handlevoiceinput-call-error/1392/6 "2024-08-08T08:09:25Z")

</div>

**Reply by k3kalinix | 2024-08-08 08:09:25**

Why don’t you use our mobile talk button?

---

<div class="post-metadata">

**Author:** ![K3](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.convai.com/k3/32/2611_2.png) [@K3](https://forum.convai.com/u/K3)\
**Post date:** [August 8, 2024, 8:10am UTC](https://forum.convai.com/t/handlevoiceinput-call-error/1392/7 "2024-08-08T08:10:35Z")

</div>

**Reply by or\_rmo | 2024-08-08 08:10:35**

There is no mobile call button because it is webgl,😭

---

<div class="post-metadata">

**Author:** ![K3](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.convai.com/k3/32/2611_2.png) [@K3](https://forum.convai.com/u/K3)\
**Post date:** [August 8, 2024, 8:12am UTC](https://forum.convai.com/t/handlevoiceinput-call-error/1392/8 "2024-08-08T08:12:39Z")

</div>

**Reply by k3kalinix | 2024-08-08 08:12:39**

You added a new interaction manager.

---

<div class="post-metadata">

**Author:** ![K3](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.convai.com/k3/32/2611_2.png) [@K3](https://forum.convai.com/u/K3)\
**Post date:** [August 8, 2024, 8:13am UTC](https://forum.convai.com/t/handlevoiceinput-call-error/1392/9 "2024-08-08T08:13:02Z")

</div>

**Reply by k3kalinix | 2024-08-08 08:13:02**

You have to create a new script.

---

<div class="post-metadata">

**Author:** ![K3](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.convai.com/k3/32/2611_2.png) [@K3](https://forum.convai.com/u/K3)\
**Post date:** [August 8, 2024, 8:19am UTC](https://forum.convai.com/t/handlevoiceinput-call-error/1392/10 "2024-08-08T08:19:45Z")

</div>

**Reply by or\_rmo | 2024-08-08 08:19:45**

Are you saying that I need to write a script that activates the microphone and inputs text when the button is pressed?

---

<div class="post-metadata">

**Author:** ![K3](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.convai.com/k3/32/2611_2.png) [@K3](https://forum.convai.com/u/K3)\
**Post date:** [August 8, 2024, 8:22am UTC](https://forum.convai.com/t/handlevoiceinput-call-error/1392/11 "2024-08-08T08:22:54Z")

</div>

**Reply by or\_rmo | 2024-08-08 08:22:54**

Do you have an example??

---

<div class="post-metadata">

**Author:** ![K3](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.convai.com/k3/32/2611_2.png) [@K3](https://forum.convai.com/u/K3)\
**Post date:** [August 8, 2024, 8:23am UTC](https://forum.convai.com/t/handlevoiceinput-call-error/1392/12 "2024-08-08T08:23:34Z")

</div>

**Reply by k3kalinix | 2024-08-08 08:23:34**

```cs
using Convai.Scripts.Runtime.Core;
using Convai.Scripts.Runtime.LoggerSystem;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

namespace Convai.Scripts.Runtime.UI
{
    public class ConvaiTalkButtonHandler : Button
    {
        private const float NORMAL_ALPHA = 1f; // The alpha when button is not pressed
        private const float PRESSED_ALPHA = 0.5f; // The alpha when button is pressed
        private ConvaiNPC _currentActiveNPC;
        private bool _subscribed;

        protected override void Start()
        {
            base.Start();
            if (ConvaiNPCManager.Instance != null)
            {
                ConvaiNPCManager.Instance.OnActiveNPCChanged += OnActiveNPCChangedHandler;
                ConvaiLogger.Info("Listening to OnActiveNPCChanged event.", ConvaiLogger.LogCategory.Character);
            }
            else
            {
                ConvaiLogger.Warn("Instance of ConvaiNPCManager is not yet initialized.", ConvaiLogger.LogCategory.Character);
            }
        }

        protected override void OnEnable()
        {
            // Check if NPC Manager instance is available before subscribing
            ConvaiNPCManager npcManager = ConvaiNPCManager.Instance;
            if (npcManager != null)
            {
                npcManager.OnActiveNPCChanged += OnActiveNPCChangedHandler;
                _currentActiveNPC = npcManager.GetActiveConvaiNPC();
                if (!_subscribed)
                {
                    _subscribed = true;
                    ConvaiLogger.Info("Subscribed to OnActiveNPCChanged event.", ConvaiLogger.LogCategory.Character);
                }
            }
            else
            {
                ConvaiLogger.Warn("NPC Manager instance is not available during enabling.", ConvaiLogger.LogCategory.Character);
            }
        }

        protected override void OnDisable()
        {
            // Always make sure to unsubscribe from events when the object is disabled
            ConvaiNPCManager npcManager = ConvaiNPCManager.Instance;
            if (npcManager != null)
            {
                npcManager.OnActiveNPCChanged -= OnActiveNPCChangedHandler;
                if (_subscribed)
                {
                    _subscribed = false;
                    ConvaiLogger.Info("Unsubscribed from OnActiveNPCChanged event.", ConvaiLogger.LogCategory.Character);
                }
            }
        }

        protected override void OnDestroy()
        {
            if (ConvaiNPCManager.Instance != null)
            {
                ConvaiNPCManager.Instance.OnActiveNPCChanged -= OnActiveNPCChangedHandler;
                ConvaiLogger.Info("Stopped listening to OnActiveNPCChanged event.", ConvaiLogger.LogCategory.Character);
            }
        }

        private void OnActiveNPCChangedHandler(ConvaiNPC newActiveNPC)
        {
            _currentActiveNPC = newActiveNPC;
            if (_currentActiveNPC != null)
                ConvaiLogger.Info($"Active NPC has changed to: {_currentActiveNPC.name}", ConvaiLogger.LogCategory.Character);
        }

```

---

<div class="post-metadata">

**Author:** ![K3](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.convai.com/k3/32/2611_2.png) [@K3](https://forum.convai.com/u/K3)\
**Post date:** [August 8, 2024, 8:23am UTC](https://forum.convai.com/t/handlevoiceinput-call-error/1392/13 "2024-08-08T08:23:37Z")

</div>

**Reply by k3kalinix | 2024-08-08 08:23:37**

```cs
public override void OnPointerDown(PointerEventData eventData)
        {
            base.OnPointerDown(eventData);

            ColorBlock colorBlock = colors;
            colorBlock.normalColor = new Color(colorBlock.normalColor.r, colorBlock.normalColor.g,
                colorBlock.normalColor.b,
                PRESSED_ALPHA);
            colors = colorBlock;

            if (_currentActiveNPC != null)
            {
                // _grpcAPI.InterruptCharacterSpeech();
                _currentActiveNPC.playerInteractionManager.UpdateActionConfig();
                _currentActiveNPC.StartListening();
                IncreaseScale();
                ConvaiLogger.DebugLog($"{gameObject.name} Was Clicked.", ConvaiLogger.LogCategory.Character);
            }
            else
            {
                ConvaiLogger.Warn("No active NPC found when button was pressed.", ConvaiLogger.LogCategory.Character);
            }
        }

        public override void OnPointerUp(PointerEventData eventData)
        {
            base.OnPointerUp(eventData);

            ColorBlock colorBlock = colors;
            colorBlock.normalColor =
                new Color(colorBlock.normalColor.r, colorBlock.normalColor.g, colorBlock.normalColor.b, NORMAL_ALPHA);
            colors = colorBlock;

            if (_currentActiveNPC != null)
            {
                _currentActiveNPC.StopListening();
                DecreaseScale();
                ConvaiLogger.DebugLog($"{gameObject.name} Was Released.", ConvaiLogger.LogCategory.Character);
            }
            else
            {
                ConvaiLogger.Warn("No active NPC found when button was released.", ConvaiLogger.LogCategory.Character);
            }
        }

        private void IncreaseScale()
        {
            Vector3 targetScale = new(1.25f, 1.25f, 1.25f);
            transform.localScale = Vector3.Lerp(transform.localScale, targetScale, 1f);
        }

        private void DecreaseScale()
        {
            Vector3 targetScale = new(1, 1, 1);
            transform.localScale = Vector3.Lerp(transform.localScale, targetScale, 1f);
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![K3](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.convai.com/k3/32/2611_2.png) [@K3](https://forum.convai.com/u/K3)\
**Post date:** [August 8, 2024, 8:45am UTC](https://forum.convai.com/t/handlevoiceinput-call-error/1392/14 "2024-08-08T08:45:35Z")

</div>

**Reply by or\_rmo | 2024-08-08 08:45:35**

An error occurs saying that the definition is not included.

**Images:**

 ![image.png](https://canada1.discourse-cdn.com/flex004/uploads/convai/original/2X/c/cc442600ccdd691bbdea3c412e64ea85bef0987e.png)

---

<div class="post-metadata">

**Author:** ![K3](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.convai.com/k3/32/2611_2.png) [@K3](https://forum.convai.com/u/K3)\
**Post date:** [August 8, 2024, 9:52am UTC](https://forum.convai.com/t/handlevoiceinput-call-error/1392/15 "2024-08-08T09:52:39Z")

</div>

**Reply by or\_rmo | 2024-08-08 09:52:39**

**Images:**

 ![image.png](https://canada1.discourse-cdn.com/flex004/uploads/convai/original/2X/8/84cfeed2ff2e27dff8e4a5ac5d01d417f32aa7ea.png)

---

<div class="post-metadata">

**Author:** ![K3](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.convai.com/k3/32/2611_2.png) [@K3](https://forum.convai.com/u/K3)\
**Post date:** [August 8, 2024, 9:52am UTC](https://forum.convai.com/t/handlevoiceinput-call-error/1392/16 "2024-08-08T09:52:48Z")

</div>

**Reply by k3kalinix | 2024-08-08 09:52:48**

This is from core sdk

---

<div class="post-metadata">

**Author:** ![K3](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.convai.com/k3/32/2611_2.png) [@K3](https://forum.convai.com/u/K3)\
**Post date:** [August 8, 2024, 9:52am UTC](https://forum.convai.com/t/handlevoiceinput-call-error/1392/17 "2024-08-08T09:52:56Z")

</div>

**Reply by k3kalinix | 2024-08-08 09:52:56**

So you have to remove this line

---

<div class="post-metadata">

**Author:** ![K3](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.convai.com/k3/32/2611_2.png) [@K3](https://forum.convai.com/u/K3)\
**Post date:** [August 8, 2024, 9:53am UTC](https://forum.convai.com/t/handlevoiceinput-call-error/1392/18 "2024-08-08T09:53:57Z")

</div>

**Reply by or\_rmo | 2024-08-08 09:53:57**

I removed this line and ran it, and it worked. Thank you!!

---

<div class="post-metadata">

**Author:** ![K3](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.convai.com/k3/32/2611_2.png) [@K3](https://forum.convai.com/u/K3)\
**Post date:** [August 8, 2024, 9:54am UTC](https://forum.convai.com/t/handlevoiceinput-call-error/1392/19 "2024-08-08T09:54:04Z")

</div>

**Reply by k3kalinix | 2024-08-08 09:54:04**

Amazing!

---

<div class="post-metadata">

**Author:** ![K3](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.convai.com/k3/32/2611_2.png) [@K3](https://forum.convai.com/u/K3)\
**Post date:** [August 8, 2024, 9:54am UTC](https://forum.convai.com/t/handlevoiceinput-call-error/1392/20 "2024-08-08T09:54:38Z")

</div>

**Reply by or\_rmo | 2024-08-08 09:54:38**

Thank you so much!❤

[Next page](https://forum.convai.com/t/handlevoiceinput-call-error/1392.md?page=2)
