Go to file
2025-06-28 11:34:19 +03:30
Assets first commit 2025-06-28 11:28:54 +03:30
Packages first commit 2025-06-28 11:28:54 +03:30
ProjectSettings first commit 2025-06-28 11:28:54 +03:30
UserSettings first commit 2025-06-28 11:28:54 +03:30
.gitignore gitignore 2025-06-28 11:32:35 +03:30
README.md Update README.md 2025-06-28 11:34:19 +03:30

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 plugin for package management
  • A WebSocket server (see below)

📦 Dependencies (via NuGet)

1. Install NuGetForUnity

  1. Download the latest .unitypackage from 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. Heres a Python example:

pip install websockets