Пример #1
0
        public void AwakeChat()
        {
            if (instance != null && instance != this)
            {
                Destroy(this);
                Debug.LogError("Only one instance of VoiceChatRecorder can exist");
                return;
            }
            instance = this;

            foreach (VoiceChatPlayer player in voiceChatPlayers)
            {
                player.StartChat();
            }

            Application.RequestUserAuthorization(UserAuthorization.Microphone);

            if (Microphone.devices.Length == 0)
            {
                Debug.LogError("Mic not found");
                return;
            }
            // VoiceChatSettings.Preset = VoiceChatPreset.Speex_8K;
            VoiceChatClient.StartClient();
        }
Пример #2
0
        void TransmitBuffer(float[] buffer)
        {
            int compressedSize = 0;

            byte[] compressedData = VoiceChatUtils.Compress(buffer, out compressedSize);
            if (finalPacket != null)
            {
                //Добавляем новый кусок в конец массива в пакете
                int    endOfPacket = finalPacket.Data.Length;
                byte[] resultArray = new byte[endOfPacket + compressedData.Length];
                for (int i = 0; i < finalPacket.Data.Length; i++)
                {
                    resultArray[i] = finalPacket.Data[i];
                }
                for (int i = 0; i < compressedData.Length; i++)
                {
                    resultArray[i + endOfPacket] = compressedData[i];
                }
                finalPacket.Data = resultArray;

                //если массив достаточно маленький или сжатых аудиокусков мало не отправляем.
                if (finalPacket.Data.Length < 400 && (finalPacket.Data.Length / finalPacket.CompressedSampleLen) < 4)
                {
                    return;
                }
            }
            else
            {
                finalPacket = new VoiceChatPacket();
                finalPacket.CompressedSampleLen = compressedSize;
                finalPacket.Data = compressedData;

                packetId            += 20;
                finalPacket.PacketId = packetId;

                //Debug.Log("create Packet. base Length= " + finalPacket.CompressedSampleLen + " array Length= " + finalPacket.Data.Length );

                //алав жмет плохо. поэтому пакет отправляется сразу
                if (VoiceChatSettings.compression == VoiceChatCompression.Speex)
                {
                    return;
                }
            }
            // Debug.Log("send Packet. base Length= " + finalPacket.CompressedSampleLen +  " array Length= " + finalPacket.Data.Length);

            totalSendedBytes += finalPacket.Data.Length;
            // Debug.Log("totalSendedBytes=" + totalSendedBytes);
            VoiceChatClient.SendPacket(finalPacket);
            finalPacket = null;
        }