romanws
Member
- Joined
- Mar 10, 2021
- Messages
- 5
- Programming Experience
- 1-3
Hey guys, I´m working on a Virtual Assistant calculator on C# with Visual Stuido. No errors appear but still when I say the assigned activation work nothing happens. I would really appreciate your help.
This is my code...
This is my code...
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.IO;
using System.Speech.Recognition;
using System.Speech.Synthesis;
namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SpeechSynthesizer ss = new SpeechSynthesizer();
SpeechRecognitionEngine ta = new SpeechRecognitionEngine();
PromptBuilder pb = new PromptBuilder();
private void Form1_Load(object sender, EventArgs e)
{
}
private void Speak_Click(object sender, EventArgs e)
{
ss.SelectVoiceByHints(VoiceGender.Male);
Choices list = new Choices();
list.Add(File.ReadAllLines(@"C:\Users\Corporativo Isakar\OneDrive\Escritorio\George\georgecommands"));
Grammar gr = new Grammar(new GrammarBuilder(list));
try
{
ta.RequestRecognizerUpdate();
ta.LoadGrammar(gr);
ta.SpeechRecognized += Ta_SpeechRecognized;
ta.SetInputToDefaultAudioDevice();
ta.RecognizeAsync(RecognizeMode.Multiple);
}
catch
{
return;
}
pb.ClearContent();
pb.AppendText(richTextBox1.Text);
ss.Speak(pb);
}
public void Say(string phrase)
{
ss.SpeakAsync(phrase);
}
private void Ta_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
string speechSaid = e.Result.Text;
switch (speechSaid)
{
case ("hey"):
Say("good morning sir");
break;
}
}
private void RichTextBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
Last edited by a moderator: