Hi guys,
I am trying to run voice over IP (by SmartFox server) using my purchased DFVoice package on Unity, my attempt was as follows:
On the first machine (let’s say a sender), I created an object and attached all required DFVoice components as well as a script as follows:
public class TestVoiceSender : VoiceControllerBase
{
byte[] headers;
byte[] dataFrame;
protected override void OnAudioDataEncoded (VoicePacketWrapper encodedFrame)
{
headers = encodedFrame.ObtainHeaders ();
dataFrame = encodedFrame.RawData;
NetworkManager.Instance.SendDFVoiceAudio (headers, dataFrame);
encodedFrame.ReleaseHeaders ();
}
public override bool IsLocal {
get {
return true;
}
}
}
}
The used Method “SendDFVoiceAudio” in NetworkManager class (which sends and receives from the server) contains of the following code:
public void SendDFVoiceAudio (byte[] header, byte[] dataFrame) {
ISFSObject parameters = new SFSObject ();
Room room = smartFox.LastJoinedRoom;
ByteArray h = new ByteArray (header);
ByteArray d = new ByteArray (dataFrame);
parameters.PutByteArray("headers", h);
parameters.PutByteArray("audio", d);
parameters.PutInt ("userId", smartFox.MySelf.Id);
Debug.Log ("Sent User Id: " + smartFox.MySelf.Id);
smartFox.Send (new ExtensionRequest ("DFAudio", parameters, room));
Debug.Log ("DFVoice Audio Sent");
}
On the second machine (the receiver), I created a method in the NetworkManger class, and attached the NetworkManager class to Unity receiver object as follows:
public void OnAudioDataReceived (ISFSObject dt) {
senderUser = dt.GetInt (“userId”);
Debug.Log ("Received user id: " + senderUser);
Sfs2X.Util.ByteArray headers = dt.GetByteArray("headers");
Debug.Log ("Received Header Size: " + headers.Length);
Sfs2X.Util.ByteArray audioData = dt.GetByteArray ("audio");
Debug.Log ("Received Audio Size: " + audioData.Length);
VoicePacketWrapper packet = new VoicePacketWrapper (headers.Bytes, audioData.Bytes);
ReceiveAudioData (packet);
Debug.Log ("Audio received OK! ");
}
public override bool IsLocal {
get {
return true;
}
}
Consoles on both machines as shown below giving me variable lengths of byte array of the audio when speaking on mic which is good, and however the sound does not appear on the second machine, so any help would highly be appreciated.
Sender machine:
On receiver machine:
Thanks.
Note: Most of code have been copied from DFVoice forum, but it still does not work.
Can you help me with this issue please?