Voice recognition using System.Speech not working correctly - c#

I have been trying to experiment with the system.speech feature I have seen various online videos and web articles teaching how to properly use it, but I can't get it to work somehow. I get no errors, the program compiles as it should but when I speak nothing happens, I have tried changing my language to en-UK and back to en-US but it did nothing. I am using VS17 and the code is as follows:
SpeechRecognitionEngine recEngine = new SpeechRecognitionEngine(new CultureInfo("en-US"));
public Form1()
{
InitializeComponent();
this.TransparencyKey = (BackColor);
this.StartPosition = FormStartPosition.Manual;
this.Location = new Point(Convert.ToInt32(0.10), 300);
textBox1.Visible = false;
}
private void Form1_Load(object sender, EventArgs e)
{
Choices commands = new Choices();
commands.Add(new string[] { "hello" });
GrammarBuilder gr = new GrammarBuilder();
gr.Append(commands);
Grammar grammar = new Grammar(gr);
recEngine.LoadGrammarAsync(grammar);
recEngine.SetInputToDefaultAudioDevice();
recEngine.SpeechRecognized += RecEngine_SpeechRecognized;
}
private void RecEngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
switch (e.Result.Text)
{
case "hello":
MessageBox.Show("Hello");
break;
}
}
private void label1_Click(object sender, EventArgs e)
{
}
private void pictureBox2_Click(object sender, EventArgs e)
{
recEngine.RecognizeAsyncStop();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
void button1_Click(object sender, EventArgs e)
{
recEngine.RecognizeAsync(RecognizeMode.Multiple);
}
}
Edit: I downloaded and tested the program with the same code below on 2 different computers and it works fine with all of them except this one. I tried to use the mic of both computers which recognized my speech. But none of them worked, so the problem lies within my PC after all, I might have to download some windows update with the speech feature or something like that. Where can I find it though?

Apparently running as an admin fixed the issue.
Somehow this thought never even reached my mind.

Related

Windows forms not rendering buttons, images, launching application at runtime - C#

I'm having this issue for a while now on some machines, when the user runs the application all the buttons, images, menu items, almost everything goes blank.
My first thought was: I have a separate thread using BackgroundWorker updating a StatusBar and I've read that this can cause issues to form rendering.
I found an article (it's in portuguese, since I'm a Brazilian) that explains this is a issue caused by a security plugin installed by our banks called Warsaw. One of the solutions was to contact the developers to have them analyze your software so the plugin will work correctly. I've done this and I'm waiting for their response.
The other solution is to sign our assembiles so the plugin may recognize as a trusted software, this is good but not free of charge unfortunately.
Now, here's an example of my application looks like when it's launched with this issue:
A form with a GridView
The code for the separate thread as mentioned above:
int countAlerta = 0;
int countAlertaRFRP = 0;
int countAlertaAditivo = 0;
private void timer1_Tick(object sender, EventArgs e)
{
if (!backgroundWorker1.IsBusy)
backgroundWorker1.RunWorkerAsync();
else
{
alertaToolStripStatusLabel.Text = "Continuando a verificação...";
alertaToolStripStatusLabel.IsLink = false;
}
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
backgroundWorker1.ReportProgress(0);
timer1.Enabled = false;
lock (new object())
{
countAlerta = new BLL.AlertasBLL().CountRVSRAS();
countAlertaRFRP = new BLL.AlertasBLL().CountRFRP();
countAlertaAditivo = new BLL.AlertasBLL().CountAditivos();
}
backgroundWorker1.ReportProgress(100);
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
alertaToolStripStatusLabel.Text = "Verificando...";
alertaToolStripStatusLabel.IsLink = false;
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (countAlerta + countAlertaAditivo + countAlertaRFRP > 0)
{
alertaToolStripStatusLabel.Text = "ALERTA: Verifique!!!";
alertaToolStripStatusLabel.IsLink = true;
alertaToolStripStatusLabel.Font = new Font(alertaToolStripStatusLabel.Font, FontStyle.Bold);
}
else
{
alertaToolStripStatusLabel.Text = "Não existem alertas";
alertaToolStripStatusLabel.IsLink = false;
}
timer1.Enabled = true;
}

GlobalHotKey not firing any events

I googled around to find a way to have a GlobalHotKey on my C# Winform.
I saw this tutorial and followed it.
The issue I'm having now is that nothing is occurring once I press the designated key.(In this case, the ` key)
Here is the class I'm using
Here is the relevant code on my Form1.cs
Hotkey hk = new Hotkey();
private void Form1_Load(object sender, EventArgs e)
{
hk.KeyCode = Keys.Oemtilde;
hk.Windows = true;
hk.Pressed += hk_Pressed;
hk.Register(this);
}
private void hk_Pressed(object sender, EventArgs e)
{
MessageBox.Show("pressed");
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (hk.Registered)
{ hk.Unregister(); }
}
Because you set hk.Windows = true; which required you to press Windows+ ``, remove that line and press `, it will work

Continuous Playing of Different Video Files in a VLC Playlist

I am trying to play different video files continuously on VLC player on my Winform application.
The problem I face is between different playlist videos there is a 1-2 seconds of black screen.
How can I play all videos in my playlist smoothly without any waiting?
private void buttonLoad_Click(object sender, EventArgs e)
{
var uri = new Uri(#"C:\Users\Val\Downloads\000013.ts");
var converted = uri.AbsoluteUri;
var uri2 = new Uri(#"C:\Users\Val\Downloads\000210.ts");
var converted2 = uri2.AbsoluteUri;
axVLCPlugin21.playlist.add(converted);
axVLCPlugin21.playlist.add(converted2);
}
private void buttonStart_Click(object sender, EventArgs e)
{
axVLCPlugin21.MediaPlayerEndReached += new EventHandler(OnTimedEvent);
axVLCPlugin21.playlist.playItem(0);
}
private void OnTimedEvent(object sender, EventArgs e)
{
axVLCPlugin21.playlist.playItem(1);
}
this is a simplified version of what I am trying to do.
When the player reaches end of the first video file it starts the second on by eventhandler function.
The best way I know to play videos seamlessly is to avoid the timed event in your example:
private void buttonLoad_Click(object sender, EventArgs e)
{
var uri = new Uri(#"C:\Users\Val\Downloads\000013.ts");
var converted = uri.AbsoluteUri;
var uri2 = new Uri(#"C:\Users\Val\Downloads\000210.ts");
var converted2 = uri2.AbsoluteUri;
axVLCPlugin21.playlist.add(converted);
axVLCPlugin21.playlist.add(converted2);
}
private void buttonStart_Click(object sender, EventArgs e)
{
axVLCPlugin21.playlist.play();
}

Error while using webbrowser

So I want to use a webbrowser to show an html file, and print it. I can load the file, but when I try to use webBrowser1.ShowPrintDialog(); I have a script error. I tried to disable this with webBrowser1.ScriptErrorsSuppressed = true; but it doesn't work.
The weird part is that when I run my code in debug(F5), it works, but not in "normal" mode (Ctrl + F5).
My code so far is very simple:
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.Navigate("http://google.com");
}
private void button1_Click(object sender, EventArgs e)
{
webBrowser1.ScriptErrorsSuppressed = true;
webBrowser1.ShowPrintDialog();
}

Displaying corresponding text relating to check box names in Word 2010 and visual Studio 2010 that is removed when box is unchecked?

The code im currently using in Visual Studio to populate a text field when check boxes are clicked on is:
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
this.displayText.Text += "Internal Use";
}
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
this.displayText.Text += "Company Confidential";
}
private void checkBox3_CheckedChanged(object sender, EventArgs e)
{
this.displayText.Text += "Customer Confidential";
}
private void checkBox4_CheckedChanged(object sender, EventArgs e)
{
this.displayText.Text += "Strictly Confidential";
}
This is fine but i'd like the text to be removed when the boxes are not checked. Does anybody have any insight into the specific code that I might need to make this requirement functional?
Many thanks in advance.
Do you mean something like
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
this.displayText.Text = "Internal Use";
else
this.displayText.Text = String.Empty;
}
And are you sure this isn't C# you're talking about?

Categories