我有4种格式的音频流(.asx,.m3u,.mp3和.pls),我想将该音频流读入C#NAudio并将该音频转换为15秒的小块。
String url = "";
DateTime start = DateTime.Now;
using (Stream ms = new MemoryStream())
{
using (Stream stream = WebRequest.Create(url).GetResponse().GetResponseStream())
{
byte[] buffer = new byte[32768];
int read;
WaveFormat waveFormat = new WaveFormat(8000, 8, 2);
using (WaveFileWriter writer = new WaveFileWriter(@"C:\\Users\\Public\\Music\\Sample Music\\Test.wav", waveFormat))
{
while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, read);
writer.Write(buffer, 0, read);
var a = DateTime.Now - start;
if (a.TotalSeconds >= 15)
{
break;
}
}
}
}
}
在以下功能中创建的每段音频都会以静态形式返回。