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 WindowsFormsApplication6
{
public partial class Reader : Form
{
public SpeechSynthesizer synthesizer;
public string SpeechText = string.Empty;
public Reader()
{
InitializeComponent();
}
private void VoiceSlelection()
{
try
{
if (ddlvoice.SelectedItem.ToString() == "Female Voice")
{
synthesizer.SelectVoiceByHints(VoiceGender.Female);
}
else if (ddlvoice.SelectedItem.ToString() == "Male Voice")
{
synthesizer.SelectVoiceByHints(VoiceGender.Male);
}
}
catch
{
}
}
private void ToolBarButtonStyle(Button btn, bool value)
{
btn.Enabled = value;
}
private void btnread_Click(object sender, EventArgs e)
{
try
{
if (txtdoc.Text != "")
{
synthesizer = new SpeechSynthesizer();
VoiceSlelection();
ddlvoice.Enabled = false;
// synthesizer.Volume = 100; // 0...100
// synthesizer.Rate = -2; // -10...10
SpeechText = txtdoc.Text.Trim();
// Synchronous
//synthesizer.Speak("Hello World");
// Asynchronous
synthesizer.SpeakAsync(SpeechText);
lblmessage.Text = "SPEAKING";
synthesizer.SpeakCompleted += new EventHandler<SpeakCompletedEventArgs>(reader_SpeakCompleted);
}
else
{
MessageBox.Show("Please enter text to read", "Message", MessageBoxButtons.OK);
}
}
catch
{
}
}
void reader_SpeakCompleted(object sender, SpeakCompletedEventArgs e)
{
lblmessage.Text = "IDLE";
idle();
}
private void btnsave_Click(object sender, EventArgs e)
{
try
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
DialogResult result = fbd.ShowDialog();
SpeechSynthesizer Savesynthesizer = new SpeechSynthesizer();
Savesynthesizer.SetOutputToWaveFile(fbd.SelectedPath + "\\Speech.wav");
Savesynthesizer.Dispose();
}
catch
{
}
}
private void btnpause_Click(object sender, EventArgs e)
{
try
{
if (synthesizer != null)
{
if (synthesizer.State == SynthesizerState.Speaking)
{
synthesizer.Pause();
lblmessage.Text = "PAUSED";
idle();
}
}
}
catch
{
}
}
private void btnplay_Click(object sender, EventArgs e)
{
try
{
if (synthesizer != null)
{
if (synthesizer.State == SynthesizerState.Paused)
{
synthesizer.Resume();
lblmessage.Text = "SPEAKING";
}
}
}
catch
{
}
}
private void btnstop_Click(object sender, EventArgs e)
{
try
{
if (synthesizer != null)
{
synthesizer.SpeakAsyncCancelAll();
synthesizer.Dispose();
lblmessage.Text = "IDLE";
idle();
// MessageBox.Show("Goodbye");
// Application.Exit();
}
}
catch
{
}
}
private void btnReadAgain_Click(object sender, EventArgs e)
{
try
{
if (synthesizer != null)
{
lblmessage.Text = "IDLE";
txtdoc.Text = "";
synthesizer.Dispose();
idle();
}
}
catch
{
}
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
ddlvoice.SelectedIndex = 0;
lblmessage.Text = "Copy Paste the text in the plain and click on Read button";
}
catch
{
}
}
private void idle()
{
if (lblmessage.Text.ToString() == "IDLE")
{
ddlvoice.Enabled = true;
}
else
{
ddlvoice.Enabled = false;
}
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
MessageBox.Show("This App is for Lazy ppl like me ;) Thanks Gokuldas.Palapatta","Message", MessageBoxButtons.OK);
}
}
}
No comments:
Post a Comment