On visual studio code; I'm trying to get a text box to be used as a speech to text. However, when I enable it no error get thrown, nor does any speech appear. So, not entirely sure were I went wrong here. Very new to C# and visual studio. Any help is appreciated!! :) My mic is set to the default device and is able to detect me speaking. Other function such as copy to clipboard and clear work.
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;
using System.Speech.Recognition;
using System.Threading;
namespace MercyProto
{
public partial class Form1 : Form
{
public Grammar grammar;
public Thread RecThread;
public Boolean RecognizerState = true;
public SpeechRecognitionEngine recognizer;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
GrammarBuilder build = new GrammarBuilder();
build.AppendDictation();
grammar = new Grammar(build);
recognizer = new SpeechRecognitionEngine();
recognizer.LoadGrammar(grammar);
recognizer.SetInputToDefaultAudioDevice();
recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>
(recognizer_SpeechRecognized);
RecognizerState = true;
RecThread = new Thread(new ThreadStart(RecThreadFunction));
RecThread.Start();
}
public void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
//Recognizer recognizes the speech
if (!RecognizerState)
return;
this.Invoke((MethodInvoker)delegate
{
textBox1.Text += (" " + e.Result.Text.ToLower());
//This will add a space between each word you say
});
}
public void RecThreadFunction()
{
while (true)
{
try
{
recognizer.Recognize();
}
catch
{
//Handles errors
//Won't hear you, nothing will happen
}
}
private void button21_Click(object sender, EventArgs e)
{
RecognizerState = true;
}
private void button22_Click(object sender, EventArgs e)
{
RecognizerState = false;
}
private void button23_Click(object sender, EventArgs e)
{
Clipboard.SetText(textBox1.Text);
}
private void button24_Click(object sender, EventArgs e)
{
textBox1.Text = String.Empty;
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
Related
The code is as follows:
The ServerForm 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 SimpleTCP;
namespace TCPIP
{
public partial class ServerForm : Form
{
public ServerForm()
{
InitializeComponent();
}
SimpleTcpServer server;
private void Form1_Load(object sender, EventArgs e)
{
server = new SimpleTcpServer();
server.Delimiter = 0x13; //enter
server.StringEncoder = Encoding.UTF8;
server.DataReceived += Server_DataReceived;
}
private void Server_DataReceived(object sender, SimpleTCP.Message e)
{
StatusText.Invoke((MethodInvoker)delegate ()
{
StatusText.Text = e.MessageString;
e.ReplyLine(string.Format("You said: {0}",e.MessageString));
});
// throw new NotImplementedException();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void StartButton_Click(object sender, EventArgs e)
{
StatusText.Text += "Server Starting !";
System.Net.IPAddress ip = new System.Net.IPAddress(long.Parse(HostText.Text)); //error here
server.Start(ip,Convert.ToInt32(PortText.Text));
}
private void StopButton_Click(object sender, EventArgs e)
{
if(server.IsStarted)
{
server.Stop();
}
}
}
}
The Code of the ClientForm is as follows:
using SimpleTCP;
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;
namespace Client
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SimpleTcpClient client;
private void ConnectButton_Click(object sender, EventArgs e)
{
ConnectButton.Enabled = false;
}
private void Form1_Load(object sender, EventArgs e)
{
client = new SimpleTcpClient();
client.StringEncoder = Encoding.UTF8;
client.DataReceived += Client_DataReceived;
}
private void Client_DataReceived(object sender, SimpleTCP.Message e)
{
StatusText.Invoke((MethodInvoker)delegate ()
{
StatusText.Text = e.MessageString;
//...
});
//throw new NotImplementedException();
}
private void SendButton_Click(object sender, EventArgs e)
{
client.WriteLineAndGetReply(TextMessage.Text, TimeSpan.FromSeconds(4));
}
}
}
The issue in the above code is that it is 'build'ing correctly and even when I am debug it with the new instance, the code is running fine, but will I debug, as soon as I press the "start" button in the Server form it shows the error in line :
System.Net.IPAddress ip = new System.Net.IPAddress(long.Parse(HostText.Text));
The error is: System.FormatException: 'Input string was not in a correct format.'
Please refer the Screenshot for details and suggest a potential fix to the issue.Image of Screenshot of Error inLine
Clearly HostText.Text is returning a value that can't be parsed into a long.
This exception is coming from long.Parse, which is really a language shortcut for Int64.Parse, whose documentation states that it will throw this exception if the input string is not formatted correctly.
I have three commands to execute waiting for each command to finish before starting the next one.
Based on my implementation after completing the first one the second one will start but backgroundWorker1_RunWorkerCompleted won't raise at all.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace cmd_commands
{
public partial class Form1 : Form
{
string[] commands = new string[] {
#"test",
#"test1",
#"test2" };
int command = 0;
public Form1()
{
InitializeComponent();
}
public void runCmd(string command)
{
ProcessStartInfo cmdsi = new ProcessStartInfo("cmd.exe");
cmdsi.Arguments = command;
Process cmd = Process.Start(cmdsi);
cmd.WaitForExit();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
runCmd(commands[command]);
backgroundWorker1.ReportProgress(0, command);
}
private void button1_Click(object sender, EventArgs e)
{
backgroundWorker1.RunWorkerAsync();
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
label1.Text = "Working on command number: " + e.UserState.ToString();
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
command++;
runCmd(commands[command]);
}
}
}
BackgroundWorker is one time usage only i.e once the state is Completed it wont restart, u need to re-instantiate it.
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
command++;
if (command < commands.Length)
{
backgroundWorker1 = new BackgroundWorker();
backgroundWorker1.DoWork += this.backgroundWorker1_DoWork;
backgroundWorker1.ProgressChanged += this.backgroundWorker1_ProgressChanged;
backgroundWorker1.RunWorkerCompleted += this.backgroundWorker1_RunWorkerCompleted;
backgroundWorker1.RunWorkerAsync();
}
}
I got a question for the community. I followed some somewhat recent tutorial on a speech-to-text kinda deal. It worked for him and not for me, so do you have any suggestions?
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;
namespace Voice_Recognition
{
public partial class Form1 : Form
{
SpeechRecognitionEngine recEngine = new SpeechRecognitionEngine();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
recEngine.RecognizeAsync(RecognizeMode.Multiple);
btnEnable.Enabled = true;
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
Choices commands = new Choices();
commands.Add(new string[] {"say hello", "print my name" });
GrammarBuilder gBuilder = new GrammarBuilder();
gBuilder.Append(commands);
Grammar grammar = new Grammar(gBuilder);
recEngine.LoadGrammarAsync(grammar);
recEngine.SetInputToDefaultAudioDevice();
recEngine.SpeechRecognized += RecEngine_SpeechRecognized;
}
private void RecEngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
switch (e.Result.Text)
{
case "say hello":
MessageBox.Show("Hello, Zach!");
break;
case "print my name":
richTextBox1.Text += "\n Zach";
break;
}
}
private void btnDisable_Click(object sender, EventArgs e)
{
recEngine.RecognizeAsyncStop();
btnDisable.Enabled = false;
}
}
}
I'm trying to grab a list of all of my Skype friends who are online and put it into my listbox named lst1.
I'm also trying to make my tool answer to some commands like if some one sends !news to me it messages them a text that I've set in the code.
This is what I've tried so far, I'm just playing around with the code to learn how to use skype4comlib.
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 MetroFramework;
using MetroFramework.Forms;
using MetroFramework.Components;
using SKYPE4COMLib;
using System.Threading;
namespace betaskypetool
{
public partial class Form1 : MetroForm
{
#region Definitions
Skype Merk = new Skype();
private int count = 1;
#endregion
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void metroButton1_Click(object sender, EventArgs e)
{
try
{
this.Merk.Attach(5, true);
MessageBox.Show("You are now connected enjoy!", "Tutorial Skype Tool!");
}
catch (Exception)
{
MessageBox.Show("Failed To Connect?\n Be Sure Skype Is Open!", "Tutorial Skype Tool!");
}
}
private void metroButton2_Click(object sender, EventArgs e)
{
this.Merk.CurrentUserStatus = TUserStatus.cusOnline;
}
private void metroButton3_Click(object sender, EventArgs e)
{
this.Merk.CurrentUserStatus = TUserStatus.cusDoNotDisturb;
}
private void metroButton4_Click(object sender, EventArgs e)
{
this.Merk.CurrentUserStatus = TUserStatus.cusAway;
}
private void metroButton5_Click(object sender, EventArgs e)
{
this.Merk.CurrentUserStatus = TUserStatus.cusInvisible;
}
private void metroButton6_Click(object sender, EventArgs e)
{
this.Merk.CurrentUserStatus = TUserStatus.cusOffline;
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if(checkBox1.Checked == true)
{
timer1.Start();
}
else
{
timer1.Stop();
}
}
private void timer1_Tick(object sender, EventArgs e)
{
this.Merk.CurrentUserStatus = TUserStatus.cusOnline;
Thread.Sleep(20);
this.Merk.CurrentUserStatus = TUserStatus.cusAway;
Thread.Sleep(20);
this.Merk.CurrentUserStatus = TUserStatus.cusDoNotDisturb;
Thread.Sleep(20);
this.Merk.CurrentUserStatus = TUserStatus.cusInvisible;
Thread.Sleep(20);
}
private void metroButton7_Click(object sender, EventArgs e)
{
foreach(User spamall in Merk.Friends)
{
Merk.SendMessage(spamall.Handle, "Haiiiii" + spamall.FullName + ",\n" + richTextBox1.Text + "\n\n(cash) Sent From Merk's Tutorial Tool! (cash)");
}
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
I hope you understand my question and can help me out with what I need to do to add those 2 features to my project
You can get a collection of your online friends like this:
var onlineFriends = Merk.Friends.Cast<User>().Where(u => u.OnlineStatus == TOnlineStatus.olsOnline);
After this it's easy to put them in a ListBox.
WPF example:
foreach (var friend in onlineFriends)
{
MyListBox.Items.Add(friend.FullName);
}
That said, I'm not sure if it's worth to spend a lot of time learning it, because according to this blog post, Microsoft doesn't really support skype4comlib anymore.
https://support.skype.com/en/faq/FA12384/how-does-my-3rd-party-application-work-with-skype-and-how-will-changes-to-skype-impact-my-3rd-party-application
As communicated in this blog post, due to technology improvements we are making to the Skype experience, some features of the API will stop working with Skype for desktop. For example, delivery of chat messages using the API will cease to work.
For example, I'm not able to send a message using the library anymore.
PS.: I'm using Skype 7.17.0.106
I'm trying to show a MessageBox but i'm getting the error:
no overload for method 'show' takes 1 arguments.
I cant seem to find a solution in any forum (stackoverflow,msdn...) and I have tried everything that has been suggested. What am I missing?
Any help is appreciated.
BTW. I'm new to windows forms and c# in general but I have written this from a tutorial and it should work.
This is the complete 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 NetworksApi.TCP.CLIENT;
using System.IO;
namespace AdvancedClientChat
{
public partial class Form1 : Form
{
Client client;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void btnConnect_Click(object sender, EventArgs e)
{
if (textBoxIP.Text !="" && textBoxName.Text !="" && textBoxPort.Text !="")
{
client = new Client();
client.ClientName = textBoxName.Text;
client.ServerIp = textBoxIP.Text;
client.ServerPort = textBoxPort.Text;
}
else
{
MessageBox.Show("You must fill all the boxes");
}
}
private void btnSend_Click(object sender, EventArgs e)
{
}
private void MessageBox_KeyDown(object sender, KeyEventArgs e)
{
}
}
}
It looks like you have a control named MessageBox which is causing your problems. Either rename the control, or you will have to specify the MessageBox class with its full namespace, System.Windows.Forms.MessageBox.Show("myMessage");
private void btnConnect_Click(object sender, EventArgs e)
{
if (textBoxIP.Text !="" && textBoxName.Text !="" && textBoxPort.Text !="")
{
client = new Client();
client.ClientName = textBoxName.Text;
client.ServerIp = textBoxIP.Text;
client.ServerPort = textBoxPort.Text;
}
else
{
System.Windows.Forms.MessageBox.Show("You must fill all the boxes");
}
}