Unity麦克风开始滞后录音

时间:2018-09-26 18:51:14

标签: unity3d microphone

我正在尝试通过此代码从麦克风录制一个样本

private bool recording = false;

void Start () {
    Button btnREC = recordButton.GetComponent<Button>();
    btnREC.onClick.AddListener(RecordToggle);

    Button btnPlay = playButton.GetComponent<Button>();
    btnPlay.onClick.AddListener(PlayAudioSource);
}

public void RecordToggle(){
    if (recording) {
        StopRecording ();
    } else {
        StartCoroutine("StartRecording");
    }
}

IEnumerator StartRecording(){
    source.clip = Microphone.Start(null, true, 10, 44100);
    while(!(Microphone.GetPosition(null) > 0)){
        yield return true;
    }
    recording = true;
    recIndicator.SetActive (true);
    StopCoroutine("StartRecording");
}

在Unity编辑器中,一切都很好,但是在构建中,我在单击按钮和录制开始之间有一个滞后(滞后也显示了我的recIndicator)。单击按钮后如何解决此问题并立即开始录制?

0 个答案:

没有答案