0

I would like to play the sound get from Oculus Go's microphone through speaker in real-time, but could not made it. I have tried this code, it works well in Editor with headphone's microphone not with Oculus Go, or I have made some mistake?

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();
    }
}

Or this the device limitation? I already observed a lot but have no luck and found only start the microphone with no real time playback one. Hope anyone could help me.:(

1 Answers1

0

This script should work on Oculus GO, which is used in my audio + video live streaming demo with 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;
}