我想通过扬声器实时播放从Oculus Go的麦克风获得的声音,但无法做到。我已经试过了这段代码,但是在带耳机麦克风的Editor中不能与Oculus Go一起使用,还是我犯了一些错误?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;
public class MicrophoneAudio : MonoBehaviour
{
void Start()
{
AudioSource micAudio = GetComponent<AudioSource>();
micAudio.clip = Microphone.Start(Microphone.devices[0], true, 10, 44100);
micAudio.loop = true;
while(!(Microphone.GetPosition(null) > 0)) { }
micAudio.Play();
}
}
这是设备限制吗?我已经观察了很多,但是没有运气,发现只启动麦克风而没有实时播放。希望有人能帮助我。:(
答案 0 :(得分:0)
此脚本应在Oculus GO上运行,该脚本已在我的Oculus GO音频和视频实时流演示中使用。
AudioSource AudioMic;
void Start() {
StartCoroutine(CaptureMic());
}
IEnumerator CaptureMic()
{
if (AudioMic == null) AudioMic = GetComponent<AudioSource>();
AudioMic.clip = Microphone.Start(null, true, 1, OutputSampleRate);
AudioMic.loop = true;
while (!(Microphone.GetPosition(null) > 0)) { }
Debug.Log("Start Mic(pos): " + Microphone.GetPosition(null));
AudioMic.Play();
//capture for live streaming
//while (!stop)
//{
// AddMicData();
// yield return null;
//}
//capture for live streaming
yield return null;
}