UWP Continuous Vouce in Published App

Paul Ryan 316 Reputation points
2022-11-13T15:55:05.47+00:00

Hi,
VS 2022, Win 11 Home build 22621.819
The below works in Debug and Release testing, however when I publish the Application it fails to stop Continuous Voice. I have narrowed it down to the while loop does not pick change "StaticVariables.ContinuousVoice " The variable is changed

Should I be doing something different?

thanks

 public async Task SpeechContinuousMicAsync()  
        {  
            StaticVariables.VoiceText = " ";  
            StaticVariables.ContinuousVoice = true;  
            speechconfig = SpeechConfig.FromSubscription(Names.VoiceKey, Names.VoiceRegion);  
            speechconfig.EnableDictation();  
  
            StaticVariables.LogM = new() { Category = "VOICE", Action = "Before Using", SubAction = " " };  
            LogWriteLine();  
  
            // Creates a speech recognizer from microphone.  
            using (var recognizer = new SpeechRecognizer(speechconfig, audioConfig))  
            {  
                var phraseList = PhraseListGrammar.FromRecognizer(recognizer);  
                phraseList.Clear();  
                phraseList.AddPhrase("sedentary");  
                // Subscribes to events.  
                recognizer.Recognizing += (s, e) =>  
                {  
                    // StaticVariables.VoiceText += e.Result.Text;  
                };  
  
                recognizer.Recognized += (s, e) =>  
                {  
                    StaticVariables.VoiceText += $"{e.Result.Text} ";  
                    StaticVariables.LogM = new() { Category = "VOICE", Action = "In Recognized:", SubAction = StaticVariables.ContinuousVoice.ToString() };  
                    LogWriteLine();  
  
                };  
  
                recognizer.Canceled += (s, e) =>  
                {  
                    Console.WriteLine($"\n    Canceled. Reason: {e.Reason.ToString()}, CanceledReason: {e.Reason}");  
                    StaticVariables.LogM = new() { Category = "VOICE", Action = "Canceled Reason:", SubAction = e.Reason.ToString() };  
                    LogWriteLine();  
                };  
  
                recognizer.SessionStarted += (s, e) =>  
                {  
                    Console.WriteLine("\n    Session started event.");  
                    StaticVariables.LogM = new() { Category = "VOICE", Action = "Session started event", SubAction = " " };  
                    LogWriteLine();  
                };  
  
                recognizer.SessionStopped += (s, e) =>  
                {  
  
                    Console.WriteLine("\n    Session stopped event.");  
                    StaticVariables.LogM = new() { Category = "VOICE", Action = "Session stopped event", SubAction = " " };  
                    LogWriteLine();  
                };  
  
                // Starts continuous recognition.   
                // Uses StopContinuousRecognitionAsync() to stop recognition.  
                await recognizer.StartContinuousRecognitionAsync().ConfigureAwait(false);  
                StaticVariables.LogM = new() { Category = "VOICE", Action = "Before Do Loop ", SubAction = StaticVariables.VoiceText };  
                LogWriteLine();  
                do  
                {   
  
                } while (StaticVariables.ContinuousVoice == true);  
                // Stops recognition.  
                await recognizer.StopContinuousRecognitionAsync().ConfigureAwait(false);  
                StaticVariables.LogM = new() { Category = "VOICE", Action = "After await Stop", SubAction = StaticVariables.VoiceText };  
                LogWriteLine();  
  
            }  
        }  

the above is called using the below

 switch (btn.Tag.ToString())  
            {  
                case "VoiceOn":  
                    MicOn.Visibility = Visibility.Collapsed;  
                    MicOff.Visibility = Visibility.Visible;  
                    await vtext.SpeechContinuousMicAsync();  
                    StaticVariables.LogM = new() { Category = "VOICE", Action = "After await Stop", SubAction = StaticVariables.VoiceText };  
                    logC.LogWriteLine();  
                    newCase.CaseDescription = StaticVariables.VoiceText;  
                    break;  
                case "VoiceOff":  
                    MicOn.Visibility = Visibility.Visible;  
                    MicOff.Visibility = Visibility.Collapsed;  
                    StaticVariables.ContinuousVoice = false;  
                    StaticVariables.LogM = new() { Category = "VOICE", Action = "After setting false", SubAction = StaticVariables.ContinuousVoice.ToString() };  
                    logC.LogWriteLine();  
Universal Windows Platform (UWP)
{count} votes

1 answer

Sort by: Most helpful
  1. Paul Ryan 316 Reputation points
    2023-01-05T14:20:52.53+00:00

    I created a simple UWP and it worked, I cloud not re-produce the issue

    Paul

    0 comments No comments