2013-03-23 59 views
0

我正在構建一個語音控制應用程序,並且我想在用戶說出他的用戶名和密碼時設置文本框的文本,但是這不會發生,但是如果我顯示使用消息我的文本框的文本沒有改變(信息裏面)

public Form1() 
    { 
     InitializeComponent(); 

     GrammarBuilder g = new Choices("wissam.h44", "jordan_6"); 
     Grammar g1 = new Grammar(g); 
     Grammar g2 = new Grammar(g); 
     InitializeComponent(); 
     this.Shown += new System.EventHandler(this.Form1_Shown); 
     Recognizer1.LoadGrammar(g1); 
     Recognizer2.LoadGrammar(g2); 

    } 
    private void Form1_Shown(Object sender, EventArgs e) 
    { 
     Synthesizer1.Speak("Application is loaded."); 
     Synthesizer1.Speak("Please Enter Your Email: "); 
     Recognizer1.SpeechRecognized += 
     new EventHandler<SpeechRecognizedEventArgs>(recognizer1_SpeechRecognized); 
     Recognizer1.SetInputToDefaultAudioDevice(); 
     Recognizer1.Recognize(); 
     Synthesizer1.Speak("Please Enter Your Password: "); 
     Recognizer2.SpeechRecognized += 
     new EventHandler<SpeechRecognizedEventArgs>(recognizer2_SpeechRecognized); 
     Recognizer2.SetInputToDefaultAudioDevice(); 
     Recognizer2.Recognize(); 

    } 
    void recognizer1_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) 
    { 
     string eml = e.Result.Text; 
     txtemail.Text = eml; 
    } 
    void recognizer2_SpeechRecognized(object sender, SpeechRecognizedEventArgs r) 
    { 
     txtpwd.Text = r.Result.Text; 
    } 

所以在講話中確認的事件識別的字符串,如果我把MessageBox.Show(EML)正確顯示的電子郵件,但文本框的文本沒有改變

回答

0

最有可能識別的文本包含新的行字符,或類似的東西。

若要找出這個問題,嘗試在* SpeechRecognized事件明確了具體的字符串,如

txtemail.Text = "recognized text"; 

將它的工作?如果是,則檢查調試器中的字符串是否存在特定字符。

+0

它沒有工作,問題是在文本框中,是否有任何屬性,我可能已經改變了錯誤,所以現在我不能以編程方式設置文本? – 2013-03-23 21:11:23

+0

你在更改正確的文本框嗎?你能改變設計師的文本框文字嗎?你可以嘗試在設計器中刪除和和表單上的文本框 - 它會有幫助嗎? – Lanorkin 2013-03-23 22:22:11

相關問題