private void Update() { CheckForErrorOnCall(MicStream.MicSetGain(InputGain)); if (Input.GetKeyDown(KeyCode.Q)) { CheckForErrorOnCall(MicStream.MicStartStream(KeepAllData, false)); } else if (Input.GetKeyDown(KeyCode.W)) { CheckForErrorOnCall(MicStream.MicStopStream()); } else if (Input.GetKeyDown(KeyCode.A)) { CheckForErrorOnCall(MicStream.MicStartRecording(SaveFileName, false)); } else if (Input.GetKeyDown(KeyCode.S)) { string outputPath = MicStream.MicStopRecording(); Debug.Log("Saved microphone audio to " + outputPath); CheckForErrorOnCall(MicStream.MicStopStream()); } gameObject.transform.localScale = new Vector3(minObjectScale + averageAmplitude, minObjectScale + averageAmplitude, minObjectScale + averageAmplitude); }
/// <summary> /// starts the recording. /// </summary> void StartRecording() { WEKITSpeechManager.Instance.PauseRecognizer(); Debug.Log("Stopped listening to voice commands."); isRecording = true; if (useUnityMic) { //Check if there is at least one microphone connected if (Microphone.devices.Length <= 0) { //Throw a warning message at the console if there isn't Debug.LogWarning("Microphone not connected!"); } else //At least one microphone is present { //Set 'micConnected' to true micConnected = true; //Get the default microphone recording capabilities Microphone.GetDeviceCaps(null, out minFreq, out maxFreq); //According to the documentation, if minFreq and maxFreq are zero, the microphone supports any frequency... if (minFreq == 0 && maxFreq == 0) { //...meaning 44100 Hz can be used as the recording sampling rate maxFreq = 44100; } //Get the attached AudioSource component goAudioSource = this.GetComponent <AudioSource>(); //If the audio from any microphone isn't being captured if (!Microphone.IsRecording(null)) { //Start recording and store the audio captured from the microphone at the AudioClip in the AudioSource goAudioSource.clip = Microphone.Start(null, true, 20, maxFreq); } } } else { CheckForErrorOnCall(MicStream.MicInitializeCustomRate((int)StreamType, AudioSettings.outputSampleRate)); CheckForErrorOnCall(MicStream.MicSetGain(InputGain)); //CheckForErrorOnCall(MicStream.MicStartStream(KeepAllData, false)); SaveFileName = "WEKIT_Audio_" + DateTime.Now.ToFileTimeUtc() + ".wav"; CheckForErrorOnCall(MicStream.MicStartRecording(SaveFileName, false)); } Debug.Log("Started audio recording"); changeColor(Color.red); }