I created a C# project using speech recognition where I have a form that has a next and last button What I am trying to do is when I say next the button will take me to the next file or if I say back it will go to the previous file. But When debug the project it only shows me what I say instead of doing it. Does anyone know how can I Fix it?
This is the code I made:
private void Form1_Load(object sender, EventArgs e)
{
SpeechRecognizer recognizer = new SpeechRecognizer();
Choices command = new Choices();
command.Add(new string[] { "next", "last", "first" });
GrammarBuilder gb = new GrammarBuilder();
gb.Append(command);
Grammar g = new Grammar(gb);
recognizer.LoadGrammar(g);
recognizer.SpeechRecognized +=
new EventHandler<SpeechRecognizedEventArgs>(sre_SpeechRecognized);
}
void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
MessageBox.Show("Speech recognized: " + e.Result.Text);
}
}
A couple of years ago I had a case study for this subject. If you compare my codes with yours you can find out something. The code below changes a light bulb's status.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Speech.Recognition;
using System.Threading;
namespace SesTanima
{
public partial class Form1 : Form
{
private SpeechRecognitionEngine recognizer = new SpeechRecognitionEngine();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
LoadGrammars();
StartRecognition();
}
private void LoadGrammars()
{
Choices choices = new Choices( new string[] {"Lights on", "Exit", "Zoom out", "Zoom in", "Reset", "Lights off" } );
GrammarBuilder grammarBuilder = new GrammarBuilder(choices);
Grammar grammar = new Grammar(grammarBuilder);
recognizer.LoadGrammar(grammar);
}
private void StartRecognition()
{
recognizer.SpeechDetected += new EventHandler<SpeechDetectedEventArgs>(recognizer_SpeechDetected);
recognizer.SpeechRecognitionRejected += new EventHandler<SpeechRecognitionRejectedEventArgs>(recognizer_SpeechRecognitionRejected);
recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);
recognizer.RecognizeCompleted += new EventHandler<RecognizeCompletedEventArgs>(recognizer_RecognizeCompleted);
Thread t1 = new Thread(delegate()
{
recognizer.SetInputToDefaultAudioDevice();
recognizer.RecognizeAsync(RecognizeMode.Single);
});
t1.Start();
}
private void recognizer_SpeechDetected(object sender, SpeechDetectedEventArgs e)
{
textBox1.Text = "Recognizing voice command...";
}
private void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
if (e.Result.Text == "Lights on")
{
pictureBox1.Image = Properties.Resources.lightsOn;
}
else if (e.Result.Text == "Lights off")
{
pictureBox1.Image = Properties.Resources.lightsOff;
}
else if ( e.Result.Text == "Exit" )
{
recognizer.Dispose();
Application.Exit();
}
else if ( e.Result.Text == "Zoom out" )
{
pictureBox1.Size = new System.Drawing.Size( 135, 107 );
}
else if ( e.Result.Text == "Zoom in" )
{
pictureBox1.Size = new System.Drawing.Size( 538, 426 );
}
else if ( e.Result.Text == "Reset" )
{
pictureBox1.Size = new System.Drawing.Size( 269, 213 );
}
textBox1.Text = e.Result.Text;
}
private void recognizer_SpeechRecognitionRejected(object sender, SpeechRecognitionRejectedEventArgs e)
{
textBox1.Text = "Failure.";
}
private void recognizer_RecognizeCompleted(object sender, RecognizeCompletedEventArgs e)
{
recognizer.RecognizeAsync();
}
}
}
Related
I wrote this code in c# and the issue here is that when I run the program the form window will not show up because of this line: RecognitionResult result = recEngine.Recognize();
But when I comment it out the code runs I also commented out the switch cases because they use the e.result..
My main goal with this code is to change the Grammar whenever I say the keyword so do you have a better way solving this ?
Thank you!
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 Lil_AI
{
public partial class Form1 : Form
{
SpeechRecognitionEngine recEngine = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US"));
SpeechSynthesizer spekEngine = new SpeechSynthesizer();
public enum ProcessState
{
on,
command,
off
}
public ProcessState current_state = ProcessState.off;
public Form1()
{
InitializeComponent();
}
private void btnEnable_Click(object sender, EventArgs e)
{
recEngine.RecognizeAsync(RecognizeMode.Multiple);
btnDisable.Enabled = true;
}
private void Form1_Load(object sender, EventArgs e)
{
recEngine.SetInputToDefaultAudioDevice();
spekEngine.SetOutputToDefaultAudioDevice();
//RecognitionResult result = recEngine.Recognize();
Choices oncommands = new Choices();
oncommands.Add(new string[] { "Please", "Bye" });
GrammarBuilder ongBuilder = new GrammarBuilder();
ongBuilder.Append(oncommands);
Grammar ongrammar = new Grammar(ongBuilder);
Choices commands = new Choices();
commands.Add(new string[] { "Turn on the lights", "Bye" });
GrammarBuilder gBuilder = new GrammarBuilder();
gBuilder.Append(commands);
Grammar grammar = new Grammar(gBuilder);
Choices offcommands = new Choices();
offcommands.Add(new string[] { "Hello", "Bye" });
GrammarBuilder offgBuilder = new GrammarBuilder();
offgBuilder.Append(offcommands);
Grammar offgrammar = new Grammar(offgBuilder);
// recEngine.LoadGrammar(offgrammar);
if (current_state == ProcessState.on)
{
recEngine.LoadGrammarAsync(ongrammar);
spekEngine.Speak("I'm waiting for your commands");
/* switch (result.Text)
{
case "Please":
current_state = ProcessState.command;
break;
case "Bye":
spekEngine.Speak("Bye, bye");
current_state = ProcessState.off;
break;
}*/
}
if (current_state == ProcessState.command)
{
recEngine.LoadGrammarAsync(grammar);
/* switch (result.Text)
{
case "Turn the lights on":
spekEngine.Speak("Of course");
break;
case "Bye":
spekEngine.Speak("Bye, bye");
current_state = ProcessState.off;
break;
}*/
}
if (current_state == ProcessState.off)
{
recEngine.LoadGrammarAsync(offgrammar);
/* switch (result.Text)
{
case "Hello":
spekEngine.Speak("Hi there");
current_state = ProcessState.on;
break;
}*/
}
}
private void btnDisable_Click(object sender, EventArgs e)
{
recEngine.RecognizeAsyncStop();
btnDisable.Enabled = false;
}
}
}
#Crowcoder, #Hans Passant thank you for the help. I managed to solve the issue by getting the grammars from a class.
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 AI_Graph
{
public partial class Form1 : Form
{
public SpeechRecognitionEngine recEngine = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US"));
public SpeechSynthesizer spekEngine = new SpeechSynthesizer();
public class DemoCode
{
public Grammar on_Grammar()
{
Choices oncommands = new Choices();
oncommands.Add(new string[] { "Please", "Bye" });
GrammarBuilder ongBuilder = new GrammarBuilder();
ongBuilder.Append(oncommands);
Grammar ongrammar = new Grammar(ongBuilder);
ongrammar.Name = "Standby";
return ongrammar;
}
public Grammar command_Grammar()
{
Choices commands = new Choices();
commands.Add(new string[] { "Turn on the lights", "Bye" });
GrammarBuilder gBuilder = new GrammarBuilder();
gBuilder.Append(commands);
Grammar grammar = new Grammar(gBuilder);
grammar.Name = "ON";
return grammar;
}
public Grammar off_Grammar()
{
Choices offcommands = new Choices();
offcommands.Add(new string[] { "Hello", "Bye", "Good night", "Good morning" });
GrammarBuilder offgBuilder = new GrammarBuilder();
offgBuilder.Append(offcommands);
Grammar offgrammar = new Grammar(offgBuilder);
offgrammar.Name = "OFF";
return offgrammar;
}
}
public DemoCode _Grammar = new DemoCode();
public enum ProcessState
{
on,
command,
off
}
public ProcessState current_state = ProcessState.off;
public Form1()
{
InitializeComponent();
}
public void recEngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
here:
do
{
if (current_state == ProcessState.on)
{
recEngine.LoadGrammarAsync(_Grammar.on_Grammar());
spekEngine.Speak("I'm waiting for your commands");
switch (e.Result.Text)
{
case "Please":
current_state = ProcessState.command;
richTextBox1.Text += e.Result.Grammar.Name;
break;
case "Bye":
spekEngine.Speak("Bye, bye");
current_state = ProcessState.off;
richTextBox1.Text += e.Result.Grammar.Name;
break;
}
}
if (current_state == ProcessState.command)
{
recEngine.LoadGrammarAsync(_Grammar.command_Grammar());
switch (e.Result.Text)
{
case "Turn the lights on":
spekEngine.Speak("Of course");
current_state = ProcessState.on;
richTextBox1.Text += e.Result.Grammar.Name;
break;
case "Bye":
spekEngine.Speak("Bye, bye");
current_state = ProcessState.off;
richTextBox1.Text += e.Result.Grammar.Name;
break;
}
}
if (current_state == ProcessState.off)
{
recEngine.LoadGrammarAsync(_Grammar.off_Grammar());
switch (e.Result.Text)
{
case "Hello":
spekEngine.Speak("Hi there");
current_state = ProcessState.on;
richTextBox1.Text += e.Result.Grammar.Name;
break;
case "Bye":
spekEngine.Speak("Bye, bye");
current_state = ProcessState.off;
richTextBox1.Text += e.Result.Grammar.Name;
break;
}
}
} while (e.Result.Text != "Good night");
if (e.Result.Text == "Good morning")
{
goto here;
}
}
public void recEngine_SpeechDetected(object sender, SpeechDetectedEventArgs e)
{
richTextBox1.Text += " Speech detected at AudioPosition = " + e.AudioPosition;
}
private void Form1_Load(object sender, EventArgs e)
{
recEngine.LoadGrammarAsync(_Grammar.off_Grammar());
recEngine.SetInputToDefaultAudioDevice();
spekEngine.SetOutputToDefaultAudioDevice();
recEngine.SpeechRecognized += recEngine_SpeechRecognized;
}
private void btnEnable_Click(object sender, EventArgs e)
{
recEngine.RecognizeAsync(RecognizeMode.Multiple);
btnDisable.Enabled = true;
}
private void btnDisable_Click(object sender, EventArgs e)
{
recEngine.RecognizeAsyncStop();
btnDisable.Enabled = false;
}
}
}
I am creating a question and answer level for a school project where we have to make a quiz. It seems that sometimes the questions and answers are being read in correctly but sometimes the questions and answers aren't - even on the first attempt. I am not sure why the questions and answers aren't being read in correctly.
Here is the 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 frmSplashScreen
{
public partial class frmLevel3 : Form
{
public frmLevel3()
{
InitializeComponent();
}
int questionsshown = 1; //to go up to 4
int questionno = 0;
public void randomq() //new question function... generating number, using it as index, putting it on lblQ
{
Random ran = new Random();
questionno = ran.Next(20);
lblQ.Text = gameClass.questions[questionno];
gameClass.questions.RemoveAt(questionno);
}
private void frmLevel3_Load(object sender, EventArgs e) // Load //
{
gameClass.time = 16;
tmrCountdown.Start();
this.BackgroundImage = gameClass.background; //settings bg
btnNext.Hide();
using (StreamReader sr = new StreamReader("l3questions.txt")) //reading all questions from text file
{
string line;
while ((line = sr.ReadLine()) != null)
{
gameClass.questions.Add(line);
}
}
using (StreamReader sr = new StreamReader("l3answers.txt")) //reading all answers from text file
{
string line;
while ((line = sr.ReadLine()) != null)
{
gameClass.answers.Add(line);
}
}
randomq();
if (gameClass.background != null)
{
lblQ.ForeColor = Color.White;
lblScore.ForeColor = Color.White;
}
}
private void btnNext_Click(object sender, EventArgs e) // Next Button //
{
if (questionsshown < 4)
{
questionsshown++;
randomq();
gameClass.time = 15;
tmrCountdown.Start();
gameClass.answers.RemoveAt(questionno);
btnNext.Hide();
btnCheck.Show();
}
if (questionsshown >= 4) // Checking no. of questions shown
{
tmrCountdown.Stop();
frmMainMenu menu = new frmMainMenu(); //Go to Menu
this.Hide();
MessageBox.Show("You have completed level 3 with a score of " + gameClass.score);
menu.Show();
}
txt1a.BackColor = Color.White; //Setting txts back to normal
txt1a.Text = null;
}
public void check()
{
tmrCountdown.Stop();
gameClass.time = 15;
btnCheck.Hide();
btnNext.Show();
if (txt1a.Text.ToLower() == gameClass.answers[questionno]) //checking question
{
gameClass.score++;
lblScore.Text = "Score: " + gameClass.score.ToString();
txt1a.BackColor = Color.Green;
}
else
{
txt1a.BackColor = Color.Red;
}
}
private void btnCheck_Click(object sender, EventArgs e) // Check Button //
{
check();
}
private void picHelp_Click(object sender, EventArgs e)
{
frmHelp help = new frmHelp();
this.Hide();
help.Show();
tmrCountdown.Stop();
}
private void picHome_Click(object sender, EventArgs e)
{
tmrCountdown.Stop();
frmMainMenu menu = new frmMainMenu();
this.Hide();
menu.Show();
}
private void lblQ_Click(object sender, EventArgs e)
{
}
private void menuToolStripMenuItem_Click(object sender, EventArgs e)
{
frmMainMenu menu = new frmMainMenu();
this.Hide();
menu.Show();
}
private void helpToolStripMenuItem_Click(object sender, EventArgs e)
{
frmHelp help = new frmHelp();
this.Hide();
help.Show();
tmrCountdown.Stop();
}
private void level1ToolStripMenuItem_Click(object sender, EventArgs e)
{
frmLevel1 l1 = new frmLevel1();
this.Hide();
l1.Show();
tmrCountdown.Stop();
}
private void level2ToolStripMenuItem_Click(object sender, EventArgs e)
{
frmLevel2 l2 = new frmLevel2();
this.Hide();
l2.Show();
tmrCountdown.Stop();
}
private void logOutToolStripMenuItem_Click(object sender, EventArgs e)
{
frmLogin login = new frmLogin();
this.Hide();
login.Show();
tmrCountdown.Stop();
}
private void tmrCountdown_Tick_1(object sender, EventArgs e)
{
gameClass.time--;
lblCountdown.Text = "Time left: " + gameClass.time.ToString();
if (gameClass.time == 0 && this.Name == "frmLevel3")
{
tmrCountdown.Stop();
MessageBox.Show("You have run out of time!");
questionsshown++;
check();
}
label1.Text = this.Name;
}
}
}
It was working perfectly before I started using a timer to count down from 15 to add bit more of a challenge to the level.
Any help would be greatly appreciated, thanks!
I have fixed the problem by putting the current question and current answer in variables and using that to check instead.
Here is my new, working 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 frmSplashScreen
{
public partial class frmLevel3 : Form
{
public frmLevel3()
{
InitializeComponent();
}
int questionsshown = 0; //to go up to 4
int questionno = 0;
string currentq = null;
string currenta = null;
public void randomq() //new question function... generating number, using it as index, putting it on lblQ
{
Random ran = new Random();
questionno = ran.Next(20);
currentq = gameClass.questions[questionno];
currenta = gameClass.answers[questionno];
lblQ.Text = currentq;
gameClass.questions.RemoveAt(questionno);
gameClass.answers.RemoveAt(questionno);
}
private void frmLevel3_Load(object sender, EventArgs e) // Load //
{
gameClass.time = 16;
tmrCountdown.Start();
this.BackgroundImage = gameClass.background; //settings bg
btnNext.Hide();
using (StreamReader sr = new StreamReader("l3questions.txt")) //reading all questions from text file
{
string line;
while ((line = sr.ReadLine()) != null)
{
gameClass.questions.Add(line);
}
}
using (StreamReader sr = new StreamReader("l3answers.txt")) //reading all answers from text file
{
string line;
while ((line = sr.ReadLine()) != null)
{
gameClass.answers.Add(line);
}
}
if (gameClass.background != null)
{
lblQ.ForeColor = Color.White;
lblScore.ForeColor = Color.White;
}
randomq();
Console.WriteLine(currentq);
Console.WriteLine(currenta);
Console.WriteLine(questionno);
}
private void btnNext_Click(object sender, EventArgs e) // Next Button //
{
if (questionsshown >= 4) // Checking no. of questions shown
{
tmrCountdown.Stop();
frmMainMenu menu = new frmMainMenu(); //Go to Menu
this.Hide();
MessageBox.Show("You have completed level 3 with a score of " + gameClass.score);
menu.Show();
}
else
{
questionsshown++;
gameClass.time = 16;
btnNext.Hide();
btnCheck.Show();
randomq();
tmrCountdown.Start();
}
txt1a.BackColor = Color.White; //Setting txts back to normal
txt1a.Text = null;
Console.WriteLine(currentq);
Console.WriteLine(currenta);
Console.WriteLine(questionno);
}
public void check()
{
tmrCountdown.Stop();
gameClass.time = 16;
btnCheck.Hide();
btnNext.Show();
if (txt1a.Text.ToLower() == currenta) //checking question
{
gameClass.score++;
lblScore.Text = "Score: " + gameClass.score.ToString();
txt1a.BackColor = Color.Green;
}
else
{
txt1a.BackColor = Color.Red;
}
}
private void btnCheck_Click(object sender, EventArgs e) // Check Button //
{
check();
}
private void picHelp_Click(object sender, EventArgs e)
{
frmHelp help = new frmHelp();
this.Hide();
help.Show();
tmrCountdown.Stop();
}
private void picHome_Click(object sender, EventArgs e)
{
tmrCountdown.Stop();
frmMainMenu menu = new frmMainMenu();
this.Hide();
menu.Show();
}
private void lblQ_Click(object sender, EventArgs e)
{
}
private void menuToolStripMenuItem_Click(object sender, EventArgs e)
{
frmMainMenu menu = new frmMainMenu();
this.Hide();
menu.Show();
}
private void helpToolStripMenuItem_Click(object sender, EventArgs e)
{
frmHelp help = new frmHelp();
this.Hide();
help.Show();
tmrCountdown.Stop();
}
private void level1ToolStripMenuItem_Click(object sender, EventArgs e)
{
frmLevel1 l1 = new frmLevel1();
this.Hide();
l1.Show();
tmrCountdown.Stop();
}
private void level2ToolStripMenuItem_Click(object sender, EventArgs e)
{
frmLevel2 l2 = new frmLevel2();
this.Hide();
l2.Show();
tmrCountdown.Stop();
}
private void logOutToolStripMenuItem_Click(object sender, EventArgs e)
{
frmLogin login = new frmLogin();
this.Hide();
login.Show();
tmrCountdown.Stop();
}
private void tmrCountdown_Tick_1(object sender, EventArgs e)
{
gameClass.time--;
lblCountdown.Text = "Time left: " + gameClass.time.ToString();
if (gameClass.time == 0 && this.Name == "frmLevel3")
{
tmrCountdown.Stop();
MessageBox.Show("You have run out of time!");
questionsshown++;
check();
}
label1.Text = this.Name;
}
}
}
So I've made the application recognize what I say. But how do I make the application confirm a request when I command it to carry out a task?
As of now I have this code:
public partial class Form1 : Form
{
SpeechSynthesizer synth = new SpeechSynthesizer();
SpeechRecognitionEngine sRecognize= new SpeechRecognitionEngine();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Choices sList = new Choices();
sList.Add(new String[] { "Exit"});
Grammar gr = new Grammar(new GrammarBuilder(sList));
sRecognize.RequestRecognizerUpdate();
sRecognize.LoadGrammar(gr);
sRecognize.SpeechRecognized += sRecognize_SpeechRecognized;
sRecognize.SetInputToDefaultAudioDevice();
sRecognize.RecognizeAsync(RecognizeMode.Multiple);
sRecognize.SpeechRecognitionRejected += sRecognize_SpeechRecognitionRejected;
}
private void sRecognize_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
if (e.Result.Text == "Exit")
{
Application.Exit();
}
}
}
So my question as an example:
I say, "Exit"
Application confirms by:
Are you sure you want to exit?
And depending on my answer, the application responds.
Yes being a confirmation and No being a request cancellation. What changes do I have to make?
Something like this?
private void sRecognize_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
if (e.Result.Text == "Exit")
{
Choices sList = new Choices();
sList.Add(new String[] { "Yes"});
Grammar gr = new Grammar(new GrammarBuilder(sList));
sRecognize.RequestRecognizerUpdate();
sRecognize.LoadGrammar(gr);
sRecognize.SpeechRecognized += delegate(object sender, SpeechRecognizedEventArgs e)
{
Application.Exit();
};
sRecognize.SetInputToDefaultAudioDevice();
sRecognize.RecognizeAsync(RecognizeMode.Multiple);
}
}
The invocation of the constructor on type 'WpfApplication1.MainWindow'
that matches the specified binding constraints threw an exception.'
Line number '4' and line position '9'.
That was the error I'm facing while changing my target platform from 'x86' to 'Any CPU' in order to run my executable to run in x86 and x64 bit windows operating systems.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WebKit;
using WebKit.Interop;
using Twitterizer;
using Facebook;
using TwitterConnect;
using facebook;
namespace WpfApplication3
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
WebKitBrowser wb = new WebKitBrowser();
TwitterConnect.TwitterStuff ts = new TwitterStuff();
Browser b = new Browser();
OpenWebkitBrowser.facebook fb_1 = new OpenWebkitBrowser.facebook();
private void Possibillion_Loaded(object sender, RoutedEventArgs e)
{
System.Windows.Forms.Integration.WindowsFormsHost host = new System.Windows.Forms.Integration.WindowsFormsHost();
host.Child = wb;
this.Grid2.Children.Add(host);
wb.DocumentCompleted += wb_DocumentCompleted;
}
void wb_DocumentCompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e)
{
textBox1.Text = wb.Url.ToString();
TabItem1.Header = wb.DocumentTitle;
}
private void btnMinimize_Click(object sender, RoutedEventArgs e)
{
Possibillion.WindowState = WindowState.Minimized;
}
private void btnMaximize_Click(object sender, RoutedEventArgs e)
{
if (Possibillion.WindowState == WindowState.Maximized)
Possibillion.WindowState = WindowState.Normal;
else
Possibillion.WindowState = WindowState.Maximized;
}
private void btnClose_Click(object sender, RoutedEventArgs e)
{
Possibillion.Close();
}
private void btnGo_Click(object sender, RoutedEventArgs e)
{
wb.Navigate("http://" + textBox1.Text);
}
private void btnTwitter_Click(object sender, RoutedEventArgs e)
{
bool loggedIn = b.AlreadyLoggedIn();
if (!loggedIn)
{
//this.Hide();
b.Show();
}
//else
//{
// MainWindow mw = new MainWindow();
// mw.Show();
// this.Close();
//}
else if (textBox1.Text != "")
{
ts.tweetIt(wb.DocumentTitle);
//textBox1.Clear();
}
}
private void btnfacebook_Click_1(object sender, RoutedEventArgs e)
{
if (val.login == true)
{
//fb_1.Show();
if (string.IsNullOrEmpty(textBox1.Text))
{
Dispatcher.Invoke(new Action(() => { System.Windows.MessageBox.Show("Enter message."); }));
return;
}
var fb = new FacebookClient(val.token);
fb.PostCompleted += (o, args) =>
{
if (args.Error != null)
{
Dispatcher.Invoke(new Action(() => { System.Windows.MessageBox.Show(args.Error.Message); }));
return;
}
var result = (IDictionary<string, object>)args.GetResultData();
//_lastMessageId = (string)result["id"];
Dispatcher.Invoke(new Action(() =>
{
System.Windows.MessageBox.Show("Message Posted successfully");
textBox1.Text = string.Empty;
// pho.IsEnabled = true;
}));
};
var fbimg = new Facebook.FacebookMediaObject
{
FileName = Guid.NewGuid() + ".jpg",
ContentType = "image/png"
};
// FileStream fs = new FileStream("Rose.png", FileMode.Open, FileAccess.Read);
// BinaryReader br = new BinaryReader(fs);
// byte[] res = br.ReadBytes((int)fs.Length);
// br.Close();
// fs.Close();
//fbimg.SetValue(res);
// Uri uri = new Uri("/Background.png",UriKind.Relative);
var parameters = new Dictionary<string, object>();
//parameters.Add("picture", fbimg);
//parameters.Add("message", "hi");
// parameters["picture"] ="https://twimg0-a.akamaihd.net/profile_images/2263781693/SAchin_reasonably_small.png";
parameters["message"] = textBox1.Text;
// parameters["picture"] =fbimg;
//fb.PostAsync(#"/photos", parameters);
fb.PostAsync("me/feed", parameters);
}
else
{
Dispatcher.Invoke(new Action(() => { fb_1.ShowDialog(); }));
//System.Windows.MessageBox.Show("message not sent");
}
}
private void textBox1_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
wb.Navigate("http://" + textBox1.Text);
}
}
}
Make sure your target platform matches your build settings.
If you have changed your configuration manager to any CPU, then in the project properties under build you will need to do the same.
Edit - Ah seems like your trying to run a toolkit that is build for x86 in a x64 world.
I am a new in this world, I am fall in problem with some strange thing, I was change Windows 7 Text To Speech Voice to Ivona Brina my computer default voice, but when I run my program the voice is same as first MS ANNA,
AND
There is another problem when I speck to my program then it come double,
here is my full code in c#,
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;
using System.Diagnostics;
using System.Globalization;
using System.IO;
namespace VoiceRs
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.button1.Click += new EventHandler(button1_Click);
this.button2.Click += new EventHandler(button2_Click);
this.button3.Click += new EventHandler(button3_Click);
foreach (InstalledVoice voice in sSynth.GetInstalledVoices())
{
Console.WriteLine(voice.VoiceInfo.Name);
}
}
SpeechSynthesizer sSynth = new SpeechSynthesizer();
PromptBuilder pBuilder = new PromptBuilder();
SpeechRecognitionEngine sRecognize = new SpeechRecognitionEngine();
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
pBuilder.ClearContent();
pBuilder.AppendText(textBox1.Text);
sSynth.SelectVoice("IVONA 2 Brian");
sSynth.Speak(pBuilder);
}
private void button2_Click(object sender, EventArgs e)
{
button2.Enabled = false;
button3.Enabled = true;
Choices sList = new Choices();
sList.Add(new string[] { "hello", "test", "it works", "how", "are", "you", "today", "i", "am", "fine", "exit", "close", "quit", "so", "hello how are you" });
Grammar gr = new Grammar(new GrammarBuilder(sList));
try
{
sRecognize.RequestRecognizerUpdate();
sRecognize.LoadGrammar(gr);
sRecognize.SpeechRecognized += sRecognize_SpeechRecognized;
sRecognize.SetInputToDefaultAudioDevice();
sRecognize.RecognizeAsync(RecognizeMode.Multiple);
sRecognize.Recognize();
}
catch
{
return;
}
}
private void button3_Click(object sender, EventArgs e)
{
sRecognize.RecognizeAsyncStop();
button2.Enabled = true;
button3.Enabled = false;
}
private void sRecognize_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
if (e.Result.Text == "exit")
{
Application.Exit();
}
else
{
textBox1.Text = textBox1.Text + " " + e.Result.Text.ToString();
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
and here is my full project : ClickLink
please help, Thank you...
Here is the prove that I am Install IVONA 2 Brian
Try running this MSDN example and see if you are able to hear IVONA voice.
private void button1_Click(object sender, EventArgs e)
{
using (SpeechSynthesizer synth = new SpeechSynthesizer())
{
// Configure the audio output
synth.SetOutputToDefaultAudioDevice();
// Build a prompt
PromptBuilder builder = new PromptBuilder();
builder.AppendText("That is a big pizza!");
foreach (InstalledVoice voice in synth.GetInstalledVoices())
{
VoiceInfo info = voice.VoiceInfo;
// Select voice
synth.SelectVoice(info.Name);
// Speak the prompt
synth.Speak(builder);
}
}
}