???????????????????????????????£?

 

privateSpeechSynthesizersynth=null;//???????
///<summary>
///???????SpeechSynthesizer????
///</summary>
///<returns></returns>
privateSpeechSynthesizerGetSpeechSynthesizerInstance()
{
if(synth==null)
{
synth=newSpeechSynthesizer();
}
returnsynth;
}
///<summary>
///?????????????
///</summary>
///<returns></returns>
privateVoiceClassGetVoiceClass()
{
VoiceClasssetViceClass=newVoiceClass();
setViceClass.VoiceName=cboTokens.Text;
setViceClass.Rate=int.Parse(cboSpeed.Text);
setViceClass.Volume=tbVoice.Value;
setViceClass.VoiceText=txtInput.Text;
returnsetViceClass;
}
///<summary>
///????
///</summary>
///<paramname="sender"></param>
///<paramname="e"></param>
privatevoidbtnGo_Click(objectsender??EventArgse)
{
if(IsVaild())
{
VoiceClasssetViceClass=GetVoiceClass();//VoiceClass????????????????????????????????????????????
Threadthread=newThread(RingVoice);
thread.Start(setViceClass);
}
}
///<summary>
///???????????????
///</summary>
///<paramname="VoiceObject"></param>
publicvoidRingVoice(objectVoiceObject)
{
try
{
VoiceClassvoiceClass=(VoiceClass)VoiceObject;
synth=GetSpeechSynthesizerInstance();
synth.SelectVoice(voiceClass.VoiceName);
synth.Rate=voiceClass.Rate;
synth.Volume=voiceClass.Volume;
synth.SpeakAsync(voiceClass.VoiceText);
}
catch(Exceptioner)
{
MessageBox.Show(er.ToString()??"???"??MessageBoxButtons.OK??MessageBoxIcon.Error);
}
}
///<summary>
///????
///</summary>
///<paramname="sender"></param>
///<paramname="e"></param>
privatevoidbtnSave_Click(objectsender??EventArgse)
{
if(IsVaild())
{
synth=GetSpeechSynthesizerInstance();
VoiceClassvoiceClass=GetVoiceClass();
synth.SelectVoice(voiceClass.VoiceName);
synth.Rate=voiceClass.Rate;
synth.Volume=voiceClass.Volume;
SaveFileDialogsaveFileDialog=newSaveFileDialog();
saveFileDialog.Title="???????";
saveFileDialog.Filter="*.wav|*.wav|*.mp3|*.mp3";
saveFileDialog.InitialDirectory=Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
DialogResultsaveDialog=saveFileDialog.ShowDialog();
try
{
if(saveDialog==System.Windows.Forms.DialogResult.OK)
{
synth.SetOutputToWaveFile(saveFileDialog.FileName);
synth.Speak(voiceClass.VoiceText);
synth.SetOutputToNull();
System.Diagnostics.Process.Start("Explorer.exe"??string.Format(@"/select??{0}"??saveFileDialog.FileName));//??wav??????????
}
}
catch(Exceptioner)
{
MessageBox.Show(er.ToString()??"???"??MessageBoxButtons.OK??MessageBoxIcon.Error);
}
}
}
///<summary>
///????
///</summary>
///<paramname="sender"></param>
///<paramname="e"></param>
privatevoidbtnContinum_Click(objectsender??EventArgse)
{
synth.Resume();
}
///<summary>
///???
///</summary>
///<paramname="sender"></param>
///<paramname="e"></param>
privatevoidbtnStop_Click(objectsender??EventArgse)
{
synth.Pause();
}

?????и????????????????????????????????μ?12345???????????????12345??????????1??2?3??4??塣????????????У??????鷳???????????лл??