Example code using a different audio source?

Options
Hi! I'm trying to stream audio from an audio listener in unity, rather than MIC.
Actually, I'd rather just stream one mixer track, but I can't figure out how to get that audio yet...

I can get the audio from the audio listener as a float array using the function OnAudioFilterRead().
However, I can't seem to get it working with Photon Voice.

Is there any example code available? I can't find any.
Thanks!

Comments

  • vadim
    Options
    HI,

    First, make sure that your OnAudioFilterRead works. Simply log some floats from incoming array.

    To change microphone to custom audio source, create class reading your audio source and implementing ExitGames.Client.Photon.Voice.IAudioReader interface. Look at AudioClipWrapper which streams audio clip assigned in editor.
    Set PhotonVoiceRecorder's Source to Factory in editor and tell PhotonVoice to use factory creating instance of your class somewhere during app initialization (before PhotonVoiceRecorder created):
    PhotonVoiceNetwork.AudioSourceFactory = (rec) => new MyAudioSource();
    As long as client is connected to a voice room and PhotonVoiceRecorder is transmitting, Read(float[] buffer) method will be called on MyAudioSource instance. Calls frequency and buffer size are adjusted to meet sampling rate returned by SamplingRate property of MyAudioSource.
  • shadowsora
    edited April 2018
    Options
    vadim said:

    Set PhotonVoiceRecorder's Source to Factory in editor and tell PhotonVoice to use factory creating instance of your class somewhere during app initialization (before PhotonVoiceRecorder created):
    PhotonVoiceNetwork.AudioSourceFactory = (rec) => new MyAudioSource();

    Confused about this... you say before the PhotonVoiceRecorder is created... but isn't "rec" your recorder? Doesn't it have to be created already to use this line of code?

    EDIT: I just enable the component after this and it *seems* to be working (getData() is being called).
    Thanks for all your help!