Voice chat using NAudio, mic deviceNum
Hello. I hope you understand my weak English skills.
I'm developing a voice chat using NAudio.
Unity receives the microphone device number as a string. However, NAudio accepts the device number as an int.
(Example: in Unity : input = Microphone.devices[0].ToString(); // in NAudio : public int DeviceNumber { get; set; })
So I tried. However, I found an error as an int which is a string.
The reason is Microphone.devices [0] .ToString (); It is the name of the microphone.
The following is part of my code.
void Start() { // client = new UdpClient(); //client.Connect(hostip, port); //string micnum = Microphone. if (!connected) { IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(hostip), port); int inputDeviceNumber = Convert.ToInt32(Microphone.devices[0].ToString()); // int micnum = 0; //DeviceNum test this.codec = new G722ChatCodec(); Connect(endPoint, inputDeviceNumber, codec); } else { Disconncet(); } } private void Connect(IPEndPoint endPoint, int inputDeviceNumber, INetworkChatCodec codec) { waveln = new WaveIn(); waveln.BufferMilliseconds = 50; waveln.DeviceNumber = inputDeviceNumber; waveln.WaveFormat = codec.RecordFormat; waveln.DataAvailable += waveln_DataAvailable; waveln.StartRecording(); udpSender = new UdpClient(); udpListener = new UdpClient(); udpListener.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); udpListener.Client.Bind(endPoint); waveOut = new WaveOut(); waveProvider = new BufferedWaveProvider(codec.RecordFormat); waveOut.Init(waveProvider); waveOut.Play(); connected = true; ListenerThreadState state = new ListenerThreadState() {Codec = codec, EndPoint = endPoint }; ThreadPool.QueueUserWorkItem(this.ListenerThread, state); }
Thank you for your advice. Thank you for reading this article.
Your answer
Follow this Question
Related Questions
How to request Microphone Permisson for Mac OSX Standalone? 2 Answers
Microphone image button 0 Answers
Online client code execution 0 Answers
Can i use Vivox for my WebGL game? 1 Answer
reverberation time and microphone dB value visualisation 0 Answers