Unity-Technologies / Unity-Technologies/com.unity.webrtc

[BUG]: How get spectrum data from receiving audio stream track?

Open
#1,033 0 comments 0 reactions 1 assignee View on GitHub

@karasusan is already working on this.

Since May 21, 2024.

bug
Dominant language
Assembly
Stars
852
Forks
238
PR merge metrics
No merged PRs in 30d

Description

Package version

3.0.0-pre.7

Environment
* OS: Windows 11
* Unity version: 2023.2
Steps To Reproduce
void ReceivingAudio() {
  var receivedAudioSource = GetComponent<AudioSource>();
  var receiveStream = new MediaStream();
  receiveStream.OnAddTrack = e => {
    if(e.Track is AudioStreamTrack track)
    {
        receivedAudioSource.SetTrack(track);
        receivedAudioSource.loop = true;
        receivedAudioSource.Play();        
    }
  }
}

void FixedUpdate() {
  if(receivedAudioSource != null) {
    float[] data = new float[256]
    receivedAudioSource.GetSpectrumData(data, 0, FFTWindow.Rectangular)
    // do something
  }
}

After sending peer has connected to receiving peer data array is empty, cause receivedAudioSource.clip is null, but receiver has sound from sender

Current Behavior

I have implemented audio streaming channel on LAN with own signalling server. Everything works good.
After receiving the audio stream track on remote PC I need get a output data or spectrum data from the Audio Source. But the receiving Audio Source doesn't contains a audio clip and i get the empty float array from the necessary methods (AudioSource.GetSpectrumData() or AudioSource.GetOutPutData())
I tried the Audio Sample. The Same thing there.

Expected Behavior

Maybe there are other ways to get a data from audio clip?

Anything else?

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.