使用C#通过IP进行实时语音聊天



我尝试使用C#通过IP进行语音聊天。首先,我连接了两台笔记本电脑。然后,我在两台笔记本电脑之间发送了消息。然后,我尝试发送副消息,这很困难。我使用Naudio获得麦克风语音输入。然后,我应该进行采样,然后将Wave File放入字节数组中,然后制作数据包并发送。在客户端,我应该捕获数据包并将其转换为声音。但是问题是我找不到有关用于转换和发送数据包的代码的任何材料。我搜索互联网,但找不到我能理解的任何东西。所以请任何人帮助我这样做。我看到许多人从事的项目,但是这些项目很难理解。我是关于此发送数据的初学者。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;``
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Net;
using System.Net.Sockets;
using System.IO;
namespace Tutorial7
{
   public partial class Form1 : Form
   {
       Socket sock;
       Socket acc;
       public Form1()
       {
           InitializeComponent();
       }
       Socket socket()
       {
           return new Socket(AddressFamily.InterNetwork, SocketType.Stream, 
           ProtocolType.Tcp);
       }
       private void button1_Click(object sender, EventArgs e)
       {
           List<NAudio.Wave.WaveInCapabilities> sources = new 
           List<NAudio.Wave.WaveInCapabilities>();
           for (int i = 0; i < NAudio.Wave.WaveIn.DeviceCount; i++)
           {
               sources.Add(NAudio.Wave.WaveIn.GetCapabilities(i));
           }
           sourceList.Items.Clear();
           foreach (var source in sources)
           {
               ListViewItem item = new ListViewItem(source.ProductName);
               item.SubItems.Add(new ListViewItem.ListViewSubItem(item, 
                   source.Channels.ToString()));
               sourceList.Items.Add(item);
           } 
       }
       NAudio.Wave.WaveIn sourceStream = null;
       NAudio.Wave.DirectSoundOut waveOut = null;
       NAudio.Wave.WaveFileWriter waveWriter = null;
       private void button2_Click(object sender, EventArgs e)
       {
           if (sourceList.SelectedItems.Count == 0) return;
           int deviceNumber = sourceList.SelectedItems[0].Index;
           sourceStream = new NAudio.Wave.WaveIn();
           sourceStream.DeviceNumber = deviceNumber;
           sourceStream.WaveFormat = new NAudio.Wave.WaveFormat(44100, 
           NAudio.Wave.WaveIn.GetCapabilities(deviceNumber).Channels);
           NAudio.Wave.WaveInProvider waveIn = new 
           NAudio.Wave.WaveInProvider(sourceStream);
        }
    }
}

我认为您可以使用System.net.sockets.networkStream类:

看:https://learn.microsoft.com/en-us/dotnet/api/system.net.sockets.networkStream?rediretectedfrom = msdn&amp; view = netframework-4.7.2

这是一个类似的问题:获取C#

中的插座对象的流

最新更新