我尝试使用C#通过IP进行语音聊天。首先,我已经连接了两台笔记本电脑。然后,我在两台笔记本电脑之间发送了邮件。然后我尝试发送副消息很难。我可以使用Naudio获得麦克风语音输入。然后,我应该进行采样并将波形文件放入字节数组中,并制作数据包并将其发送。在客户端,我应该捕获数据包并将其转换为声音。但是问题是我找不到任何有关转换和发送数据包的代码的材料。我搜索互联网,但找不到任何我能理解的东西。所以,请任何人帮助我做到这一点。我看到很多人在做的项目,但是很难理解。我是这个发送数据的初学者。
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);
}
}
}
答案 0 :(得分:1)
我认为您可以使用System.Net.Sockets.NetworkStream类:
这是一个类似的问题:get stream of a socket object in c#