1
我的c#代碼如下,它沒有提供任何錯誤,但沒有聲音輸出。我使用來自COM14端口的putty和受監控的數據流很好。這是我第一次在NAudio中,所以不知道那我做錯了什麼。NAudio流媒體播放器沒有聲音輸出
WaveInEvent waveSource;
WaveOut waveOut = new WaveOut();
WaveFormat format = new WaveFormat(8000, 16, 1);
public int audioCounter = 0;
public byte[] buffer;
private BufferedWaveProvider _bufferedWaveProvider = new BufferedWaveProvider(new WaveFormat(16000, 16, 1));
private void btn_scan_Click(object sender, EventArgs e)
{
string temppoteName = "COM14";
SerialPort tempSerialPort = new SerialPort(temppoteName, 57600, Parity.None, 8, StopBits.One);
tempSerialPort.Open();
tempSerialPort.DataReceived += new SerialDataReceivedEventHandler(comPort14_DataReceived);
}
private void comPort14_DataReceived(object sender,SerialDataReceivedEventArgs e)
{
SerialPort sp = (SerialPort)sender;
string indata = sp.ReadExisting();
Console.WriteLine("Data Started Reciving :" + sp.PortName);
waveSource = new WaveInEvent();
waveSource.WaveFormat = new WaveFormat(8000, 16, 1);
waveOut.DesiredLatency = 100;
int x = sp.BytesToRead;
buffer = new byte[x];
sp.Read(buffer, 0, x);
_bufferedWaveProvider.AddSamples(buffer, 0, x);
if (audioCounter == 0)
{
waveOut.Init(_bufferedWaveProvider);
}
waveOut.Play();
++audioCounter;
}