+ 2
c#
SoundPlayer a = new SoundPlayer (@âD:\letter\a.wavâ); SoundPlayer b = new SoundPlayer (@âD:\letter\b.wavâ); SoundPlayer c = new SoundPlayer (@âD:\letter\c.wavâ); SoundPlayer d = new SoundPlayer (@âD:\letter\d.wavâ); SoundPlayer e = new SoundPlayer (@âD:\letter\e.wavâ); String allLetter=null; switch(allLetter) { caseâaâ: a.Play(); break; caseâbâ: b.Play(); break; caseâcâ: c.Play(); break; caseâdâ: d.Play(); break; caseâeâ: e.Play(); break; default: break; } This way is very long , how about short form?
1 Answer
+ 9
Assuming the variable allLetter represents the audio file name, you can try the following:-
var filePath = Path.Combine(@"D:\letter", quot;{ allLetter }.wav");
var soundPlayer = new SoundPlayer(filePath);
soundPlayer.Play();
Hopefully it helps! đ