need guidance for speech recognition engine with custom keywords c# - c#

I have an windows form app. I need to add speech recognition into it in order to shorten the processing time for product entry. we need this speech recognition in Turkish. if it was in english, because of wrong pronunciation it would give a lot of false results. So we need in Turkish. But windows offline speech recognition engine doesnt support Turkish.
Actually We need max 100 keywords in order to succeed this. we don't need whole language in process. So if I can create a language by adding a word and train the engine for that with a kind of training as speech training in windows, it would be great.
So I need guidance to start or move forward for this task. I have looked at the cmusphnfix but it doesnt have turkish language also. But I dont know if I can create a custom language for 100 words with correct pronunciation. if so how can ı do it in c#.
note: we dont want to use google and microsoft online services. we are looking other options.
Thanks in advance.

Windows desktop versions have built in APIs for speech recognition. These include grammar support for identifying the words or meaning of what was spoken. I don't know if Turkish is supported.
Perhaps https://stackoverflow.com/a/5473407/90236 or https://learn.microsoft.com/en-us/previous-versions/office/developer/speech-technologies/hh361633(v%3doffice.14) can help you get started

https://www.sestek.com has good Turkish speech recognition. As for 100 keywords, on that scale it is easier to recognize whole speech and just look for keywords in transcription. That will give you better accuracy because speech recognition uses more context. When you just look for keywords you do not have context so the recognition is actually less accurate.

this is script for C# console app
if you want this in windows forms, just copy static void recognize and all in this and paste it in class Form : Form1, or where you want. write recognize(); in button1_click, or where you want. in windows forms do not copy anything else!

write this:
using System;
using System.Runtime.CompilerServices;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.Threading;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.IO;
using System.Linq.Expressions;
namespace speechrecognition
{
class Program
{
static string a { get; set; }
static void Main(string[] args)
{
recognize();
}
static void recognize()
{
SpeechRecognitionEngine recognizer = new SpeechRecognitionEngine();
Choices colorChoice = new Choices(new string[] { "gugl", "noutpad" });
GrammarBuilder colorElement = new GrammarBuilder(colorChoice);
Choices bothChoices = new Choices(new GrammarBuilder[] { colorElement });
Grammar grammar = new Grammar((GrammarBuilder)bothChoices);
recognizer.LoadGrammar(grammar);
try
{
recognizer.SetInputToDefaultAudioDevice();
RecognitionResult result = recognizer.Recognize();
try
{
if (result.Text != null)
{
switch (result.Text.ToString())
{
// Here you add keywords like other two
// and write the into choices color choice too
case "noutpad":
Process.Start(#"notepad.exe");
Console.WriteLine("Notepad opened!");
recognize();
break;
case "gugl":
Process.Start(#"chrome.exe");
Console.WriteLine("Google opened!");
recognize();
break;
}
}
else
{
Console.WriteLine("I dont hear you!");
recognize();
}
}
catch (System.NullReferenceException)
{
recognize();
}
}
catch (InvalidOperationException exception)
{
Console.WriteLine("I dont hear you!");
Console.ReadLine();
recognize();
}
finally
{
recognizer.UnloadAllGrammars();
recognize();
}
}
}
}

Related

Calculating a moving average in C# with IronPython Data Stream

I have a sensor that is displaying real-time data through a Python script, running on IronPython. Unfortunately, IronPython does not support pandas, so I am unable to use the pd.rolling_mean function in my Python script, or perform much data processing in real-time (as far as I understand).
When I run the below program in Visual Studio, a console application appears, and the data from the sensor starts streaming in. My goal is to calculate the rolling_mean of this data stream, and then to trigger an event once that rolling_mean exceeds a certain value.
I am limited to IronPython, because that is what the sensor company requires in order to run their real-time data script. Unfortunately, I am having trouble finding ways to process that data stream in real-time.
I was wondering if there is a way for me to write the rolling_mean in C# on the data stream that is coming in - similar to the following question: Calculate a moving std in C#.
Thank you for any feedback and support! My current code is as follows:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IronPython.Hosting;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter Y to begin:");
var input = Console.ReadLine();
var py = Python.CreateEngine();
var engine = Python.CreateEngine();
var paths = engine.GetSearchPaths();
paths.Add("C:\\Python34\\Lib\\site-packages");
engine.SetSearchPaths(paths);
try
{
py.ExecuteFile("C:\\Users\\MyName\\Desktop\\Sensor_Data.py");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message.ToString());
}
Console.WriteLine("Press Enter to Exit");
Console.ReadLine();
}
}
}

C# Reading/Splitting Text Files and Reversing Sentences Exercise

Locked. There are disputes about this question’s content being resolved at this time. It is not currently accepting new answers or interactions.
I am trying to do this book exercise for quite a while now in C# using visual studio and windows forms, however, I am having trouble with the last few steps and the book has no solution manual that I can look to for help.
Here is what the exercise says:
Read in the file
Split the file line-by-line
Push each line on to a stack
Pop each line out to a results Window
Save the reversed file (the sentences should be reversed).
Here is a picture of what the windows form should look like:
What the windows form should look like
Here is the sample .txt file named SocialJustice-SampleText.txt:
The idea of social justice is innately a subjective concept. A socially created reality critical to the enactment of social institutions, ‘justice’ exists within the minds of all individuals as we each have varying ideas of what is just or unjust, fair or unfair, right or wrong (Tyler, 1997). In turn, what emerges from this socially created reality is considered the “first virtue” in the enactment of social institutions (Rawls, 1971), and the first form of criteria that emerges when political, legal, and other managerial authorities come under judgment (Kelman and Hamilton, 1989). From the perspective of the academician, social justice bears fruit in areas such as moral philosophy, theology, political science, law, social psychology, and many others. From the perspective of the citizen, social justice is at the heart of modern discourse on topics related to equal distributions of wealth (Piketty, 2014), equal distributions of healthy food (Alkon and Agyeman, 2011), and the general precept of human rights as the virtue of being able to achieve equal outcomes given equal effort (Cergy-Pontoise, 2005; Wilkinson and Pickett, 2010). Thus, social justice is instrumentalist an Pragmatist by its very nature (Fraser, 1998) as the psychology of social justice is predicated on the consequences and meanings of an action or an event in a social situation, and such meaning cannot be given in advance of experience (Denzin, 2012) in seeking a Pragmatism that addresses social justice issues (Denzin, 2012; West, 1995). To research social justice is to adopt an inherently moral aim (Denzin, 2012; West, 1995) where the outputs inherently carry political consequences. In turn, our ideas of social justice are not conceived not from a universalistic ontology, but from a psychologically-driven understanding of actions (Tyler, 1997). However, much of the research on social justice is predicated on organizational work from the industrial revolution (cite), and far less with regard to understanding social justice in the information age (Eubanks, 2011). As we transpose our understanding of the psychology of social justice to the information age, and offer new vistas for IS research, we conceptualize areas of research at the confluence of information, technology, societal systems, and praxis that emanates as just actions and lies beyond the organizational container (Winter et al., 2014). In this section, we draw on the psychology of social justice (Tyler, 1997; cite; cite), which has, in turn, drawn from the etymological, theological, and philosophical roots of organizational justice to elucidate four areas: relative deprivation, distributive justice, procedural justice, and retributive justice, that can be elucidated as platforms for Pragmatic social justice research in IS.
So far I have created the form with the two rich textboxes and also created the two buttons "Open File" and "Split File." I also have read the .txt file in when I click the "Open File" button.
Here is what my form looks like based off of what I have done so far:
My windows form
Here is my full 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.IO;
namespace FileExercise
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void OpenFileButton_Click(object sender, EventArgs e)
{
StreamReader objstream = new StreamReader("C:\\Users\\Omie\\Desktop\\SocialJustice-SampleText.txt");
richTextBox1.Text = objstream.ReadLine();
}
private void SplitFileButton_Click(object sender, EventArgs e)
{
}
}
}
So I am having trouble with steps 2-5 and was wondering if anyone could provide me an example of how to go about doing it based on what I have worked on already.
Thank you.
EDIT: Updated 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.IO;
using System.Text.RegularExpressions;
namespace FileExercise
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void OpenFileButton_Click(object sender, EventArgs e)
{
string TextFile = File.ReadAllText("C:\\Users\\Omie\\Desktop\\SocialJustice-SampleText.txt", Encoding.UTF8);
richTextBox1.Text = TextFile;
}
private void SplitFileButton_Click(object sender, EventArgs e)
{
string SplitFile = File.ReadAllText("C:\\Users\\Omie\\Desktop\\SocialJustice-SampleText.txt", Encoding.UTF8);
string[] SplitFileBySentence = Regex.Split(SplitFile, ".");
foreach (string Period in SplitFileBySentence)
{
richTextBox2.Text = Period;
}
}
}
}
You can use
string[] readText = File.ReadAllLines("C:\\Users\\Omie\\Desktop\\SocialJustice-SampleText.txt")
to read all lines into string array.
Then, process the each line in the loop. I hope you can write the code to reverse the line.

How to use System.Speech on non-English Win Vista Business

I´d like to try Speech recognition to controlling program. I wrote test program in C# and when I´m debugging this, an error occurred every time -
System.Runtime.InteropServices.COMException (0x80004005): Calling part of COM return error HRESULT E_FAIL.*
in System.Speech.Recognition.RecognizerBase.Initialize(SapiRecognizer recognizer, Boolean inproc)
in System.Speech.Recognition.SpeechRecognitionEngine.get_RecoBase()
in System.Speech.Recognition.SpeechRecognitionEngine.LoadGrammar(Grammar grammar)
It looks the error is caused by engine.LoadGrammar(new DictationGrammar());
On my notebook I installed CZECH OS Vista, and maybe this is the problem that speech recognition language is not the same as OS language.
Is there a way how to developing with system.speech in non english OS, or am I wrong in some step? There is no problem in language, I´d like use english for speech recognizing, but, I cannot get english Vista or MUI language pack.
Full code is below.
Thanks a lot!
using System;
using System.Windows;
using System.Speech.Recognition;
namespace rozpoznani_reci_WPF
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
SpeechRecognitionEngine engine = new SpeechRecognitionEngine();
try
{
engine.LoadGrammar(new DictationGrammar());
engine.SetInputToDefaultAudioDevice();
engine.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);
}
catch(Exception e)
{
//MessageBox.Show(e.ToString());
textBox1.Text = e.ToString();
}
}
void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
if (e.Result != null)
{
textBox1.Text = e.Result.Text + " ";
}
}
}
}
According to the MSDN documentation on DictationGrammar, the argument-free constructor
Initializes a new instance of the DictationGrammar class for the default dictation grammar provided by Windows Desktop Speech Technology.
Is there a Czech language DicationGrammar class available on your machine? If not, you need to create one and use the other constructor DictationGrammar(String) and load one from a URI. You can also use GrammarBuilder to construct your own and load it instead using SpeechRecognizer.LoadGrammar().
You might also find this link useful; it's from 2008, but you did ask about Vista. :-)

Fast screen capture using DirectX in Java (Re-writing from existing code in C# to Java)

My aim is to capture the screen using DirectX in Java.
I have found the project fully detailed and explained here in C# .
Unfortunately, I do not have any knowledge in C sharp. I don't know if I can ask here a re-writing code above mentioned from C# to Java to those who handle both language, but I guess the final result would interest a lot of people.
Anyway, I thank those in advance who would be kind enough to help me with this. Even if I never tried, I know that a C# -> Java conversion software (or any other language) is not advised, explaining my question of re-writing.
Please find on below the code concerned:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SlimDX.Direct3D9;
namespace KMPP
{
public class DxScreenCapture
{
Device d;
public DxScreenCapture()
{
PresentParameters present_params = new PresentParameters();
present_params.Windowed = true;
present_params.SwapEffect = SwapEffect.Discard;
d = new Device(new Direct3D(), 0, DeviceType.Hardware, IntPtr.Zero, CreateFlags.SoftwareVertexProcessing, present_params);
}
public Surface CaptureScreen()
{
Surface s = Surface.CreateOffscreenPlain(d, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, Format.A8R8G8B8, Pool.Scratch);
d.GetFrontBufferData(0, s);
return s;
}
}
}
PS:Since Surface s is here a DirectX type of image, it would be interesting for me then to convert it into PNG then.
Java isn't C#
C# is totally different to java. C# can use DirectX but java cannot use it because DirectX was unavailable on all platforms. Instead you can use the Robot class present in java.awt package. Here's how to get the image.
Doing it with a robot
Dimension ss = Toolkit.getDefaultToolkit().getScreenSize();
Robot r = new Robot();
BufferedImage s = r.createScreenCapture(new Rectangle(ss));
It returns a BufferedImage which contains the screenshot.

C# DirectX input problem

So i have simple application, just a few lines:
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 Microsoft.DirectX.DirectInput;
namespace asdasd
{
public partial class Form1 : Form
{
public Device joystick;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
foreach (
DeviceInstance di in
Manager.GetDevices(
DeviceClass.GameControl,
EnumDevicesFlags.AttachedOnly))
{
joystick = new Device(di.InstanceGuid);
break;
}
if (joystick == null)
{
throw new Exception("No joystick found.");
}
}
}
}
and i try to get the active joystick on my computer, but i get error:
i have the assembly Microsoft.DirectX.DirectInput and i have directX SDK 2010 installed.
Can someone tell me where is the problem?
Try adding this to the config file:
http://devonenote.com/2010/08/mixed-mode-assembly-error-after-upgrading-to-dotnet-4-0/
(if configuration already exists, just merge these in)
And, maybe it's not the right place, but just take a look at XNA... Things are usually much easier with that.
I couldn't paste the XML directly here, it doesn't show up.
The DirectX assemblies are built against .NET v1.1 Microsoft stopped actively developing them before .NET v2.0 was released.
They cannot be used in projects targeting other than .NET v1.1. XNA is the "blessed" path forward for managed access to Direct X features. I don't know all if it's features, but SlimDX appears to give a more Direct X feeling API for C# than XNA, though I have not used it, I've heard a lot about it.
You might find better responses for chosing an upgrade path over at gamedev.stackexchange.com though.

Categories