Unity-WebSocket/README.md

62 lines
1.8 KiB
Markdown
Raw Permalink Normal View History

2025-06-28 07:42:11 +00:00
# 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.
2025-06-28 08:04:19 +00:00
- ✅ Apply a bandpass filter with adjustable `lowFreq` and `highFreq`.
2025-06-28 07:42:11 +00:00
- ✅ 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+)
2025-06-28 08:04:19 +00:00
- [NuGetForUnity](https://github.com/GlitchEnzo/NuGetForUnity) plugin for package management
- A WebSocket server (see below)
2025-06-28 07:42:11 +00:00
---
2025-06-28 08:04:19 +00:00
## 📦 Dependencies (via NuGet)
2025-06-28 07:42:11 +00:00
2025-06-28 08:04:19 +00:00
### 1. Install NuGetForUnity
2025-06-28 07:42:11 +00:00
2025-06-28 08:04:19 +00:00
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.
2025-06-28 07:42:11 +00:00
2025-06-28 08:04:19 +00:00
### 2. Install Required Packages
2025-06-28 07:42:11 +00:00
2025-06-28 08:04:19 +00:00
Use the **NuGet → Manage NuGet Packages** menu and search for:
2025-06-28 07:42:11 +00:00
2025-06-28 08:04:19 +00:00
- `Concentus` (e.g., `Concentus.Oggfile` or `Concentus` by `lostromb`)
Once installed, Unity will generate `.csproj` references for you.
2025-06-28 07:42:11 +00:00
2025-06-28 08:04:19 +00:00
> ✅ No need to manually copy DLLs!
2025-06-28 07:42:11 +00:00
---
2025-06-28 08:04:19 +00:00
## Project Structure
2025-06-28 07:42:11 +00:00
2025-06-28 08:04:19 +00:00
### 🎙️ `OpusMicRecorder.cs`
Captures microphone audio, filters it, and encodes using Opus.
2025-06-28 07:42:11 +00:00
2025-06-28 08:04:19 +00:00
### 📤 `OpusVoiceSender.cs`
Sends encoded voice packets to a WebSocket server.
2025-06-28 07:42:11 +00:00
2025-06-28 08:04:19 +00:00
### 📥 `OpusVoiceReceiverWithBuffer.cs`
Receives Opus packets, decodes them, and streams via `AudioSource`.