-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form2.cs
317 lines (274 loc) · 10.1 KB
/
Form2.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
using System;
using System.Xml;
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 IronPython.Hosting;
using Microsoft.Scripting;
using Microsoft.Scripting.Hosting;
using System.Diagnostics;
using System.IO;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.Threading;
using System.Speech;
namespace CalculoFormsApp
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void BtnEcSimplify_Click(object sender, EventArgs e)
{
using Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
//Set the process start by using relative path
process.StartInfo.FileName = "EcSimplifier.exe";
//Dont create a window
process.StartInfo.CreateNoWindow = true;
String ecuacion = EcTextBox.Text.Replace(" ", "");
String args = "S " + ecuacion;
process.StartInfo.Arguments = args;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
//Start the process
process.Start();
StreamReader reader = process.StandardOutput;
String result = reader.ReadToEnd();
process.WaitForExit();
AnswerLabel.Text = result;
}
/*private void PythonEcuationSimplifier()
{
String ecuacion = EcTextBox.Text.Replace(" ", "");
String pathPython = @"C:\Users\ZomserchXD\OneDrive - Benemérita Universidad Autónoma de Puebla\Proyecto de Cálculo (App)\CalculoFormsApp\EcSimplifier.py";
var runtime = Python.CreateRuntime();
var engine = runtime.GetEngine("python");
var scope = engine.CreateScope();
try
{
scope.ImportModule("sys");
dynamic pyProgram = runtime.UseFile(pathPython);
var result = pyProgram.simplificar(ecuacion);
AnswerLabel.Text = result;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}*/
private void Form2_Load(object sender, EventArgs e)
{
BtnMic.Enabled = true;
BtnStop.Enabled = false;
}
private void BtnCopiar_Click(object sender, EventArgs e)
{
//Copiar el resultado al portapapeles
Clipboard.SetText(AnswerLabel.Text);
}
private void BtnPegar_Click(object sender, EventArgs e)
{
//Pegar el contenido del portapapeles en el textbox
EcTextBox.Text = Clipboard.GetText();
}
SpeechRecognitionEngine sre = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("es-ES"));
SpeechSynthesizer ss = new SpeechSynthesizer();
PromptBuilder pb = new PromptBuilder();
public Choices clist;
private void BtnMic_Click(object sender, EventArgs e)
{
BtnMic.Enabled = false;
BtnMic.Text = "Escuchando...";
ss.Speak("Escuchando...");
BtnStop.Enabled = true;
//reiniciar la lista de palabras
clist = new Choices();
sre.UnloadAllGrammars();
String[] choices = { "más", "menos", "por", "entre", "paréntesis abierto", "paréntesis cerrado", "elevado", "potencia", "raíz",
"uno", "dos", "tres", "cuatro", "cinco", "seis", "siete", "ocho", "nueve", "cero",
"equis", "euler", "seno", "coseno", "tangente", "secante", "cosecante", "cotangente", "pi",
"logaritmo", "logaritmo natural", "espacio", "borrar", "borar todo", "listo", "derecha", "izquierda" };
clist.Add(choices);
GrammarBuilder gb = new GrammarBuilder();
gb.Culture = new System.Globalization.CultureInfo("es-ES");
gb.Append(clist);
Grammar gr = new Grammar(gb);
try
{
sre.RequestRecognizerUpdate();
sre.LoadGrammarAsync(gr);
sre.SpeechRecognized += sre_SpeechRecognized;
sre.SetInputToDefaultAudioDevice();
sre.RecognizeAsync(RecognizeMode.Multiple);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
}
}
private void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
switch (e.Result.Text)
{
case "más":
EcTextBox.Text += "+";
break;
case "menos":
EcTextBox.Text += "-";
break;
case "por":
EcTextBox.Text += "*";
break;
case "entre":
EcTextBox.Text += "/";
break;
case "paréntesis abierto":
EcTextBox.Text += "(";
break;
case "paréntesis cerrado":
EcTextBox.Text += ")";
break;
case "elevado":
EcTextBox.Text += "**";
break;
case "potencia":
EcTextBox.Text += "**";
break;
case "raíz":
EcTextBox.Text += "sqrt(";
break;
case "uno":
EcTextBox.Text += "1";
break;
case "dos":
EcTextBox.Text += "2";
break;
case "tres":
EcTextBox.Text += "3";
break;
case "cuatro":
EcTextBox.Text += "4";
break;
case "cinco":
EcTextBox.Text += "5";
break;
case "seis":
EcTextBox.Text += "6";
break;
case "siete":
EcTextBox.Text += "7";
break;
case "ocho":
EcTextBox.Text += "8";
break;
case "nueve":
EcTextBox.Text += "9";
break;
case "cero":
EcTextBox.Text += "0";
break;
case "equis":
EcTextBox.Text += "x";
break;
case "euler":
EcTextBox.Text += "e";
break;
case "seno":
EcTextBox.Text += "sin(";
break;
case "coseno":
EcTextBox.Text += "cos(";
break;
case "tangente":
EcTextBox.Text += "tan(";
break;
case "secante":
EcTextBox.Text += "sec(";
break;
case "cosecante":
EcTextBox.Text += "csc(";
break;
case "cotangente":
EcTextBox.Text += "cot(";
break;
case "pi":
EcTextBox.Text += "pi";
break;
case "logaritmo":
EcTextBox.Text += "log(";
break;
case "logaritmo natural":
EcTextBox.Text += "ln(";
break;
case "espacio":
EcTextBox.Text += " ";
break;
case "borrar":
//borrar el ultimo caracter
if (EcTextBox.Text.Length > 0)
{
EcTextBox.Text = EcTextBox.Text.Remove(EcTextBox.Text.Length - 1, 1);
}
break;
case "borar todo":
//borrar todo el texto
EcTextBox.Text = "";
break;
case "listo":
//detener el reconocimiento de voz
sre.RecognizeAsyncStop();
//llamar al metodo que evalua la expresion por medio del boton BtnEcSimplify
BtnEcSimplify_Click(sender, e);
BtnMic.Enabled = true;
BtnStop.Enabled = false;
//Reiniciar la gramatica
clist = new Choices();
ss.Speak("Obteniendo el resultado...");
break;
case "derecha":
//mover el cursor a la derecha del caracter actual
EcTextBox.SelectionStart = EcTextBox.Text.Length;
break;
case "izquierda":
//mover el cursor a la izquierda del ultimo caracter
try
{
EcTextBox.SelectionStart = EcTextBox.Text.Length - 1;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
break;
}
}
private void BtnStop_Click(object sender, EventArgs e)
{
//detener el reconocimiento de voz
try
{
BtnMic.Enabled = true;
BtnStop.Enabled = false;
sre.RecognizeAsyncStop();
//Reiniciar la gramatica
clist = new Choices();
ss.Speak("Obteniendo el resultado...");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}