我完成了我的项目,即文本文件和PDF文件中的文本到语音 但它不断地逐字读取整个文件。 我的问题:如果我想要程序读取一个单词,我已经通过双击它突出显示它, 我怎样才能在c#编码中做到这一点。
请帮帮我吗?
[
if (richTextBox1.Text != "")
{ try
{
switch (comboBox1.SelectedItem.ToString())
{
case "NotSet":
{ voice.SelectVoiceByHints(VoiceGender.NotSet);
voice.SpeakAsync(richTextBox1.Text);
voice.Volume = trackBar1.Value;
voice.Rate = trackBar2.Value;
}
break;
case "Male":
{
voice.SelectVoiceByHints(VoiceGender.Male);
voice.SpeakAsync(richTextBox1.Text);
voice.Volume = trackBar1.Value;
voice.Rate = trackBar2.Value;
}
break;
case "Neutral":
{
voice.SelectVoiceByHints(VoiceGender.Neutral);
voice.SpeakAsync(richTextBox1.Text);
voice.Volume = trackBar1.Value;
voice.Rate = trackBar2.Value;
}
break;
case "Samar":
{
// voice.SelectVoiceByHints(VoiceGender.Female);
voice.Volume = trackBar1.Value;
voice.Rate = trackBar2.Value;
Pause.Enabled = true;
Stop.Enabled = true;
//SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=speakerpro;Integrated Security=True");
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=speakerpro;Integrated Security=True");
//انشاء قائمة اصوات جديدة
WMPLib.IWMPPlaylist firstPlaylist = axWindowsMediaPlayer4.playlistCollection.newPlaylist("MyPlayList");
//تقسيم النص
string[] stArray = richTextBox1.Text.Trim().Split(' ');
foreach (string stWords in stArray)
{
SqlDataAdapter adp = new SqlDataAdapter("select path from [en1] where word = '" + stWords + "'", con);
DataTable dt = new DataTable();
adp.Fill(dt);
if (dt.Rows.Count == 0)
{
MessageBox.Show("error1");
}
else
{
//نضيف المسارات الى قائمة اولا بدون تشغيلها
var mediaItem = axWindowsMediaPlayer4.newMedia(dt.Rows[0]["path"].ToString());
firstPlaylist.appendItem(mediaItem);
// richTextBox3.SelectionBackColor = Color.Yellow;
//axWindowsMediaPlayer1.URL = ds.Tables["check"].Rows[0]["path"].ToString();
}
}
//تشغيل جميع المسارات
axWindowsMediaPlayer4.currentPlaylist = firstPlaylist;
//string txtstr = richTextBox3.Text.Trim() + " ";
}
break;
}
}
catch (Exception)
{
MessageBox.Show("Speak error", "SAH", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{ MessageBox.Show("Enter your text, please !"); }
}
private void button3_Click(object sender, EventArgs e)
{
voice.Pause();
Resume.Enabled = true;
}
private void button4_Click(object sender, EventArgs e)
{
voice.Resume();
}