mirror of
https://github.com/Dadechin/Unity-WebSocket.git
synced 2025-07-01 19:04:35 +00:00
1.8 KiB
1.8 KiB
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
andhighFreq
. - ✅ 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 plugin for package management
- A WebSocket server (see below)
📦 Dependencies (via NuGet)
1. Install NuGetForUnity
- Download the latest
.unitypackage
from NuGetForUnity Releases - Import it into your Unity project (
Assets → Import Package → Custom Package
) - 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
orConcentus
bylostromb
)
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
.