mirror of
https://github.com/Dadechin/Unity-WebSocket.git
synced 2025-07-05 12:54:33 +00:00
Update README.md
This commit is contained in:
parent
c990256eac
commit
12ec54e0cf
62
README.md
62
README.md
|
@ -12,7 +12,7 @@ This Unity project demonstrates a real-time voice chat system using:
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- ✅ Record microphone audio in real time.
|
- ✅ Record microphone audio in real time.
|
||||||
- ✅ Apply a tunable bandpass filter to remove noise and improve voice clarity.
|
- ✅ Apply a bandpass filter with adjustable `lowFreq` and `highFreq`.
|
||||||
- ✅ Encode audio using Opus codec for low-latency transmission.
|
- ✅ Encode audio using Opus codec for low-latency transmission.
|
||||||
- ✅ Transmit voice data over a WebSocket connection.
|
- ✅ Transmit voice data over a WebSocket connection.
|
||||||
- ✅ Decode and playback received voice with a continuous audio stream.
|
- ✅ Decode and playback received voice with a continuous audio stream.
|
||||||
|
@ -24,49 +24,47 @@ This Unity project demonstrates a real-time voice chat system using:
|
||||||
### 🔧 Requirements
|
### 🔧 Requirements
|
||||||
|
|
||||||
- Unity 2020.3 or newer (tested on Unity 2021+)
|
- Unity 2020.3 or newer (tested on Unity 2021+)
|
||||||
- [WebSocketSharp](https://github.com/sta/websocket-sharp) library
|
- [NuGetForUnity](https://github.com/GlitchEnzo/NuGetForUnity) plugin for package management
|
||||||
- [Concentus Opus codec for C#](https://github.com/lostromb/concentus)
|
- A WebSocket server (see below)
|
||||||
- A WebSocket server (you can use a basic Python or Node.js echo server for testing)
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📦 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
|
## Project Structure
|
||||||
|
|
||||||
### 🎙️ `OpusMicRecorder.cs`
|
### 🎙️ `OpusMicRecorder.cs`
|
||||||
|
Captures microphone audio, filters it, and encodes using Opus.
|
||||||
- Captures microphone audio.
|
|
||||||
- Applies a bandpass filter with adjustable `lowFreq` and `highFreq`.
|
|
||||||
- Encodes audio using Opus (20ms frame).
|
|
||||||
- Sends encoded data through `OnEncodedAudio` event.
|
|
||||||
|
|
||||||
### 📤 `OpusVoiceSender.cs`
|
### 📤 `OpusVoiceSender.cs`
|
||||||
|
Sends encoded voice packets to a WebSocket server.
|
||||||
- Connects to a WebSocket server.
|
|
||||||
- Listens for encoded audio from `OpusMicRecorder`.
|
|
||||||
- Sends voice packets via WebSocket.
|
|
||||||
|
|
||||||
### 📥 `OpusVoiceReceiverWithBuffer.cs`
|
### 📥 `OpusVoiceReceiverWithBuffer.cs`
|
||||||
|
Receives Opus packets, decodes them, and streams via `AudioSource`.
|
||||||
- Connects to the same WebSocket server.
|
|
||||||
- Receives encoded Opus packets.
|
|
||||||
- Decodes them into PCM audio.
|
|
||||||
- Buffers the audio into a ring buffer for continuous playback using an `AudioSource`.
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Usage Instructions
|
## 🔌 WebSocket Server
|
||||||
|
|
||||||
### 1. Add Required Libraries
|
|
||||||
|
|
||||||
- Import `WebSocketSharp.dll` into your Unity project.
|
|
||||||
- Add the `Concentus` library (via Unity Package Manager or DLL).
|
|
||||||
|
|
||||||
### 2. Setup Scene
|
|
||||||
|
|
||||||
- Create an empty GameObject in your scene.
|
|
||||||
- Attach:
|
|
||||||
- `OpusMicRecorder`
|
|
||||||
- `OpusVoiceSender`
|
|
||||||
- `OpusVoiceReceiverWithBuffer`
|
|
||||||
|
|
||||||
|
You can use a simple WebSocket server for voice routing. Here’s a Python example:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip install websockets
|
||||||
|
|
Loading…
Reference in New Issue
Block a user