0

Right now I'm trying to create a voice recognition assistant (basically a JARVIS program) using c#. I started off writing the code in visual studio, and once the code was working, I moved over to expression blend to work on the UI.

I've successfully imported the images and animated them on a loop. At that point, when I ran the program, everything worked (animations and speech recognition included). My next step was then to try and "replace" the standard window with the images I had just imported by setting the standard window to transparent. Using the panes, I then set all the brushes to "no brush," and I set allowstransparency to "true." When I ran the program, the animations still worked but the program stopped running all of the voice recognition code.

Through the process of elimination, I've isolated the problem to the background brush and the allowstransparency function. If I either set the allowstransparency to true or mess with the background brush in any way, there's no more speech recognition.

I'm new to coding, so the only reason I can think of (and I don't even know if this is the reason) is that the speech recognition directory and functions are mapped to the window.

Is there any reason for why this is happening/is there a fix?


EDIT: Code added

    public MainWindow()
    {
        InitializeComponent();
        Loaded += MainWindow_Loaded;
    }

    private void MainWindow_Loaded(object sender, EventArgs e)
    {
        _recognizer.SetInputToDefaultAudioDevice();
        _recognizer.LoadGrammar(new Grammar(new GrammarBuilder(new Choices(File.ReadAllLines(@"C:\users\username\Documents\commands.txt")))));
        _recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(_recognizer_SpeechRecognized);
        _recognizer.RecognizeAsync(RecognizeMode.Multiple);
    }
    void _recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
    {
        int ranNum = rnd.Next(1, 10);
        string speech = e.Result.Text;
        switch (speech)
        {
            //INTERACTIONS
            case "hello":

...and so on

  • I don't understand when you say, ""replace" the standard window with the images I had just imported by setting the standard window to transparent." How can you replace a window with images? Do you mean you are setting the background to an image? – Daniel Ward Jun 11 '14 at 22:05
  • When the program runs, I want the UI to only display the animation and not the window. Specifically, the image (which is circular in shape) is going to serve as the main window. This is why I set the window to transparent so that only the images would be visible. – user3731896 Jun 11 '14 at 22:11
  • I see. Like a splash? – Daniel Ward Jun 11 '14 at 22:13
  • I suppose in appearance only, if that makes sense. I'm not trying to create a loading screen. – user3731896 Jun 11 '14 at 22:17
  • [This](http://stackoverflow.com/questions/48916/multi-threaded-splash-screen-in-c/3296362#3296362) might help. You can also search along the lines of "WPF animated splash screen" and a good number of guides show up. – Daniel Ward Jun 11 '14 at 22:43

1 Answers1

0

You need to complete four steps to make your window "Disappear":

  1. Window.WindowStyle set equal to "None."
  2. Window.Background set equal to "Transparent"
  3. Window.BorderThickness set equal to "0"
  4. Window.AllowsTransparency set equal to "True"

I see no reason for your speech recognition to be tied to the Window appearance, but you need to post some code; initialization code, and some example usage would probably be very useful in diagnosing the rest of the issue.

If you need the user to click on pieces of the user interface, you may need to set the Background to an "almost transparent" color, instead of a pure transparent brush. The reason for this is; when a background is purely "Transparent," it no longer detects click events - it treats the background as though it is no longer there.

You could try something like this:

Background="#01000000"

You will also probably want to keep a reference to the Task which (I assume) is returned by your RecognizeAsync method call; no telling when that might be inadvertently garbage-collected.

BTownTKD
  • 7,911
  • 2
  • 31
  • 47
  • I've made the window disappear, but the problem is all the other code except for the animations stop working. I've edited my question with the code. – user3731896 Jun 12 '14 at 14:08