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 Answer 1

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;
}
2
  • This works! Thank you so much. But there still a bit delay, do you have any suggestion to solve delay in playback? Nov 22, 2019 at 9:32
  • some tricks I found, but I haven't tested. Edit -> Project Settings -> Audio Set DSP Buffer Size to ‘Best Latency
    – user12138816
    Nov 22, 2019 at 10:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.