C-sharp

2013/06/05
การเปิดไฟล์

1. add object “openFileDialog”
set properties : Filter = “Word2003(*.doc)”|*.doc
2. Code command button
private void button2_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
}
=====================================================
2013/06/05
Text2Speech Lib.

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.Synthesis;
using System.IO;

namespace text_to_speech
{
public partial class Form1 : Form
{
SpeechSynthesizer reader;
public Form1()
{
InitializeComponent();

}
private void Form1_Load(object sender, EventArgs e)
{
reader = new SpeechSynthesizer();
button2.Enabled = false;
button3.Enabled = false;
button4.Enabled = false;
textBox1.ScrollBars = ScrollBars.Both;
}

//SPEAK TEXT
private void button1_Click(object sender, EventArgs e)
{
reader.Dispose();
if (textBox1.Text != “”)
{

reader = new SpeechSynthesizer();
reader.SpeakAsync(textBox1.Text);
label2.Text = “SPEAKING”;
button2.Enabled = true;
button4.Enabled = true;
reader.SpeakCompleted += new EventHandler<SpeakCompletedEventArgs>(reader_SpeakCompleted);
}
else
{
MessageBox.Show(“Please enter some text in the textbox”, “Message”, MessageBoxButtons.OK);
}
}

void reader_SpeakCompleted(object sender, SpeakCompletedEventArgs e)
{
label2.Text = “IDLE”;
}

//PAUSE
private void button2_Click(object sender, EventArgs e)
{
if (reader != null)
{
if (reader.State == SynthesizerState.Speaking)
{
reader.Pause();
label2.Text = “PAUSED”;
button3.Enabled = true;

}
}
}

//RESUME
private void button3_Click(object sender, EventArgs e)
{
if (reader != null)
{
if (reader.State == SynthesizerState.Paused)
{
reader.Resume();
label2.Text = “SPEAKING”;
}
button3.Enabled = false;
}
}

private void button4_Click(object sender, EventArgs e)
{
if (reader != null)
{
reader.Dispose();
label2.Text = “IDLE”;
button2.Enabled = false;
button3.Enabled = false;
button4.Enabled = false;
}
}

private void button5_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
}

private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{
textBox1.Text = File.ReadAllText(openFileDialog1.FileName.ToString());

}
}
}
=====================================================
2013-06-06
Text2Speech Working 

/*
Add reference…
.NET
System.Speech
*/
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;
//1
using System.Speech.Synthesis;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
//2
SpeechSynthesizer reader;
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
//3
reader = new SpeechSynthesizer();
}

private void button1_Click(object sender, EventArgs e)
{
//4
reader.SpeakAsync(text1.Text);
}
}
}
=====================================================
=====================================================
=====================================================

ใส่ความเห็น

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / เปลี่ยนแปลง )

Twitter picture

You are commenting using your Twitter account. Log Out / เปลี่ยนแปลง )

Facebook photo

You are commenting using your Facebook account. Log Out / เปลี่ยนแปลง )

Google+ photo

You are commenting using your Google+ account. Log Out / เปลี่ยนแปลง )

Connecting to %s