# Unity Socket Voice Chat Example ๐ŸŽ™๏ธ This Unity project demonstrates a real-time voice chat system using: - ๐ŸŽง **Microphone input with Opus codec (via Concentus)** - ๐Ÿ”Š **Dynamic bandpass audio filtering** - ๐Ÿ“ก **WebSocket communication (via WebSocketSharp)** - ๐ŸŽฎ **Unity AudioSource streaming with a circular buffer** --- ## Features - โœ… Record microphone audio in real time. - โœ… Apply a bandpass filter with adjustable `lowFreq` and `highFreq`. - โœ… Encode audio using Opus codec for low-latency transmission. - โœ… Transmit voice data over a WebSocket connection. - โœ… Decode and playback received voice with a continuous audio stream. --- ## Setup ### ๐Ÿ”ง Requirements - Unity 2020.3 or newer (tested on Unity 2021+) - [NuGetForUnity](https://github.com/GlitchEnzo/NuGetForUnity) plugin for package management - A WebSocket server (see below) --- ## ๐Ÿ“ฆ Dependencies (via NuGet) ### 1. Install NuGetForUnity 1. Download the latest `.unitypackage` from [NuGetForUnity Releases](https://github.com/GlitchEnzo/NuGetForUnity/releases) 2. Import it into your Unity project (`Assets โ†’ Import Package โ†’ Custom Package`) 3. A new **NuGet** menu will appear in the Unity toolbar. ### 2. Install Required Packages Use the **NuGet โ†’ Manage NuGet Packages** menu and search for: - `Concentus` (e.g., `Concentus.Oggfile` or `Concentus` by `lostromb`) Once installed, Unity will generate `.csproj` references for you. > โœ… No need to manually copy DLLs! --- ## Project Structure ### ๐ŸŽ™๏ธ `OpusMicRecorder.cs` Captures microphone audio, filters it, and encodes using Opus. ### ๐Ÿ“ค `OpusVoiceSender.cs` Sends encoded voice packets to a WebSocket server. ### ๐Ÿ“ฅ `OpusVoiceReceiverWithBuffer.cs` Receives Opus packets, decodes them, and streams via `AudioSource`. --- ## ๐Ÿ”Œ WebSocket Server You can use a simple WebSocket server for voice routing. Hereโ€™s a Python example: ```bash pip install websockets