Exemplo n.º 1
0
    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();
    }
Exemplo n.º 2
0
    /// <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);
    }
        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));
                }
            }
        }
        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");
        }
Exemplo n.º 5
0
 private void Awake()
 {
     CheckForErrorOnCall(MicStream.MicInitializeCustomRate((int)StreamType, AudioSettings.outputSampleRate));
  }