Пример #1
0
    void Start()
    {
        if (!photonView.IsMine)
        {
            return;
        }

        audioListener.enabled = true;

        if (!CustomMicrophone.HasConnectedMicrophoneDevices())
        {
            CustomMicrophone.RefreshMicrophoneDevices();
        }
        Debug.Log(CustomMicrophone.devices.Length + " microphone devices found");

        if (!CustomMicrophone.HasConnectedMicrophoneDevices())
        {
            Debug.Log("no microphone device connected");
        }

        _microphoneDevice = CustomMicrophone.devices[0];
        audioClip         = CustomMicrophone.Start(_microphoneDevice, true, lengthSec, frequency);

        //subscribe to events
        VoiceChat.Instance.OnStatusUpdate += OnStatusupdate;
        VoiceChat.Instance.OnIDUpdate     += OnIDUpdate;

        //initialize peer object for this client
        VoiceChat.Instance.InitializePeer();
    }
Пример #2
0
        private void StartRecord()
        {
            if (!CustomMicrophone.HasConnectedMicrophoneDevices())
            {
                return;
            }

            _workingClip = CustomMicrophone.Start(CustomMicrophone.devices[0], true, 4, 44100);
        }
Пример #3
0
        private void StartRecord()
        {
            if (!CustomMicrophone.HasConnectedMicrophoneDevices())
            {
                return;
            }

            _workingClip = CustomMicrophone.Start(selectedDevice, false, recordingTime, frequency);
        }
Пример #4
0
    private IEnumerator RecordingHandler()
    {
        //Log.Debug("STT.RecordingHandler()", "devices: {0}", Microphone.devices);
        _recording = CustomMicrophone.Start(_microphoneID, true, _recordingBufferSize, _recordingHZ);

        yield return(null);      // let _recordingRoutine get set..

        if (_recording == null)
        {
            StopRecording();
            yield break;
        }

        bool bFirstBlock = true;
        int  midPoint    = _recording.samples / 2;

        float[] samples = null;

        while (_recordingRoutine != 0 && _recording != null)
        {
            int writePos = CustomMicrophone.GetPosition(_microphoneID);
            if (writePos > _recording.samples || !CustomMicrophone.IsRecording(_microphoneID))
            {
                Log.Error("STT.RecordingHandler()", "Microphone disconnected.");
                StopRecording();
                yield break;
            }

            if ((bFirstBlock && writePos >= midPoint) ||
                (!bFirstBlock && writePos < midPoint))
            {
                // front block is recorded, make a RecordClip and pass it onto our callback.
                samples = new float[midPoint];
                _recording.GetData(samples, bFirstBlock ? 0 : midPoint);

                AudioData record = new AudioData();
                record.MaxLevel = Mathf.Max(Mathf.Abs(Mathf.Min(samples)), Mathf.Max(samples));
                record.Clip     = AudioClip.Create("Recording", midPoint, _recording.channels, _recordingHZ, false);
                record.Clip.SetData(samples, 0);

                _service.OnListen(record);

                bFirstBlock = !bFirstBlock;
            }
            else
            {
                // calculate the number of samples remaining until we ready for a block of audio,
                // and wait that amount of time it will take to record.
                int   remaining     = bFirstBlock ? (midPoint - writePos) : (_recording.samples - writePos);
                float timeRemaining = (float)remaining / (float)_recordingHZ;

                yield return(new WaitForSeconds(timeRemaining));
            }
        }

        yield break;
    }
Пример #5
0
        public void StartRecord(bool withVoiceDetection = false)
        {
            if (IsRecording)
            {
                return;
            }

            if (!ReadyToRecord())
            {
#if NET_2_0 || NET_2_0_SUBSET
                if (RecordFailedEvent != null)
                {
                    RecordFailedEvent();
                }
#else
                RecordFailedEvent?.Invoke();
#endif
                return;
            }

            DetectVoice = withVoiceDetection;

            _maxVoiceFrame = 0;

            _currentRecordingVoice = new List <float>();

            if (_microphoneWorkingAudioClip != null)
            {
                MonoBehaviour.Destroy(_microphoneWorkingAudioClip);
            }

            if (LastRecordedClip != null)
            {
                MonoBehaviour.Destroy(LastRecordedClip);
            }

            _microphoneWorkingAudioClip = CustomMicrophone.Start(MicrophoneDevice, true, 1, 16000);

            _currentAudioSamples = new float[_microphoneWorkingAudioClip.samples * _microphoneWorkingAudioClip.channels];

            IsRecording = true;

#if NET_2_0 || NET_2_0_SUBSET
            if (RecordStartedEvent != null)
            {
                RecordStartedEvent();
            }
#else
            RecordStartedEvent?.Invoke();
#endif
        }
Пример #6
0
        /// <summary>
        /// Starts recording of microphone
        /// </summary>
        public void StartRecord()
        {
            if (CustomMicrophone.IsRecording(_microphoneDevice) || !CustomMicrophone.HasConnectedMicrophoneDevices())
            {
                RecordFailedEvent?.Invoke("record already started or no microphone device conencted");
                return;
            }

            recording = true;

            _workingClip = CustomMicrophone.Start(_microphoneDevice, true, Constants.RecordingTime, Constants.SampleRate);

            RecordStartedEvent?.Invoke();
        }
Пример #7
0
        private void StartRecordHandler()
        {
            if (!CustomMicrophone.HasConnectedMicrophoneDevices())
            {
                return;
            }

#if UNITY_EDITOR
            _audioSource.clip =
#endif
            CustomMicrophone.Start(CustomMicrophone.devices[0], true, _recordingTime, _sampleRate);
#if UNITY_EDITOR
            _audioSource.loop = true;
            _audioSource.Play();
#endif
        }
        public IEnumerator OneTimeRecord(int durationSec, Action <AudioClip> callback, int sampleRate = 16000)
        {
            AudioClip clip = CustomMicrophone.Start(MicrophoneDevice, false, durationSec, sampleRate);

            yield return(new WaitForSeconds(durationSec));

            CustomMicrophone.End(MicrophoneDevice);

#if !NET_2_0 && !NET_2_0_SUBSET
            callback?.Invoke(clip);
#else
            if (callback != null)
            {
                callback(clip);
            }
#endif
        }
Пример #9
0
        public IEnumerator OneTimeRecord(int durationSec, Action <float[]> callback, int sampleRate = 16000)
        {
            AudioClip clip = CustomMicrophone.Start(MicrophoneDevice, false, durationSec, sampleRate);

            yield return(new WaitForSeconds(durationSec));

            CustomMicrophone.End(MicrophoneDevice);

            float[] array = new float[clip.samples * clip.channels];

            CustomMicrophone.GetRawData(ref array, clip);

#if !NET_2_0 && !NET_2_0_SUBSET
            callback?.Invoke(array);
#else
            if (callback != null)
            {
                callback(array);
            }
#endif
        }