使用统一2020.3和XR插件(目前只有oculus,但我希望将移动到openxr ),并试图启动麦克风时,次级按钮被按下。它可以工作,但启动麦克风会造成滞后。Coroutine并没有帮助我,我试着用线程来阻止延迟,但是却不能用听筒来做任何事情。多年来,这个问题已被问了几次,但至今仍未得到答复。下面是代码:
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;
}编辑:我已经删除了无用的协同线。为什么回答我的问题?
发布于 2021-11-19 20:46:55
我认为您可以缓解口吃的主要方法是将此工作转移到另一个线程上,这是以团结而闻名的。
解决这一问题的方法可能是使用或调整另一种录制音频的方法,如NAudio。
发布于 2022-03-06 12:31:35
使用协同线。
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()
{
}
}https://stackoverflow.com/questions/70022751
复制相似问题