tu masz kawałek kodu, w którym powinieneś znaleźć odpowiedź na swoje pytanie ;)
using SpeechLib; //Microsoft Speech Object Library
namespace SpeechLanguage
{
public partial class OptionForm : Form
{
public static SpVoice vox = new SpVoice();
public OptionForm()
{
InitializeComponent();
// Load the voices combo box
foreach (ISpeechObjectToken token in vox.GetVoices("", ""))
{
cboVoxOptions.Items.Add(token.GetDescription(0));
cboVoxOptions.SelectedIndex = 0;
}
}
void SayGreeting(String strUser)
{
// Now say something
vox.Voice = vox.GetVoices("", "").Item(0);
DateTime dt = DateTime.Now;
// clear your throat
vox.Speak("", SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak);
try
{
vox.Speak("Greetings " + strUser + " from English Speech", SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak);
vox.Speak("Today's Date is " + dt.ToShortDateString(), SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak);
vox.Speak("The time is " + dt.ToShortTimeString(), SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "I'm Speechless");
}
}
private void cboVoxOptions_SelectedIndexChanged(object sender, EventArgs e)
{
vox.Voice = vox.GetVoices("", "").Item(cboVoxOptions.SelectedIndex);
}
private void tbarRateOfSpeech_Scroll(object sender, EventArgs e)
{
vox.Rate = tbarRateOfSpeech.Value;
}
private void button1_Click(object sender, EventArgs e)
{
Close();
}
private void trackBar1_Scroll(object sender, EventArgs e)
{
vox.Volume = trackBarSpeechVolume.Value;
}
private void buttonTestSpeech_Click(object sender, EventArgs e)
{
Cursor.Current = Cursors.WaitCursor;
try
{
String str = Environment.UserName.ToString();
SayGreeting(str);
}
finally
{
Cursor.Current = Cursors.Default;
}
}
private void OptionForm_Load(object sender, EventArgs e)
{
trackBarSpeechVolume.Value = vox.Volume;
tbarRateOfSpeech.Value = vox.Rate;
}
}