Esempio n. 1
0
 public void StartRecording()
 {
     if (voice == null)
     {
         voice = GameObject.Find("Voice").GetComponent <VoiceHandler>();
     }
     voice.StartRecording();
 }
Esempio n. 2
0
        /// <summary>
        /// Removes the handler
        /// </summary>
        /// <param name="handler">handler to remove</param>
        public override void RemoveVoiceHandler(VoiceHandler handler)
        {
            ulong id = handler.NetID;

            if (handlers.Remove(id) && (mutedIds[id] & MuteStatus.RemoteHasMutedLocal) == 0 && !handler.IsRecorder)
            {
                activeIdsToSendTo.Remove(id);
            }
        }
    public void RemoveSpeaker(CSteamID exited)
    {
        VoiceHandler handler = Workflow.GetTrackedHandlerById(exited.m_SteamID);

        if (handler)
        {
            SpeakerPool.Recycle(handler.gameObject);

            //Now that handler is disabled reset its initialization status
            Handler h = handler as Handler;
            if (h != null)
            {
                h.Reset();
                h.Identity.IsInitialized = false;
            }
        }
    }
Esempio n. 4
0
        /// <summary>
        /// Informs the workflow whenever an handler has been muted
        /// </summary>
        /// <param name="handler">handler obj to check</param>
        /// <param name="sendMsgOnlyIfDiffDetected">true if you wich to send a network message only when the mute status has changed</param>
        public override void IsHandlerMuted(VoiceHandler handler, bool sendMsgOnlyIfDiffDetected = true)
        {
            ulong handlerNetId = handler.NetID;

            if (!mutedIds.ContainsKey(handlerNetId))
            {
                mutedIds.Add(handlerNetId, MuteStatus.None);
            }

            if (!handlers.ContainsKey(handlerNetId) || handlers[handlerNetId].IsRecorder)
            {
                return;
            }

            bool isMuted = handler.IsOutputMuted;

            MuteStatus curr = mutedIds[handlerNetId];

            bool isMutedLocally = ((byte)curr & (byte)MuteStatus.LocalHasMutedRemote) != 0;

            bool diff = isMuted ? !isMutedLocally : isMutedLocally;

            if (diff)
            {
                if (!isMutedLocally)
                {
                    mutedIds[handlerNetId] = curr | MuteStatus.LocalHasMutedRemote;
                }
                else
                {
                    mutedIds[handlerNetId] = curr & ~MuteStatus.LocalHasMutedRemote;
                }
            }

            if (diff || !sendMsgOnlyIfDiffDetected)
            {
                Transport.SendMessageIsMutedTo(handlerNetId, isMuted);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Adds the handler. Handler should already be initialized before calling this method
        /// </summary>
        /// <param name="handler">handler to add</param>
        public override void AddVoiceHandler(VoiceHandler handler)
        {
            //Compatibility check between handler to add and manipulator
            AudioDataTypeFlag res = Manipulator.AvailableTypes & handler.AvailableTypes;

            if (res == AudioDataTypeFlag.None)
            {
                throw new ArgumentException("the given handler type is incompatible with the current audio data manipulator");
            }

            ulong id = handler.NetID;

            //handler is added and callback for when mic data is available is set on the handler
            handlers.Add(id, handler);

            IsHandlerMuted(handler, false);

            if (!handler.IsRecorder && (mutedIds[id] & MuteStatus.RemoteHasMutedLocal) == 0)
            {
                activeIdsToSendTo.Add(id);
            }
        }
Esempio n. 6
0
    public override void IsHandlerMuted(VoiceHandler handler, bool sendMsgOnlyWithDiffDetected = true)
    {
        ulong handlerNetId = handler.NetID;

        if (!HandlersMuteStatuses.ContainsKey(handlerNetId))
        {
            HandlersMuteStatuses.Add(handlerNetId, MuteStatus.None);
        }

        bool isMuted = handler.IsOutputMuted;

        MuteStatus curr = HandlersMuteStatuses[handlerNetId];

        bool isMutedLocally = ((byte)curr & (byte)MuteStatus.LocalHasMutedRemote) != 0;

        bool diff = isMuted ? !isMutedLocally : isMutedLocally;

        if (diff)
        {
            HandlersMuteStatuses[handlerNetId] = !isMutedLocally ? curr | MuteStatus.LocalHasMutedRemote : curr & ~MuteStatus.LocalHasMutedRemote;
            Transport.SendMessageIsMutedTo(handlerNetId, isMuted);
        }
    }
Esempio n. 7
0
        /// <summary>
        /// Processes mic data from the given handler
        /// </summary>
        /// <param name="handler">handler which has available mic data</param>
        public override void ProcessMicData(VoiceHandler handler)
        {
            //If voice chat is disabled or if the given handler is not a recorder do nothing
            if (!Settings.VoiceChatEnabled || Settings.MuteSelf || !handler.IsRecorder)
            {
                return;
            }

            //Compatibility check between manipulator and handler. If they are incompatible throw exception
            AudioDataTypeFlag res = handler.AvailableTypes & Manipulator.AvailableTypes;

            if (res == AudioDataTypeFlag.None)
            {
                throw new ArgumentException("the given handler type is incompatible with the current audio data manipulator");
            }

            VoicePacketInfo info;

            //determine which data format to use.
            if (res == AudioDataTypeFlag.Both)
            {
                res = formatToUse;
            }

            bool useSingle = res == AudioDataTypeFlag.Single;

            //Retrive data from handler input
            int count;

            if (useSingle)
            {
                info = handler.GetMicData(dataBuffer, 0, dataBuffer.Length, out count);
            }
            else
            {
                info = handler.GetMicDataInt16(dataBufferInt16, 0, dataBufferInt16.Length, out count);
            }

            //if data is valid go on
            if (info.ValidPacketInfo)
            {
                //packet buffer used to create the final packet is prepared
                packetBuffer.ResetSeekLength();

                //data recovered from input is manipulated and stored into the gamepacket
                if (useSingle)
                {
                    Manipulator.FromAudioDataToPacket(dataBuffer, 0, count, ref info, packetBuffer);
                }
                else
                {
                    Manipulator.FromAudioDataToPacketInt16(dataBufferInt16, 0, count, ref info, packetBuffer);
                }

                packetBuffer.CurrentSeek = 0;

                //if packet is valid send to transport
                if (info.ValidPacketInfo)
                {
                    Transport.SendToAll(packetBuffer, info, activeIdsToSendTo);
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Process the received packet data.
        /// </summary>
        /// <param name="receivedData">received raw data</param>
        /// <param name="startIndex">received raw data start index</param>
        /// <param name="length">received raw data length</param>
        /// <param name="netId">sender net id</param>
        public override void ProcessReceivedPacket(byte[] receivedData, int startIndex, int length, ulong netId)
        {
            //If voice chat is disabled do nothing
            if (!Settings.VoiceChatEnabled)
            {
                return;
            }

            //resets packet buffer
            packetBuffer.ResetSeekLength();

            //receive packet
            VoicePacketInfo info = Transport.ProcessReceivedData(packetBuffer, receivedData, startIndex, length, netId);

            //if packet is invalid or if there is not an handler for the given netid discard the packet received
            if (!info.ValidPacketInfo || !handlers.ContainsKey(netId))
            {
                return;
            }

            VoiceHandler handler = handlers[netId];

            //Do nothing if handler is either muted or if it is a recorder
            if (handler.IsOutputMuted || handler.IsRecorder)
            {
                return;
            }

            //Compatibility check between manipulator, handler and packet; if incompatible throw exception
            AudioDataTypeFlag res = Manipulator.AvailableTypes & handler.AvailableTypes & info.Format;

            if (res == AudioDataTypeFlag.None)
            {
                throw new ArgumentException("the given handler type is incompatible with the current audio data manipulator and the received packet format");
            }

            //determine which data format to use.
            if (res == AudioDataTypeFlag.Both)
            {
                res = formatToUse;
            }

            bool useSingle = res == AudioDataTypeFlag.Single;

            //packet received Seek to zero to prepare for data manipulation
            packetBuffer.CurrentSeek = 0;

            //Different methods between Int16 and Single format. Data manipulation is done and, if no error occurred, audio data is sent to the handler in order to be used as output sound
            if (useSingle)
            {
                int count = Manipulator.FromPacketToAudioData(packetBuffer, ref info, dataBuffer, 0);
                if (info.ValidPacketInfo)
                {
                    handler.ReceiveAudioData(dataBuffer, 0, count, info);
                }
            }
            else
            {
                int count = Manipulator.FromPacketToAudioDataInt16(packetBuffer, ref info, dataBufferInt16, 0);
                if (info.ValidPacketInfo)
                {
                    handler.ReceiveAudioDataInt16(dataBufferInt16, 0, count, info);
                }
            }
        }
Esempio n. 9
0
 private void SetupVoice()
 {
     Voice = new VoiceHandler(new Otto(Hue, Sonos, weather, Message));
 }
Esempio n. 10
0
 public override void RemoveVoiceHandler(VoiceHandler handler)
 {
     Handlers.Remove(handler.NetID);
 }
Esempio n. 11
0
 public override void ProcessMicData(VoiceHandler handler)
 {
     ProcessData = true;
 }
Esempio n. 12
0
 public override void AddVoiceHandler(VoiceHandler handler)
 {
     Handlers.Add(handler.NetID, handler);
     HandlersMuteStatuses.Add(handler.NetID, VOCASY.Common.MuteStatus.None);
 }