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); }
private void Awake() { // Create and initialize the chorus filter. if (UseChorus) { chorusFilter = gameObject.AddComponent <AudioChorusFilter>(); chorusFilter.enabled = true; UpdateChorusFilter(); } // Create and initialize the echo filter. if (UseEcho) { echoFilter = gameObject.AddComponent <AudioEchoFilter>(); echoFilter.enabled = true; UpdateEchoFilter(); } // Confgure the microphone stream to use the high quality voice source // at the application's output sample rate. MicStream.MicInitializeCustomRate( (int)MicStream.StreamCategory.HIGH_QUALITY_VOICE, AudioSettings.outputSampleRate); // Set the initial microphone gain. MicStream.MicSetGain(InputGain); // Start the stream. // Do not keep the data and do not preview. MicStream.MicStartStream(false, false); MicStream.MicPause(); }
private void Awake() { audioSource = GetComponent <AudioSource>(); int errorCode = MicStream.MicInitializeCustomRate((int)Streamtype, AudioSettings.outputSampleRate); CheckForErrorOnCall(errorCode); if (errorCode == 0 || errorCode == (int)MicStream.ErrorCodes.ALREADY_RUNNING) { if (CheckForErrorOnCall(MicStream.MicSetGain(InputGain))) { audioSource.volume = HearSelf ? 1.0f : 0.0f; micStarted = CheckForErrorOnCall(MicStream.MicStartStream(false, false)); } } }
// Update is called once per frame void Update () { if (Input.GetKeyDown(KeyCode.W)) { samplingData.Clear(); CheckForErrorOnCall(MicStream.MicStartStream(KeepAllData, false)); CheckForErrorOnCall(MicStream.MicSetGain(InputGain)); _isStart = true; } else if (Input.GetKeyDown(KeyCode.S)) { _isStart = false; CheckForErrorOnCall(MicStream.MicStopStream()); WriteAudioData(); } }
private void Awake() { CheckForErrorOnCall(MicStream.MicInitializeCustomRate((int)StreamType, AudioSettings.outputSampleRate)); CheckForErrorOnCall(MicStream.MicSetGain(InputGain)); if (!ListenToAudioSource) { this.gameObject.GetComponent <AudioSource>().volume = 0; // can set to zero to mute mic monitoring } if (AutomaticallyStartStream) { CheckForErrorOnCall(MicStream.MicStartStream(KeepAllData, false)); } print("MicStream selector demo"); print("press Q to start stream to audio source, W will stop that stream"); print("It will start a recording and save it to a wav file. S will stop that recording."); print("Since this all goes through the AudioSource, you can mute the mic while using it there, or do anything else you would do with an AudioSource"); print("In this demo, we start the stream automatically, and then change the size of the gameobject based on microphone signal amplitude"); }