UniVoice 4.x.x: Upgrade guide
A lot has changed between UniVoice v3 and v4, however I've tried to keep the new things "mirror" some old patterns as much as possible.
There's no way to upgrade from v3 to v4 without code changes, so getting familiar with some key changes can help.
In this post I'll be comparing the sample code for v4 and v3 and try to describe the differences that have been made.
Namespace changes
In v3 you'll notice these namespaces
Adrenak.UniVoice.UniMicInput
Adrenak.UniVoice.AudioSourceOutput
Adrenak.UniVoice.AirPeerNetwork
This is a remnant of the previous multi-repo approach where each repo had their own namespaces. UniVoice changed to a mono-repo one as described in an earlier post with the key reason being ease of maintenance and integration.
From v4 onwards, you can expect to need only the following namespaces:
Adrenak.UniVoice.Networks;
Adrenak.UniVoice.Outputs;
Adrenak.UniVoice.Inputs;
Adrenak.UniVoice.Filters;
With all related implementations being under the same namespace. For example, OpusEncoder, OpusDecoder, RNNoiseFilter are all implementations of IAudioFilter and are under Adrenak.UniVoice.Filters namespace
This would be the case for "official" implementations. For your own, you of course can use any namespace.
UniVoice no longer allows you to host, create, join or leave the chatroom
The IChatroomNetwork interface used to allow you to handle the lifecycle of the network, as seen under the "METHODS" region here
However after v4, UniVoice now only reacts to your network state. It only tells you if the device has connected/disconnected or a peer has connected/disconnected. It does so using the events of the underlying networking plugin. For example, the MirrorClient implementation of IAudioClient<T> internally hooks on to the Mirror events to invoke the events provided by the interface.
This allows you to handle networking via the underlying plugin with univoice never interfering with it. Univoice only "piggybacks" on the underlying networking plugin to send data.
ChatroomAgent replaced by ClientSession<T>
Major changes were made to the IChatroomNetwork interface in v3 and it was split into IAudioClient<T> and IAudioServer<T> which allowed implementing the server and client code for a network to be written in two different classes. To handle the lifecycle of a client, the ClientSession class was created which replaces ChatroomAgent.
Notice here: v4 vs v3 that their constructions are similar and provide similar events that can subscribe to.
Filters to change incoming and outgoing audio
Audio can be processed before it leaves and after it arrives. This has been added as IAudioFilter interface which can be implemented.
In the v4 samples, you can see the Opus encode and decode filters being registered during initialization to ensure that outgoing audio is encoded and incoming audio is decoded properly.
Similarly, a noise filtering filter called RNNoiseFilter has been introduced in version 4.2.0. Read more about it here
Concluding
This post along with comparing the v3 and v4 samples, and reading through the comments in the v4 samples is the best way to get familiar with the breaking changes that has been introduced.
As usual you can reach out to me via email or discord. Links available on the menu of this page.
Comments