首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >统一Microphone.Start()滞后,如何摆脱它?

统一Microphone.Start()滞后,如何摆脱它?
EN

Stack Overflow用户
提问于 2021-11-18 15:42:40
回答 2查看 598关注 0票数 0

使用统一2020.3和XR插件(目前只有oculus,但我希望将移动到openxr ),并试图启动麦克风时,次级按钮被按下。它可以工作,但启动麦克风会造成滞后。Coroutine并没有帮助我,我试着用线程来阻止延迟,但是却不能用听筒来做任何事情。多年来,这个问题已被问了几次,但至今仍未得到答复。下面是代码:

代码语言:javascript
复制
 void Update()
{
    foreach(var d in devices){
        if (d.TryGetFeatureValue(CommonUsages.secondaryButton, out isPressed)){
            if (isPressed && !wasTalking)
                { 
                    wasTalking = true;
                    asource.PlayOneShot(walkietalkie);
                    //start_recording = new Thread(startRecording);
                    //start_recording.Start();
                    startRecording();  
                }
            else if (wasTalking && !isPressed){
                finishRecording();
                wasTalking = false;
            }
        }

private void startRecording(){
    
    recording = Microphone.Start(null, false, 30, freq);
    startRecordingTime = Time.time;
    yield return null;
}

编辑:我已经删除了无用的协同线。为什么回答我的问题?

EN

回答 2

Stack Overflow用户

发布于 2021-11-19 20:46:55

我认为您可以缓解口吃的主要方法是将此工作转移到另一个线程上,这是以团结而闻名的。

解决这一问题的方法可能是使用或调整另一种录制音频的方法,如NAudio

票数 0
EN

Stack Overflow用户

发布于 2022-03-06 12:31:35

使用协同线。

代码语言:javascript
复制
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Threading;

public class TestMic : MonoBehaviour
{
    [SerializeField] AudioSource self;
    public int samplerate = 44100;
    public int time = 10;
    // Start is called before the first frame update
    void Start()
    {
        //Debug.Log(Microphone.devices);
        StartCoroutine("test");
    }
    IEnumerator test()
    {
        self.clip = Microphone.Start(null, true, time, samplerate);
        self.loop = true;
        self.Play();
        yield return null;
    }
    // Update is called once per frame
    void Update()
    {
        
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70022751

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档