2012-08-01 9 views
1

내 프로젝트는 내레이터를 사용하여 모든 단어를 재생하는 방법은 무엇입니까?


string amma = myacess.Text; 
// string[] words = Regex.Split(amma,"*"); 
char[] delimeter = new char[] { '*' }; 
string[] words = amma.Split(delimeter, StringSplitOptions.RemoveEmptyEntries); 
for(int i = 0; i < words.Length; i++) { 
    string audio = words[i]; 
    if(audio == "a") { 
     SoundPlayer sndplayr = new SoundPlayer(WindowsFormsApplication1.Properties.Resources.aa); 
     sndplayr.Play(); 

    } 
    if(audio == "u") { 
     SoundPlayer sndplayr = new SoundPlayer(WindowsFormsApplication1.Properties.Resources.i); 
     sndplayr.Play(); 
    } 
} 

하지만 입력 텍스트가 "AU는"그것은 단지 "U"사운드를 재생합니다, 내 코드는 여기에, 음성 프로젝트에 텍스트입니다. 하지만 브레이크 포인트를 놓고 F11을 누르면 사운드와 사운드가 재생됩니다. 뒤에 이유가 무엇입니까. 도와 주실 수 있으신가요?

+0

thanx Tim, 문제 해결을 도와 줄 수 있습니까? – user1567372

답변

0

하지만 중단 점을 넣고 F11 키를 누르면 사운드가 재생되고 u 소리가납니다. 뒤에 이유가 무엇입니까. 도와 주실 수 있으신가요?

for 루프가 너무 빠르다는 것이 문제라고 생각합니다.

그래서 당신은이 방법으로 Timer (System.Windows.Forms.Timer)를 사용할 수 있습니다 :

private Timer timer; 
private int i; 

string amma = myacess.Text; 
// string[] words = Regex.Split(amma,"*"); 
char[] delimeter = new char[] { '*' }; 
string[] words = amma.Split(delimeter, StringSplitOptions.RemoveEmptyEntries); 

//... 

timer = new Timer(); 
timer.Interval = 100; //milliseconds 
timer.Tick = += new EventHandler(timer_Tick); 
timer.Enabled = true; //start the timer 

i = 0; 

void timer_Tick(object sender, EventArgs e){ 
    if(i < word.Lenght){ 
     string audio = words[i]; 
     if(audio == "a") { 
      SoundPlayer sndplayr = new SoundPlayer(WindowsFormsApplication1.Properties.Resources.aa); 
      sndplayr.Play(); 
     } 
     if(audio == "u") { 
      SoundPlayer sndplayr = new SoundPlayer(WindowsFormsApplication1.Properties.Resources.i); 
      sndplayr.Play(); 
     } 

     i++; //increase i to change letter like in the loop 
    } 
    else{ 
     timer.Enabled = false; //stop the timer 
     i = 0; 
    } 
} 
+0

예, 고맙습니다. .......... – user1567372

+0

당신은 천만에요. 그것이 효과가 있다면 대답을 받아주십시오. 여기 어떻게 보이는지 모르는 경우 : [답변 수락 방법은 무엇입니까?] (http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) 감사합니다. –

0

사용 SoundPlayer.PlaySync Method 대신 SoundPlayer.Play. 이렇게하면 이전 사운드가 끝난 후 다음 사운드를 시작할 수 있습니다.