System.UnauthorizedAccessException' occurred in System.Speech.dll - c#

I recive this error 'System.UnauthorizedAccessException' occurred in System.Speech.dll ' and yes I read all questions about this error, but any can fixed my error, please help me, I have the next code:
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.Recognition;
using System.Speech.Synthesis;
using System.IO;
using System.Security.Permissions;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
String speech;
SpeechRecognitionEngine reconocedor = new SpeechRecognitionEngine();
SpeechSynthesizer AVJarvis = new SpeechSynthesizer();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
AVJarvis.Speak("Iniciando");
AVJarvis.Speak("Buenos días Kevin");
CargarGramatica();
}
void CargarGramatica()
{
reconocedor.LoadGrammarAsync(new Grammar(new GrammarBuilder(new Choices(File.ReadAllLines("ComandosDefecto.txt"))))); //Cargo los comandos del .txt
//reconocedor.LoadGrammarAsync(new DictationGrammar()); //Carga todas las gramaticas de mi sistema
reconocedor.SpeechRecognized += reconocedor_SpeechRecognized;
reconocedor.SetInputToDefaultAudioDevice();
reconocedor.RecognizeAsync(RecognizeMode.Multiple);
}
void reconocedor_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
speech = e.Result.Text;
switch (speech)
{
case "Buenos días Asistente":
AVJarvis.Speak("Buenos días Kevin");
break;
default:
break;
}
}
}
}Image

Related

Blank Form in C# using speech.recognition

Hi i have situation here i don't know how to solve this. This code is fine with 0 Errors but whenever i do F5 it shows me a blank form with no voice and no recognition please help . Please i really need help can someone help me please.
Now this line is only for "it look like your post is mostly code; please add some more details";
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.Threading;
namespace a.i
{
public partial class Form1 : Form
{
SpeechSynthesizer s = new SpeechSynthesizer();
Choices list = new Choices();
public Form1()
{
SpeechRecognitionEngine rec = new SpeechRecognitionEngine();
list.Add(new String[] { "hello", "how are you" });
Grammar gr = new Grammar(new GrammarBuilder(list));
try
{
rec.RequestRecognizerUpdate();
rec.LoadGrammar(gr);
rec.SpeechRecognized += rec_SpeachRecognized;
rec.SetInputToDefaultAudioDevice();
rec.RecognizeAsync(RecognizeMode.Multiple);
}
catch { return; }
s.SelectVoiceByHints(VoiceGender.Neutral);
s.Speak("Hello, my name is Gabriel ChatterBot");
InitializeComponent();
}
public void say(string h)
{
s.Speak(h);
}
private void rec_SpeachRecognized(object sender, SpeechRecognizedEventArgs e)
{
String r = e.Result.Text;
//what you say
if (r == "hello")
{
// what it says
say("hi");
}
//what you say
if (r == "how are you")
{
// what it says
say("Great, and you!");
}
}
}
}
From the exception you posted, I think that you have not initionalized the Grammar and SpeechRecognitionEngine correctly. It seems that you need to specify a language / culture for it. From the documentation at:
https://msdn.microsoft.com/en-us/library/hh378426(v=office.14).aspx
// Create a new SpeechRecognitionEngine instance.
SpeechRecognitionEngine sre = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US"));

Serial Port Reading into TextBox

my eventual aim is to receive data and display it as both a graph and in individual text boxes (or something better!) the data is 2 x temperature readings and a humidity reading, for example the data sent would be "222160" etc.
However before I even tackle that I am having issues simply showing any data in a textbox. This is the code I am using; (Consists of a textbox for the UI)
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.Ports;
using System.Threading;
namespace WFARxSimple
{
public partial class Form1 : Form
{
string rxString;
public Form1()
{
InitializeComponent();
myport = new SerialPort();
myport.PortName = "COM5";
myport.BaudRate = 9600;
myport.Parity = Parity.None;
myport.DataBits = 8;
myport.StopBits = StopBits.One;
myport.Open();
}
private SerialPort myport;
private void DisplayText(object sender, EventArgs e)
{
showRx.AppendText(rxString);
}
private void myPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
rxString = myport.ReadExisting();
this.Invoke(new EventHandler(DisplayText));
}
}
}
However I cannot get any data to show in my textbox.
You need, at the very least: myPort.DataReceived += myPort_DataReceived;. Do this in Form1().

getting Exception in HaarCascade.cs file using Emgucv

I am showing a simple version of my project which i am trying to develop.I continuously getting error in haarCascade.cs that TypeIntilizationException was unhandled.This is my code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.Structure;
using Emgu.Util;
using Emgu.CV.CvEnum;
using System.IO;
namespace Browseface
{
public partial class Form1 : Form
{
private HaarCascade haar;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
haar = new HaarCascade(#"C:\Users\Balram\Desktop\Frontal Face HaarCascades\Frontal Face HaarCascades\haarcascade_frontalface_alt_tree.xml");
}
catch (Exception ae)
{
}
}
private void button1_Click(object sender, EventArgs e)
{
try
{
Image inputimg = Image.FromFile(#"C:\Users\Balram\Desktop\ad.jpg");
Image<Bgr, byte> imageframe = new Image<Bgr, byte>(new Bitmap(inputimg));
if (imageframe != null)
{
Image<Gray, byte> grayform = imageframe.Convert<Gray, byte>();
var faces =
grayform.DetectHaarCascade(haar, 1.4, 4, HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(25, 25))[0];
foreach (var face in faces)
{
imageframe.Draw(face.rect, new Bgr(Color.Green), 3);
}
pictureBox1.Image = imageframe.ToBitmap();
}
}
catch (Exception at)
{
}
}
}
}
In my HaarCascade.cs file in this following line i getting an error
protected override void DisposeObject()
{
CvInvoke.cvReleaseHaarClassifierCascade(ref _ptr);
}
That TypeIntilizationException was unhandled.
(I already add in references Emgu.CV ,Emgu.CV.UI and Emgu.util dll files

voice recognition program using C#

Im trying to build a voice recognition program based on this link :
https://www.youtube.com/watch?v=OJdVfwiTIXE
The problem is..When I run the windows form after compiling, it is not recognizing and responding to my voice commands...I am using .NET framework 4 client profile for this project. I made reference only to "system.speech" and Im using the build in microphone of my laptop for voice input..
Here is my text file(i wrote it line by line from the first line):
hi
hello henry
close
close henry
Here is my code so far :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.IO;
namespace Henry
{
public partial class Form1 : Form
{
SpeechRecognitionEngine _recognizer = new SpeechRecognitionEngine();
SpeechSynthesizer Henry = new SpeechSynthesizer();
Random rnd = new Random();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
_recognizer.SetInputToDefaultAudioDevice();
_recognizer.LoadGrammar(new Grammar(new GrammarBuilder(new Choices(File.ReadAllLines(#"C:\Henry\com.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)
{
//GREETINGS
case "hi":
case "hello henry":
if (ranNum < 6) { Henry.Speak("Hello sir"); }
else if (ranNum > 5) { Henry.Speak("Hi"); }
break;
case "close":
case "close henry":
Henry.Speak("Until next time");
Close();
break;
}
}
}
}

How can I use open hardware monitor source code in c# ? I tried anything doesn't work

I have this code in Form1:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using OpenHardwareMonitor.Hardware.HDD;
using OpenHardwareMonitor;
namespace OpenHardwareMonitor
{
public partial class Form1 : Form
{
OpenHardwareMonitor.Hardware.SensorValue sv;
OpenHardwareMonitor.Hardware.ISensor ii;
public Form1()
{
InitializeComponent();
string y = ii.Name;
sv = new Hardware.SensorValue();
DateTime dt = sv.Time;
float t = sv.Value;
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
ii variable is null I don't know how to make an instance for it.
The other two variables in the constructor return 0 nothing. If I'm not using the ii variable the other two don't throw an error but don't return any values.
I'm using the openhardwaremonitor dll from http://code.google.com/p/open-hardware-monitor/downloads/detail?name=openhardwaremonitor-v0.4.0-beta.zip&can=2&q=
The c# dll is coming with the program it self.
So I added as reference the dll but I don't know how to make the code.
Could someone build for me just an example of the code according to my code here ?
I tried to look in the openhwardwaremonitor site and source code there and didn't understand how to use it.
What else can I do ?
Thanks.
I've tested this code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using OpenHardwareMonitor;
using OpenHardwareMonitor.Hardware;
namespace CPUTemperatureMonitor
{
public partial class Form1 : Form
{
Computer thisComputer;
public Form1()
{
InitializeComponent();
thisComputer = new Computer() { CPUEnabled = true };
thisComputer.Open();
}
private void timer1_Tick(object sender, EventArgs e)
{
String temp = "";
foreach (var hardwareItem in thisComputer.Hardware)
{
if (hardwareItem.HardwareType == HardwareType.CPU)
{
hardwareItem.Update();
foreach (IHardware subHardware in hardwareItem.SubHardware)
subHardware.Update();
foreach (var sensor in hardwareItem.Sensors)
{
if (sensor.SensorType == SensorType.Temperature)
{
temp += String.Format("{0} Temperature = {1}\r\n", sensor.Name, sensor.Value.HasValue ? sensor.Value.Value.ToString() : "no value");
}
}
}
}
textBox1.Text = temp;
}
}
}
The form has a multiline text control and a timer. Add a reference to OpenHardwareMonitorLib.dll.
You also need to request a higher execution level in the application, i.e. right click on the project, add a new manifest file item and declare
requestedExecutionLevel level="highestAvailable" uiAccess="false"

Categories

Resources