My c# assistant is not working :(

TheDarightComputer

New member
Joined
Mar 7, 2021
Messages
1
Programming Experience
Beginner
C#:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Speech.Synthesis;
using System.Speech.Recognition;
using System.IO;
using System.Threading;

namespace HeyAI
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        SpeechSynthesizer s = new SpeechSynthesizer();
        SpeechRecognitionEngine sr = new SpeechRecognitionEngine();
        PromptBuilder pb = new PromptBuilder();
        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void btnSpeak_Click(object sender, EventArgs e)
        {
            s.SelectVoiceByHints(VoiceGender.Female);
            Choices list = new Choices();
            list.Add(File.ReadAllLines("C:\\ProgramData\\HeyAI\\commands\\cmds.txt"));

            Grammar gm = new Grammar(new GrammarBuilder(list));

            try
            {
                sr.RequestRecognizerUpdate();
                sr.LoadGrammar(gm);
                sr.SpeechRecognized += sr_SpeechRecognized;
                sr.SetInputToDefaultAudioDevice();
                sr.RecognizeAsync(RecognizeMode.Multiple);
                
            }
            catch
            {
                return;
                pb.ClearContent();
                pb.AppendText(rtbOutput.Text);
                s.Speak(pb);
                
            }
            
        }

        public void Say(string phrase)
        {
            s.SpeakAsync(phrase);
        }
              private void sr_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
           string speechsaid  = e.Result.Text;

            switch (speechsaid)
            {
                case ("hi"):
                    Say("hello");
                    
                    break;
                case ("how are you doing"):
                    Say("good, how about you");
                    break;
            }
        }
    }
}
 

Attachments

  • HeyAI.txt
    35 bytes · Views: 8
  • c#assistant.zip
    36.9 KB · Views: 8

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
4,414
Location
Sydney, Australia
Programming Experience
10+
Your post is of very poor quality. A title that tells us nothing and a post with some code and a couple of attachments is unacceptable. You need to provide a FULL and CLEAR explanation of the problem. That means taking the time and making the effort to explain what you're trying to achieve, how you're trying to achieve it and what actually happens when you try. You need to point out where in the code the issue occurs and the specific nature of the issue. If you don't know those things then you need to spend more time working on it yourself first. That means debugging the code and working exactly where and how it doesn't behave as expected. Once you can provide all that information, then you have something that we can help you with. The title should also summarise the actual issue.
 
Top Bottom