示例#1
0
 /// <summary>
 /// 停止录音
 /// </summary>
 public void StopRecord()
 {
     totalRecordedTime = (float)(DateTime.Now - lastRecordStartTime).TotalSeconds;
     if (Microphone.IsRecording(null))
     {
         Microphone.End(null);
     }
     SetLastRecordByteArray();
 }
 private void Update()
 {
     if (!Microphone.IsRecording(selectedDevice))
     {
         source.Stop();
         source.clip = Microphone.Start(selectedDevice, false, 10, maxSamplingFreq);
         source.Play();
     }
 }
 void StopRecord()
 {
     if (!Microphone.IsRecording(null))
     {
         return;
     }
     Microphone.End(null);
     audio.Stop();
 }
示例#4
0
 void OnGUI()
 {
     MicDeviceGUI((Screen.width / 2) - 150, (Screen.height / 2) - 75, 300, 100, 10, -300);
     if (Microphone.IsRecording(selectedDevice))
     {
         ramFlushTimer += Time.fixedDeltaTime;
         RamFlush();
     }
 }
示例#5
0
 private void RamFlush()
 {
     if (ramFlushTimer >= ramFlushSpeed && Microphone.IsRecording(selectedDevice))
     {
         StopMicrophone();
         StartMicrophone();
         ramFlushTimer = 0;
     }
 }
示例#6
0
    private IEnumerator RecordingHandler()
    {
        Log.Debug("ExampleStreaming.RecordingHandler()", "devices: {0}", Microphone.devices);
        _recording = Microphone.Start(_microphoneID, true, _recordingBufferSize, _recordingHZ);
        yield return(null);      // let _recordingRoutine get set..

        if (_recording == null)
        {
            StopRecording();
            yield break;
        }

        bool bFirstBlock = true;
        int  midPoint    = _recording.samples / 2;

        float[] samples = null;

        while (_recordingRoutine != 0 && _recording != null)
        {
            int writePos = Microphone.GetPosition(_microphoneID);
            if (writePos > _recording.samples || !Microphone.IsRecording(_microphoneID))
            {
                Log.Error("ExampleStreaming.RecordingHandler()", "Microphone disconnected.");

                StopRecording();
                yield break;
            }

            if ((bFirstBlock && writePos >= midPoint) ||
                (!bFirstBlock && writePos < midPoint))
            {
                // front block is recorded, make a RecordClip and pass it onto our callback.
                samples = new float[midPoint];
                _recording.GetData(samples, bFirstBlock ? 0 : midPoint);

                AudioData record = new AudioData();
                record.MaxLevel = Mathf.Max(Mathf.Abs(Mathf.Min(samples)), Mathf.Max(samples));
                record.Clip     = AudioClip.Create("Recording", midPoint, _recording.channels, _recordingHZ, false);
                record.Clip.SetData(samples, 0);

                _service.OnListen(record);

                bFirstBlock = !bFirstBlock;
            }
            else
            {
                // calculate the number of samples remaining until we ready for a block of audio,
                // and wait that amount of time it will take to record.
                int   remaining     = bFirstBlock ? (midPoint - writePos) : (_recording.samples - writePos);
                float timeRemaining = (float)remaining / (float)_recordingHZ;

                yield return(new WaitForSeconds(timeRemaining));
            }
        }

        yield break;
    }
 /// <summary>
 /// 结束录音
 /// </summary>
 public void StopRecord()
 {
     if (Microphone.IsRecording(null))
     {
         Microphone.End(null);
         audioSource.clip = clip;
         audioSource.Play();
     }
 }
示例#8
0
 /** Used in Button "On Click" function */
 public void RecordSound()
 {
     //Check if default microphone is recording
     if (Microphone.IsRecording(""))
     {
         return;
     }
     aud.clip = Microphone.Start("", false, recLen, maxFreq);
 }
示例#9
0
 void Update()
 {
     if (!Microphone.IsRecording(null) && isRecording)
     {
         AudioLib.Save("test.wav", audioClip);
         GetComponentInChildren <Text>().text = "Start recording";
         isRecording = false;
     }
 }
示例#10
0
 public void disable()
 {
     active = false;
     source.Stop();
     source.clip = null;
     Debug.Log("Disabled");
     Microphone.End(Microphone.devices[0]);
     Debug.Log(Microphone.IsRecording(Microphone.devices[0]));
 }
 void Update()
 {
     // 3.a: Add condition to check if dictationRecognizer.Status is Running
     if (hasRecordingStarted && !Microphone.IsRecording(deviceName) && dictationRecognizer.Status == SpeechSystemStatus.Running)
     {
         // Reset the flag now that we're cleaning up the UI.
         hasRecordingStarted = false;
     }
 }
示例#12
0
 private void LateUpdate()
 {
     if (IsListening && !Microphone.IsRecording(DeviceName) && dictationRecognizer.Status == SpeechSystemStatus.Running)
     {
         // If the microphone stops as a result of timing out, make sure to manually stop the dictation recognizer.
         StartCoroutine(StopRecording());
         IsRecording = false;
     }
 }
示例#13
0
    private void OnClickPlayBtn()
    {
        if ((isHaveMicrophone == false) || (Microphone.IsRecording(devices[0]) || aud.clip == null))
        {
            return;
        }

        //播放录音
        aud.Play();
    }
示例#14
0
    private void OnClickStartBtn()
    {
        if ((isHaveMicrophone == false) || (Microphone.IsRecording(devices[0])))
        {
            return;
        }

        //开始录音
        aud.clip = Microphone.Start(devices[0], true, 20, 44100);
    }
示例#15
0
        /// <summary>
        /// タップのホールドをキャンセルしたときの処理
        /// </summary>
        /// <param name="eventData">ホールドのイベントデータ</param>
        public void OnHoldCanceled(HoldEventData eventData)
        {
            view.OnHoldCanceled();

            if (Microphone.IsRecording(null))
            {
                //録音中であれば録音停止
                Microphone.End(null);
            }
        }
    void Start()
    {
        Microphone.IsRecording(null);
        var j = Newtonsoft.Json.JsonConvert.DeserializeObject("{\"err\":\"0\"}") as JObject;

        StartCoroutine(OnRequestCamera());

        new Thread(new ThreadStart(() => { })).Start();
        new System.Threading.Tasks.Task(() => { }).Start();
    }
示例#17
0
        /// <summary>
        /// ホールドのキャンセル
        /// </summary>
        /// <param name="eventData"></param>
        public void OnHoldCanceled(HoldEventData eventData)
        {
            // 録音の中断
            _recordingEventEventSubject.OnNext(RecordingEvent.Cancel);

            if (Microphone.IsRecording(null))
            {
                Microphone.End(null);
            }
        }
示例#18
0
 private void StopRecord()
 {
     if (!Microphone.IsRecording(null))
     {
         return;
     }
     Microphone.End(null);
     myAudio.Stop();
     Log("");
 }
    void Update()
    {
        // 添加条件来检查是否会识别。运行状态
        if (hasRecordingStarted && !Microphone.IsRecording(deviceName) && dictationRecognizer.Status == SpeechSystemStatus.Running)
        {
            hasRecordingStarted = false;

            SendMessage("RecordStop");
        }
    }
示例#20
0
 /// <summary>
 /// Tells the default device to start recording if it is not already.
 /// </summary>
 public void StartRecording()
 {
     if (!Microphone.IsRecording(null))
     {
         m_ForcedStopRecording = false;
         m_RecordingStartTime  = Time.time;
         m_RecordedAudio       = Microphone.Start(null, false, m_MaxRecordingLengthInSeconds, m_RecordingFrequency);
         StartCoroutine(WaitForRecordingTimeout());
     }
 }
 public void StartChat()
 {
     if (Microphone.IsRecording(deviceName))
     {
         return;
     }
     Debug.Log("开始录制");
     recordClip = Microphone.Start(deviceName, false, MAX_LENGTH, SAMPLES_PER_SEC);
     curLength  = 0f;
 }
    public void StopCaptureVoice()
    {
        if (Microphone.IsRecording(null) == false)
        {
            return;
        }

        Microphone.End(null);
        m_AudioSource.Stop();
    }
示例#23
0
 public override void Record()
 {
     base.Record();
     if (!Recording && Microphone.IsRecording(null))
     {
         int lastSample = Microphone.GetPosition(null);
         Microphone.End(null); //Stop the audio recording
         AudioSource.clip = TrimClip(_clip, lastSample);
     }
 }
示例#24
0
 /// <summary>
 /// 停止录音
 /// </summary>
 public void StopRecordAudio()
 {
     ShowInfoLog("结束录音.....");
     if (!Microphone.IsRecording(null))
     {
         return;
     }
     Microphone.End(null);
     CurAudioSource.Stop();
 }
示例#25
0
        public void StopMicrophone()
        {
#if !REK_MICROPHONE_DISABLED
            if (Microphone.IsRecording(DeviceName))
            {
                Microphone.End(DeviceName);
                audioSource.Stop();
            }
#endif
        }
示例#26
0
    private void StartRecording()
    {
        if (micConnected && !Microphone.IsRecording(null))
        {
            clip        = Microphone.Start(null, true, 2, maxFreq);
            source.clip = clip;
        }

        Invoke("StopRecording", 2f);
    }
示例#27
0
    void Break()
    {
        if (Microphone.IsRecording(null))
        {
            End();
        }

        _started = true;
        newClip  = Microphone.Start(null, false, 100, 44100);
    }
示例#28
0
        public bool IsRecording()
        {
            if (selectedDevice != null)
            {
                return(Microphone.IsRecording(selectedDevice));
            }

            Debug.LogError("<b>[SoundStone]</b> No Audio Source Found!");
            return(false);
        }
 public void StartRecordHello()
 {
     if (!Microphone.IsRecording(null))
     {
         recoHello = Microphone.Start(null, false, 15, 44100);
         isRecord  = true;
         index     = 4;
     }
     GameObject.Find("Canvas").GetComponent <Speaker>().AddMessHello(recoHello);
 }
示例#30
0
 public void Play()
 {
     if (!Microphone.IsRecording(""))
     {
         if (audioSource.clip != null)
         {
             audioSource.Play();
         }
     }
 }