【发布时间】:2019-08-13 05:24:30
【问题描述】:
我正在尝试使用 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);
}
}
}
【问题讨论】: