简体   繁体   English

如何在naudio中逐帧直播mp3帧

[英]How to live stream mp3 frames by frames in naudio

I am trying to live stream the audio in mp3 format while recording but i cannot achieve good streaming quality. 我正在尝试在录制时以mp3格式实时流式传输音频,但是我无法获得良好的流式传输质量。

what i am doing is getting 10 seconds of PCM data from "WI_DataAvailable" and convert it to MP3 then send the frames in network. 我正在做的是从“ WI_DataAvailable”获取10秒的PCM数据,并将其转换为MP3,然后在网络中发送帧。 it produce little silent between the 10 sec of data. 在10秒的数据之间,它几乎不会产生静音。

I like to stream continues mp3 frames by frames while recording. 我喜欢在录制时逐帧连续播放mp3帧。 is there any proper way? 有什么适当的方法吗?

Given that LameMP3FileWriter takes a Stream to write to, I would suggest implementing your own stream class and simply writing all the data that arrives in the Write method to UDP. 鉴于LameMP3FileWriter需要写入一个Stream,我建议您实现自己的流类,并简单地将Write方法中到达的所有数据Write UDP。 Then you can pass this to the LameMP3FileWriter. 然后,您可以将其传递给LameMP3FileWriter。

Here's a bare-bones stream class that should get you started. 这是一个基本的流类,应该使您入门。 You'll need to fill in the blanks for method Write , and possibly Flush . 您需要填写Write方法的空白,可能还需要填写Flush I imagine you can leave everything else as NotImplemented. 我想您可以将其他所有内容保留为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();} 
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM