如何在naudio中逐帧直播mp3
本文关键字:直播 mp3 naudio | 更新日期: 2023-09-27 18:24:58
我试图在录制时以mp3格式直播音频,但我无法实现良好的流媒体质量。
我正在做的是从"WI_DataAvailable"中获得10秒的PCM数据,并将其转换为MP3,然后在网络中发送帧。它在10秒的数据之间几乎不产生静音。
我喜欢在录制时逐帧流式传输连续的mp3。有什么合适的方法吗?
考虑到LameMP3FileWriter需要一个Stream来写入,我建议实现您自己的流类,并简单地将Write
方法中到达的所有数据写入UDP。然后您可以将其传递给LameMP3FileWriter。
这是一个基本的流类,应该可以让您开始学习。您需要填写方法Write
的空格,可能还有Flush
的空格。我想您可以将其他所有内容都保留为NotImplemented。
public class UdpStream:Stream
{
public override int Read(byte[] buffer, int offset, int count)
{
//you'll definitely need to implement this...
//write the buffer to UDP
}
public override void Flush()
{
//you might need to implement this
}
public override bool CanRead
{
get { return false; }
}
public override bool CanSeek
{
get { return false; }
}
public override bool CanWrite
{
get { return true; }
}
public override long Seek(long offset, SeekOrigin origin)
{
throw new NotImplementedException();
}
public override void SetLength(long value)
{
throw new NotImplementedException();
}
public override void Write(byte[] buffer, int offset, int count)
{
throw new NotImplementedException();
}
public override long Length
{
get { throw new NotImplementedException(); }
}
public override long Position {
get{throw new NotImplementedException();}
set{throw new NotImplementedException();}
}
}