Search Unity

Question How can you compare words (Speech Recognizer)?

Discussion in 'Scripting' started by LetmeDwight, Jan 12, 2021.

  1. LetmeDwight

    LetmeDwight

    Joined:
    Apr 9, 2020
    Posts:
    125
    my code with windows.speech, but I want to use it for android:
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Windows.Speech;
    3.  
    4. public class Spieler_WoerterErkennung : MonoBehaviour
    5. {
    6.     private AudioSource Audioquelle;
    7.  
    8.     [SerializeField]
    9.     private string[] m_Keywords;
    10.     private KeywordRecognizer m_Recognizer;
    11.     private int zufall;
    12.  
    13.     void Start()
    14.     {
    15.         Audioquelle = GetComponent<AudioSource>();
    16.  
    17.         m_Recognizer = new KeywordRecognizer(m_Keywords);
    18.         m_Recognizer.OnPhraseRecognized += OnPhraseRecognized;
    19.         m_Recognizer.Start();
    20.     }
    21.  
    22.     private void OnPhraseRecognized(PhraseRecognizedEventArgs args)
    23.     {
    24.         if (!Audioquelle.isPlaying)
    25.         {
    26.             // If the player says the same words like in Array '0', this if will be executed:
    27.             if (args.text == m_Keywords[0])
    28.             {
    29.         Debug.Log("the same words");
    30.             }
    31.         }
    32.  
    33.     }
    34.  
    35.  
    36.  
    37.  
    38. }

    So far I have only worked with the Windows Speech Rechonizer in Unity, but did not consider that it might not work as soon as I try to export the application as an Android apk. that's why I've been looking for days and only found this video as a half-hearted solution. everything else is otherwise too expensive or too complicated. Is there a way how I can match words as templates in an if, as I have already done with Windows.speech? Because when I say the words: "Hellow how are you" into the microphone, an if should execute a Debug.Log to show that it has understood the words as these. But how do I do that if I can't use windows.speech because I'm making an app for android? I tried to orientate myself on this video, but it does not show in the video how to query the spoken words as an if with a prepared sentence by me, with which the spoken words are compared so that if they match the Debug.Log command is executed.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,698
    I suspect all this sorta "soft learning ML AI type stuff" is just going to the cloud.

    There's probably a way with making a Google app on their back end, something to use their speech-to-text features.

    I imagine you'd capture the audio, blast it to Google, they'd send you back some text.
     
  3. LetmeDwight

    LetmeDwight

    Joined:
    Apr 9, 2020
    Posts:
    125
    Can you recommend me a Unity Asset Store Asset with this feature to make a speek regognisation and compare it in a if Statement of the same words?
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,698
    I would start by looking in Google. Conveniently you can do so yourself, leaving me free to continue. Good luck!