An extensible voice chat/VoIP solution for Unity.
The recommended installation is via the UniVoice UPM package named com.adrenak.univoice
available on npmjs.org
Add the NPM registry with UniVoice as a scope. To do this, go to Edit/Project Settings/Package Manager
, add the NPM scope registry with the URL https://registry.npmjs.org
and add com.adrenak.univoice
as a scope.
Install the package from NPM registry To do this, go to Window/Package Manager
and refresh packages. Select in the My Registries
view (located at the top left, the default selection is Unity Registry
), locate UniVoice and click install. After installation, the package will show up in the In Project
view as well.
To be able to host and join voice chatrooms, you need a ChatroomAgent
instance.
var agent = new ChatroomAgent(IChatroomNetwork network, IAudioInput audioInput, IAudioOutputFactory audioOutputFactory);
agent.Network
is the most commonly accessed object to do things with UniVoice.
// Host a chatroom
agent.Network.HostChatroom(optional_data);
// Join an existing
agent.Network.JoinChatroom(optional_data);
// Leave the chatroom
agent.Network.LeaveChatroom(optional_data);
// Closes a chatroom
agent.Network.CloseChatroom(optional_data);
The current mode of the ChatroomAgent
can be accessed using agent.Network.CurrentMode
, this will return a ChatroomAgentMode
enum object, the possible values are:
Unconnected
: The agent is neither hosting or currently a guest of a chatroomHost
: The agent is currently hosting a chatroomGuest
: The agent is currently a guest in a chatroomEveryone in the chatroom is assigned an ID by the host. And everyone has a list of IDs of their peers. An ID in UniVoice is a C# short
that is unique for each member in the chatroom
To get your ID
short myID = agent.Network.OwnID;
To get a list of the other peers in the chatroom, use this:
short others = agent.Network.PeerIDs
To mute everyone in the chatroom, use agent.MuteOthers = true;
, set it to false
to unmute. This will stop audio from every peer in the chatroom.
To mute yourself to everyone in the chatroom use agent.MuteSelf = true;
set it to false
to unmute. This will stop sending your audio to the peers in the chatroom.
For muting a specific peer, first get the peers settings object using this:
agent.PeerSettings[id].muteThem = true; // where id belongs to the peer you want to mute
If you want to mute yourself towards a specific peer, use this:
agent.PeerSettings[id].muteSelf = true; // where id belongs to the peer you don't want to hear you
agent.Network
provides several network related events. Refer to the API reference for them.
UniVoice is a plug-and-play solution with several pre-existing modules. The most common use case (which is probably 3D/spatial audio group chat) doesn't need you to write any audio or networking code yourself
But it also offers you ways to extend and modify it.
UniVoice is audio input source agnostic. This means, it doesn't care where it is getting the audio from. It only cares about getting the audio data, giving you freedom to change where it gets that from.
The most common input source is real-time mic input. If this is what you're looking for, an official input implementation based on UniMic is available here which can be used for this.
The IAudioInput
interface API reference is here
UniVoice is also audio output agnostic. This means, it doesn't care what you do with the audio you receive from peers. It just gives you the data and forgets about it, leaving it up to you what you want to do with it.
The most common use output source is playing it inside your app. An official output implementation that plays peer audio on Unity AudioSource is available here
Creating an audio output requires implementing two interfaces. They are IAudioOutput
and IAudioOutputFactory
You guessed it. UniVoice is network agnostic. This means, it doesn't care how the audio is exchanged between peers. It just needs a networking implementation of its IChatroomNetwork
interface, which allows you to adapt it to different kinds of network infra.
Creating your own network requires you to implement the IChatroomNetwork
interface
Manual is not available yet. For the API reference, please visit http://www.vatsalambastha.com/univoice
A sample app is available here
This project is under the MIT license.
Updates and maintenance are not guaranteed and the project is maintained by the original developer in his free time. Community contributions are welcome.
Commercial consultation and development can be arranged but is subject to schedule and availability.
The developer Vatsal Ambastha can be reached at the following links: