- Home /
Speech Recognition in background doesn't work correctly!
I am making a desktop application that needs to run in the background and the user can just say "Show me dog images" and it will pull up chrome with dog images.
But every time the chrome tab appears, speech recognition doesn't listen to user input anymore.
Sometime after the chrome tab opens I can say the command one more time and then it always stops listening after that.
I have (Run in Background) checked in player settings.
And when the application is in focus, it will continue to recognize everything I say, but once it is not in focus it doesn't work after some time.
Please help.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Windows.Speech;
using System.Linq;
public class Recognition : MonoBehaviour
{
public KeywordRecognizer keywordRecognizer;
public Dictionary<string, System.Action> keywords = new Dictionary<string, System.Action>();
void Start()
{
keywords.Add("open unity", () => { OpenUnityMethod(); });
keywordRecognizer = new KeywordRecognizer(keywords.Keys.ToArray());
keywordRecognizer.OnPhraseRecognized += KeywordRecognizerOnPhraseRecognize;
keywordRecognizer.Start();
}
void Update()
{
}
void KeywordRecognizerOnPhraseRecognize(PhraseRecognizedEventArgs args)
{
System.Action keywordAction;
if (keywords.TryGetValue(args.text, out keywordAction))
{
keywordAction.Invoke();
}
}
void OpenUnityMethod()
{
Application.OpenURL("http://unity3d.com/");
}
}
Answer by lwwwwww · Oct 21, 2018 at 11:10 AM
I have the same problem。 Did you solve the problem?
Well, I figured out why it does that. When you don't use one of the unity's components like audio source, background doesn't really work the way it should. When you do use audio source in the background to record speech it works perfectly but I don't know how to get that audio source into the speech recognition. What I did find was that google speech API allows you to pass in audio which will then work in the background.
Your answer
![](https://koobas.hobune.stream/wayback/20220612173052im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Microphone Input In Background 0 Answers
Oculus Quest Speech to Text API/SDKs that work 0 Answers
Code works in unity but throws errors in iOS. 0 Answers