unity3d – wasapi loopback to unity 2020 audio source or webrtc

Can anyone help me? I am sending live audio from WASAPI into Unity, and I want it to play back as a audio clip in the scene, or send it directly to WebRTC.

There are several issues. Mainly, I tried using wavutility.cs to convert the file to a audio clip, but it is unrecognized PCM data.

The bytes are incoming in to my main mono and are coming into my coroutine.

I’ll post more code if i can get some help from anyone who knows what’s going on with audio coding.

I can’t find anyone who knows about this stuff, so I’m reaching out to stack for help now.

here:

    IEnumerator Run4() {
    WavUtility w = new WavUtility();

    WasapiLoopbackCapture _loopbackCapture = _realtimeAudio._loopbackCapture;

    SoundInSource _soundInSource = new SoundInSource(_loopbackCapture);
    _singleBlockNotificationStream = new SingleBlockNotificationStream(_soundInSource.ToSampleSource());
    _realtimeSource = _singleBlockNotificationStream.ToWaveSource();

    Byte[] buffer = new byte[_realtimeSource.WaveFormat.BytesPerSecond / 2];
 
    _soundInSource.DataAvailable += (s, ea) =>
    {
        while (_realtimeSource.Read(buffer, 0, buffer.Length) > 0)
        {
            print(buffer.Length);

            print(_realtimeSource.WaveFormat);

            Playclip2( WavUtility.ToAudioClip(buffer));

        }
    };
    yield return new WaitForEndOfFrame();
}

Read more here: Source link