I decided to delve deeper into the code and figured it out a little.
Sample code was created in NetworkManager
public ChatroomAgent agent;
public override void Start()
{
base.Start();
InitializeAgent();
}
void InitializeAgent()
{
var cac = new CircularAudioClip(8000, 1, 200, segCount: 10);
agent = new ChatroomAgent(
new UniVoiceMirrorNetwork(),
new VoiceChatMic(0, 8000, 25),
new CustomFactory(10, 5, cac)
);
}
I slightly rewrote IAudioInput, otherwise on a server where there is no microphone an error occurred that did not allow me to go further
public class VoiceChatMic : IAudioInput
{
//do do do
public VoiceChatMic(int deviceIndex = 0, int frequency = 16000, int sampleLen = 100)
{
if (Mic.Instance.Devices.Count > 0)
{
Mic.Instance.SetDeviceIndex(deviceIndex);
Mic.Instance.StartRecording(frequency, sampleLen);
Debug.Log("UniVoiceUniMicInput: Start recording.");
Mic.Instance.OnSampleReady += Mic_OnSampleReady;
}
else Debug.LogWarning("Must have recording devices for Microphone input");
}
}
From the tests, the best option is 8000 kHz and 25 ms with Telepathy transport; the rest are just terrible sound. Something needs to be done with the packet size. Size 1194 clearly doesn't fit
CustomFactory
public class CustomFactory : IAudioOutputFactory
{
public int BufferSegCount { get; private set; }
public int MinSegCount { get; private set; }
public CircularAudioClip cac { get; private set; }
public AudioSource audioSource { get; set; }
public CustomFactory(int bufferSegCount, int minSegCount, CircularAudioClip _cac)
{
BufferSegCount = bufferSegCount;
MinSegCount = minSegCount;
cac = _cac;
}
public IAudioOutput Create(int samplingRate, int channelCount, int segmentLength)
{
audioSource = new GameObject($"UniVoiceAudioSourceOutput").AddComponent<AudioSource>();
audioSource.minDistance = 20;
audioSource.maxDistance = 100;
audioSource.spatialBlend = 0.85f;
return UniVoiceAudioSourceOutput.New(cac, audioSource, MinSegCount);
}
}
public override void OnStartServer()
{
base.OnStartServer();
var audio = FindObjectOfType<UniVoiceAudioSourceOutput>().transform;
if (audio != null)
{
audio.parent = transform;
audio.position = transform.position;
}
else
{
Debug.LogError("audio not found");
}
}
Now, after all the manipulations, the audio source is created and placed as a child of the player on the server. Everything is amazing. But I still haven’t been able to implement it so that I can only hear nearby players. I can still hear everyone
Hello @adrenak :)
I decided to delve deeper into the code and figured it out a little.
CustomFactory
Now, after all the manipulations, the audio source is created and placed as a child of the player on the server. Everything is amazing. But I still haven’t been able to implement it so that I can only hear nearby players. I can still hear everyone