2014-10-29 92 views
0

我已經完成了從文本文件和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(); 
    } 

]

+2

'richTextBox.SelectedText'。 – 2014-10-29 22:51:06

回答

1

使用的RichTextBox的SelectedText屬性:

voice.SpeakAsync(richTextBox1.SelectedText); 
+0

非常感謝^ _ ^ – user3676903 2014-10-30 21:40:40

相關問題