public static void PlayFromFile(string filename, int frequency)
{
using (
FileStream stream = new FileStream(filename, FileMode.Open))
{
var waveFormat = WaveFormat.CreateMuLawFormat(frequency * 2, 1);
var reader = new NAudio.Wave.RawSourceWaveStream(stream, waveFormat);
using (WaveStream convertedStream = WaveFormatConversionStream.CreatePcmStream(reader))
{
convertedStream.Seek(0, 0);
WaveOutEvent player = new WaveOutEvent();
WaveChannel32 volumeStream = new WaveChannel32(convertedStream);
player.Init(volumeStream);
player.Play();
while (player.PlaybackState == PlaybackState.Playing)
{
System.Threading.Thread.Sleep(100);
var input = Console.ReadKey();
if (input.KeyChar > 1) ;
{
player.Stop();
}
}
}
}
}