Exemplo n.º 1
0
        // ================================================
        // METHODS
        // ================================================
        /// <summary>
        /// Creates an instance and initialises with the given parameters
        /// </summary>
        /// <param name="sampleRate">The sample rate of the audio input. </param>
        /// <param name="bufferLengthSec">The buffer length in seconds</param>
        /// <param name="frameLengthMs">The frame length in milliseconds</param>
        /// <returns>A new instance</returns>
        public static MicrophoneManager Create(int sampleRate, int bufferLengthSec, int frameLengthMs)
        {
            GameObject cted = new GameObject("MicrophoneManager");

            DontDestroyOnLoad(cted);
            MicrophoneManager instance = cted.AddComponent <MicrophoneManager>();

            instance.m_SampleRate      = sampleRate;
            instance.m_BufferLengthSec = bufferLengthSec;
            instance.m_FrameLengthMs   = frameLengthMs;

            instance.m_AudioSource = cted.GetComponent <AudioSource>();
            instance.m_AudioFrame  = new float[instance.m_SampleRate / 1000 * instance.m_FrameLengthMs];

            foreach (var device in Microphone.devices)
            {
                instance.m_Devices.Add(device);
            }
            instance.m_CurrentDeviceIndex = 0;

            return(instance);
        }
Exemplo n.º 2
0
 void Start()
 {
     m_MicrophoneManager = MicrophoneManager.Create(16000, 1, 20);
     m_MicrophoneManager.SetRMSSmoothness(.05F);
     m_MicrophoneManager.StartRecording("TEST");
 }