mirror of
https://github.com/Dadechin/Unity-WebSocket.git
synced 2025-07-04 20:34:34 +00:00
62 lines
1.8 KiB
Markdown
62 lines
1.8 KiB
Markdown
# 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`.
|