UnityPlugin-AVProMovieCapture icon indicating copy to clipboard operation
UnityPlugin-AVProMovieCapture copied to clipboard

Support for multiple audio inputs

Open kahnivore opened this issue 4 years ago • 27 comments

Quite a lot of users have asked for support to record from Unity and microphone simultaneously

kahnivore avatar Apr 16 '21 14:04 kahnivore

Can we get support audio files/assets as well?

v2k avatar Apr 19 '21 17:04 v2k

I also need to be able to record Unity audio and the microphone simultaneously. Currently looking into combining the two sources manually.

WikkidEdd avatar Nov 09 '21 08:11 WikkidEdd

Hi @WikkidEdd,

Did you have some news about it ? I would like to do the same: recording video (from Unity audio) and the microphone simultaneously ..

Thanks in advance, Eric

Yup, I got it working.

The basic idea is to use the OnAudioFilterRead callback from multiple sources and then forward them on to custom UnityAudioCapture and combine the two.

I've stuck the scripts I use in a gist. https://gist.github.com/WikkidEdd/35fea92260b95135d6837188006919dc

I put one forwarder on the main AudioListener and one on the microphone playback source.

Hopefully that is helpful

WikkidEdd avatar Dec 23 '21 00:12 WikkidEdd

Oh ! Looks great ! I need it for iOS, I will check it !

Thanks a lot !

I tried it, but I have a huge larsen effect (and at best an echo effect): loop between AudioListener and the microphone AudioSource ..

You need to set the mute behavior of the microphone OnAudioFilterReadForwarder to MuteAfter. This basically lets you capture the mic audio, but prevents it from being used by anything else aka the AudioListener.

WikkidEdd avatar Jan 03 '22 08:01 WikkidEdd

Thank you for the MuteAfter property, indeed, the larsen effect is fixed !

But trying to record an audio Video (Unity audio mode) and the microphone seems to not work .. The final audio is still choppy. I might be doing something wrong but I dont know what ..

You may have a complete Unity sample which shows this kind of record ?

Hello, Is this feature in development @kahnivore or only planned ?

tomkrikorian avatar Jan 19 '22 16:01 tomkrikorian

Hello to All

can you confim if this script does work at 100% into unity 2020.3 ?

im really annoyed . i have tried many times . but no succcess . and i must present my app very soon but now , I am completely blocked with this possibility to capture multiple source issue .

EricBeetsofficiel seems to have a problem too and nobody answer him .

Im reallly desesperate . I must present my app and i cannot due to mic feedback . its become to be urgent . have you got a working sample/example? im on 2020.3 .Building app for windows .

Help please ! I will be really grateful from your help. i m ready to pay for any help. Thank you very much

GiO9876543210 avatar May 06 '22 16:05 GiO9876543210

hello at All It s me again !;)

I have tried again your scripts ( Support formultiple audio inputs revision script ) .

here i described my architecture . Could you tell me if i do mistakes .

I have : the camera :

  • with audiolistener
  • capture Audio( from Audiolistener listener )
  • On audio Filter REad forwarder ( with no mute behaviour )

the mic Object :

  • with my Microcphone input script
  • On audio filter Read forwarder component
  • the mute behaviour setupped with "After" muting .

and capture object

  • with the AVcapture from camera . audiosource is setupped on Unity
  • CApture Audio from Multiple SOurces component and i had the both on audio filter forwarder elements. ( from Mic and camera )

Of course i deactivate the line into the capturebase.cs as described

Great I succeed to capture video from camera with all sounds ( audio listener and mic ) BUT there is the terrific feedabck from mic .

Unfortunnally and it is my huge problem : when i applied the "after" muting into Audio filter read from Mic object . the mic is not captured ( i have only the sound fromlistener )

i m completely lost and i become to believe this "on Audio Filter read forwarder " is simply buggy . ? and i lose many time on it

please could someone tell me if i do big mistake ?

its very very important for me .

Thannk you very much for any help

GiO

GiO9876543210 avatar May 10 '22 09:05 GiO9876543210

Did you do this step mentioned in the gist?

Remove this line in CaptureBase.cs

removeComponent = !(_unityAudioCapture is CaptureAudioFromAudioListener);

WikkidEdd avatar May 10 '22 09:05 WikkidEdd

hello wikkiEdd thank you for your reply

Yes : i add the // before "removeComponent = !(_unityAudioCapture is CaptureAudioFromAudioListener);" to bring it into comment

remove component

GiO9876543210 avatar May 10 '22 09:05 GiO9876543210

I'll double check that my setup matches you and get back you.

What platform are you running? Can you confirm in editor that those components are correctly on the objects?

WikkidEdd avatar May 10 '22 09:05 WikkidEdd

i run on windows .

I know im not an Ace development but i have succeed to do evrey time i want . It is the first time i am so blocked . :)

i try to described as better i could my architecture :

I have : the camera :

  • with audiolistener
  • with capture Audio( from Audiolistener listener ) component
  • with your On audio Filter REad forwarder component ( with no mute behaviour selected )

the mic Object :

  • with my Microcphone input script
  • with the "On audio filter Read forwarder" component
  • the mute behaviour setupped with the "After" muting .

and my capture object

  • with the AVcapture from camera . audiosource is setupped on Unity (of course i have selected the "capture Audio" from the camera
  • with CApture Audio from Multiple SOurces component and i have added the both "on audio filter forwarder" elements. ( from Mic and camera object )

Of course i deactivate the line into the capturebase.cs as described in you r gist

I used your revision script .

thank you for your comfirmation . !

i bought AVpro capture on november 2021 . i have checked if there is new major upgrade but it seems ok

GiO9876543210 avatar May 10 '22 09:05 GiO9876543210

Ah, one thing you should check is that you have the CaptureAudioFromMultipleSources component hooked up in the avpro script underneath where you select the audio source to be "Unity"

It looks like if you don't have that set to something, then it will automatically add a CaptureAudioFromAudioListener script and use that instead.

WikkidEdd avatar May 10 '22 11:05 WikkidEdd

ooh my god . that is the solution. simply that .

thats work pretty nice now .!!

ooh many many thanks MrWikkiEdd .! for this great help and your components !

GiO9876543210 avatar May 10 '22 12:05 GiO9876543210

Great. Glad it worked, sorry for missing that from the instructions.

CC: @EricBeetsOfficial-Opuscope, this should fix your problem too

WikkidEdd avatar May 10 '22 13:05 WikkidEdd

That will help many buddy like me to keep their hair , yes :)

have the best Mr WikkiEdd !

GiO9876543210 avatar May 10 '22 14:05 GiO9876543210

Great. Glad it worked, sorry for missing that from the instructions.

CC: @EricBeetsOfficial-Opuscope, this should fix your problem too

It's not work for ios and aos unlike windows app.😢 Mic sound is recorded so~~~ small.

Kyoungsu-VIRNECT avatar Sep 30 '22 08:09 Kyoungsu-VIRNECT

Using the CaptureAudioFromMultipleSources component it drops to 3 frames. How should I solve it?

yren922 avatar Jan 31 '23 07:01 yren922

when it comes up?

choigawoon avatar Feb 15 '23 05:02 choigawoon

Yup, I got it working.

The basic idea is to use the OnAudioFilterRead callback from multiple sources and then forward them on to custom UnityAudioCapture and combine the two.

I've stuck the scripts I use in a gist. https://gist.github.com/WikkidEdd/35fea92260b95135d6837188006919dc

I put one forwarder on the main AudioListener and one on the microphone playback source.

Hopefully that is helpful

is there a chance this could work on android?

RErwandi avatar Mar 08 '23 10:03 RErwandi

Using the CaptureAudioFromMultipleSources component it drops to 3 frames. How should I solve it?

Hi,

Have you find out the reason?

jiaming233 avatar Jun 08 '23 07:06 jiaming233

Yup, tôi đã làm cho nó hoạt động.

Ý tưởng cơ bản là sử dụng lệnh gọi lại OnAudioFilterRead từ nhiều nguồn, sau đó chuyển chúng tới tùy chỉnh UnityAudioCapture và kết hợp cả hai.

Tôi đã truy vấn các tập lệnh mà tôi sử dụng trong một ý chính. https://Gist.github.com/WikkidEdd/35fea92260b95135d6837188006919dc

Tôi đặt một bộ chuyển tiếp trên AudioListener chính và một trên nguồn phát lại trống.

Hy vọng rằng đó là hữu ích

Annotation 2023-08-01 180618

Annotation 2023-08-01 181132

Hello @WikkidEdd, I import your script into my project And I get the errors Can you help me?

nguyenhuutai5798 avatar Aug 01 '23 11:08 nguyenhuutai5798

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Dec 15 '23 06:12 stale[bot]

Hello, I'm having trouble with the microphone playback part. My current script :

using UnityEngine; using System.Collections;

public class MicrophonePlayback : MonoBehaviour { private AudioSource audioSource;

void Start()
{
    StartCoroutine(CaptureMic());
}

IEnumerator CaptureMic()
{
    if (audioSource == null) audioSource = GetComponent<AudioSource>();
    audioSource.clip = Microphone.Start(null, true, 1, AudioSettings.outputSampleRate);
    audioSource.loop = true;
    while (!(Microphone.GetPosition(null) > 0)) { }
    Debug.Log("Start Mic(pos): " + Microphone.GetPosition(null));
    audioSource.Play();

    yield return null;
}

}

My script is working fine in the editor, on mobile devices, and on the Oculus Quest 3, but on the Quest 2, the audio isn’t clear and there’s an echo. I've set the MuteBehaviour to "After" for the microphone object and I confirm I have done other things mentioned here, I think the issue is related to my playback script. Any ideas on what might be causing this? Link to the original script : https://stackoverflow.com/questions/58951537/oculus-go-unity-microphone-real-time-playback

Edit: I would like to mention that this issue only happens with the microphone audio, the other audio from the listener is completely fine.

laksh308 avatar Aug 28 '24 15:08 laksh308