public void startRecording(Dissonance.Audio.Capture.MicrophoneCapture micCapture) { workingDirectory = "RECORDING/"; // + DateTime.Now.ToString("MM.dd_hh:mm"); Directory.CreateDirectory(workingDirectory); Debug.Log(workingDirectory); StartWriting(workingDirectory + "/" + fileName); micCapture.Subscribe(this); recOutput = true; }
[CanBeNull] public static MicrophoneCapture Start([CanBeNull] string micName) { //Early exit - check if there are no microphones connected if (Microphone.devices.Length == 0) { Log.Warn("No microphone detected; disabling voice capture"); return(null); } //Check the micName and default to null if it's invalid (all whitespace or not a known device) if (string.IsNullOrEmpty(micName)) { micName = null; } else if (!Microphone.devices.Contains(micName)) { Log.Warn("Cannot find mic '{0}', using default mic", micName); micName = null; } //Get device caps and modify sample rate and frame size to match int minFreq; int maxFreq; Microphone.GetDeviceCaps(micName, out minFreq, out maxFreq); //Get device capabilities and choose a sample rate as close to 48000 as possible. If min and max are both zero that indicates we can use any sample rate var sampleRate = minFreq == 0 && maxFreq == 0 ? 48000 : Mathf.Clamp(48000, minFreq, maxFreq); var clip = Microphone.Start(micName, true, 10, sampleRate); if (clip == null) { Log.Warn("Failed to start microphone capture"); return(null); } var capture = new MicrophoneCapture(micName, clip); return(capture); }