/// <inheritdoc />
        public override void Enable()
        {
            if (!Application.isPlaying || Commands.Length == 0)
            {
                return;
            }

            InputSource = MixedRealityToolkit.InputSystem?.RequestNewGenericInputSource("Windows Speech Input Source");

            var newKeywords = new string[Commands.Length];

            for (int i = 0; i < Commands.Length; i++)
            {
                newKeywords[i] = Commands[i].Keyword;
            }

            RecognitionConfidenceLevel            = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.SpeechCommandsProfile.SpeechRecognitionConfidenceLevel;
            keywordRecognizer                     = new KeywordRecognizer(newKeywords, (ConfidenceLevel)RecognitionConfidenceLevel);
            keywordRecognizer.OnPhraseRecognized += KeywordRecognizer_OnPhraseRecognized;

            if (MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.SpeechCommandsProfile.SpeechRecognizerStartBehavior == AutoStartBehavior.AutoStart)
            {
                StartRecognition();
            }
        }
Example #2
0
 /// <summary>
 /// Populates the event with data.
 /// </summary>
 /// <param name="inputSource"></param>
 /// <param name="inputAction"></param>
 /// <param name="confidence"></param>
 /// <param name="phraseDuration"></param>
 /// <param name="phraseStartTime"></param>
 /// <param name="recognizedText"></param>
 public void Initialize(IMixedRealityInputSource inputSource, MixedRealityInputAction inputAction, RecognitionConfidenceLevel confidence, TimeSpan phraseDuration, DateTime phraseStartTime, string recognizedText)
 {
     BaseInitialize(inputSource, inputAction);
     Confidence      = confidence;
     PhraseDuration  = phraseDuration;
     PhraseStartTime = phraseStartTime;
     RecognizedText  = recognizedText;
 }
 /// <summary>
 /// Populates the event with data.
 /// </summary>
 public void Initialize(IMixedRealityInputSource inputSource, RecognitionConfidenceLevel confidence, TimeSpan phraseDuration, DateTime phraseStartTime, SpeechCommands command)
 {
     BaseInitialize(inputSource, command.Action);
     Confidence      = confidence;
     PhraseDuration  = phraseDuration;
     PhraseStartTime = phraseStartTime;
     Command         = command;
 }
Example #4
0
        private void InitializeKeywordRecognizer()
        {
            //ManualList m_ManualList = SpeechInputManager2.Instance.ManualList;

            string manualJson = "";
            var    textAsset  = Resources.Load("Manual") as TextAsset;

            manualJson = textAsset.text;
            ManualList m_ManualList = JsonUtility.FromJson <ManualList>(manualJson);

            m_SpeechCommandsArray = Commands;
            foreach (var val in m_ManualList.list[0].manual[0].operation)
            {
                SpeechCommands m_SpeechCommands = new SpeechCommands(val.kaiheikikana, KeyCode.B, MixedRealityInputAction.None, null);
                Array.Resize(ref m_SpeechCommandsArray, m_SpeechCommandsArray.Length + 1);
                m_SpeechCommandsArray[m_SpeechCommandsArray.Length - 1] = m_SpeechCommands;
            }

            if (!Application.isPlaying ||
                (m_SpeechCommandsArray == null) ||
                (m_SpeechCommandsArray.Length == 0) ||
                InputSystemProfile == null ||
                keywordRecognizer != null
                )
            {
                return;
            }

            InputSource = Service?.RequestNewGenericInputSource("Windows Speech Input Source", sourceType: InputSourceType.Voice);

            var newKeywords = new string[m_SpeechCommandsArray.Length];

            for (int i = 0; i < m_SpeechCommandsArray.Length; i++)
            {
                newKeywords[i] = m_SpeechCommandsArray[i].LocalizedKeyword;
            }

            RecognitionConfidenceLevel = InputSystemProfile.SpeechCommandsProfile.SpeechRecognitionConfidenceLevel;

            try
            {
                keywordRecognizer = new KeywordRecognizer(newKeywords, (ConfidenceLevel)RecognitionConfidenceLevel);
            }
            catch (Exception ex)
            {
                Debug.LogWarning($"Failed to start keyword recognizer. Are microphone permissions granted? Exception: {ex}");
                keywordRecognizer = null;
                return;
            }

            keywordRecognizer.OnPhraseRecognized += KeywordRecognizer_OnPhraseRecognized;
        }
        private void OnPhraseRecognized(RecognitionConfidenceLevel confidence, TimeSpan phraseDuration, DateTime phraseStartTime, string text)
        {
            IMixedRealityInputSystem inputSystem = Service as IMixedRealityInputSystem;

            for (int i = 0; i < Commands?.Length; i++)
            {
                if (Commands[i].LocalizedKeyword.ToUpper() == text.ToUpper())
                {
                    inputSystem?.RaiseSpeechCommandRecognized(InputSource, confidence, phraseDuration, phraseStartTime, Commands[i]);
                    break;
                }
            }
        }
Example #6
0
        /// <inheritdoc />
        public override void Enable()
        {
            if (!Application.isPlaying ||
                (Commands == null) ||
                (Commands.Length == 0))
            {
                return;
            }

            if (InputSystemProfile == null)
            {
                return;
            }

            IMixedRealityInputSystem inputSystem = Service as IMixedRealityInputSystem;

            InputSource = inputSystem?.RequestNewGenericInputSource("Windows Speech Input Source", sourceType: InputSourceType.Voice);

            var newKeywords = new string[Commands.Length];

            for (int i = 0; i < Commands.Length; i++)
            {
                newKeywords[i] = Commands[i].LocalizedKeyword;
            }

            RecognitionConfidenceLevel = InputSystemProfile.SpeechCommandsProfile.SpeechRecognitionConfidenceLevel;

            if (keywordRecognizer == null)
            {
                try
                {
                    keywordRecognizer = new KeywordRecognizer(newKeywords, (ConfidenceLevel)RecognitionConfidenceLevel);
                }
                catch (UnityException ex)
                {
                    Debug.LogWarning($"Failed to start keyword recognizer. Are microphone permissions granted? Exception: {ex}");
                    keywordRecognizer = null;
                    return;
                }

                keywordRecognizer.OnPhraseRecognized += KeywordRecognizer_OnPhraseRecognized;
            }

            if (InputSystemProfile.SpeechCommandsProfile.SpeechRecognizerStartBehavior == AutoStartBehavior.AutoStart)
            {
                StartRecognition();
            }
        }
Example #7
0
        private void InitializeKeywordRecognizer()
        {
            if (!Application.isPlaying ||
                InputSystemProfile == null ||
                keywordRecognizer != null)
            {
                return;
            }

            SpeechCommands[] commands = Commands;
            int commandsCount         = commands?.Length ?? 0;

            if (commandsCount == 0)
            {
                return;
            }

            globalInputSource = Service?.RequestNewGlobalInputSource("Windows Speech Input Source", sourceType: InputSourceType.Voice);

            var newKeywords = new string[commandsCount];

            for (int i = 0; i < commandsCount; i++)
            {
                newKeywords[i] = commands[i].LocalizedKeyword;
            }

            RecognitionConfidenceLevel = InputSystemProfile.SpeechCommandsProfile.SpeechRecognitionConfidenceLevel;

            try
            {
                keywordRecognizer = new KeywordRecognizer(newKeywords, (ConfidenceLevel)RecognitionConfidenceLevel);
            }
            catch (Exception ex)
            {
                // Don't log if the application is currently running in batch mode (for example, when running tests). This failure is expected in this case.
                if (!Application.isBatchMode)
                {
                    Debug.LogWarning($"Failed to start keyword recognizer. Are microphone permissions granted? Exception: {ex}");
                }
                keywordRecognizer = null;
                return;
            }

            keywordRecognizer.OnPhraseRecognized += KeywordRecognizer_OnPhraseRecognized;
        }
Example #8
0
        private void InitializeKeywordRecognizer()
        {
            if (!Application.isPlaying ||
                (Commands == null) ||
                (Commands.Length == 0) ||
                InputSystemProfile == null ||
                keywordRecognizer != null
                )
            {
                return;
            }

            InputSource = Service?.RequestNewGenericInputSource("Windows Speech Input Source", sourceType: InputSourceType.Voice);

            var newKeywords = new string[Commands.Length];

            for (int i = 0; i < Commands.Length; i++)
            {
                newKeywords[i] = Commands[i].LocalizedKeyword;
            }

            RecognitionConfidenceLevel = InputSystemProfile.SpeechCommandsProfile.SpeechRecognitionConfidenceLevel;

            try
            {
                keywordRecognizer = new KeywordRecognizer(newKeywords, (ConfidenceLevel)RecognitionConfidenceLevel);
            }
            catch (Exception ex)
            {
                Debug.LogWarning($"Failed to start keyword recognizer. Are microphone permissions granted? Exception: {ex}");
                keywordRecognizer = null;
                return;
            }

            keywordRecognizer.OnPhraseRecognized += KeywordRecognizer_OnPhraseRecognized;
        }