videokit-ai / videokit

Low-code, cross-platform media SDK for Unity Engine. Register at https://videokit.ai
https://videokit.ai
Apache License 2.0
107 stars 14 forks source link

VideoKitAudioManager OnAudioBuffer dosen't work, throws exception #69

Closed marvpaul closed 1 year ago

marvpaul commented 1 year ago

I tried to use the OnAudioBuffer feature of the VideoKitAudioManager. I assigned a device to the script and called StartRunning

GameObject.Find("Recorder").GetComponent<VideoKitAudioManager>().device = audioDevice;
await GameObject.Find("Recorder").GetComponent<VideoKitAudioManager>().StartRunning();

I configured this empty method to be the callback:

Screenshot 2023-11-01 at 17 32 30 Screenshot 2023-11-01 at 17 32 48

When starting, I get a lot of exceptions caused by VideoKit:

UnityException: get_isPlaying can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
UnityEngine.Events.PersistentCall.GetRuntimeCall (UnityEngine.Events.UnityEventBase theEvent) (at /Users/bokken/buildslave/unity/build/Runtime/Export/UnityEvent/UnityEvent.cs:451)
UnityEngine.Events.PersistentCallGroup.Initialize (UnityEngine.Events.InvokableCallList invokableList, UnityEngine.Events.UnityEventBase unityEventBase) (at /Users/bokken/buildslave/unity/build/Runtime/Export/UnityEvent/UnityEvent.cs:656)
UnityEngine.Events.UnityEventBase.RebuildPersistentCallsIfNeeded () (at /Users/bokken/buildslave/unity/build/Runtime/Export/UnityEvent/UnityEvent.cs:837)
UnityEngine.Events.UnityEventBase.PrepareInvoke () (at /Users/bokken/buildslave/unity/build/Runtime/Export/UnityEvent/UnityEvent.cs:880)
UnityEngine.Events.UnityEvent`1[T0].Invoke (T0 arg0) (at /Users/bokken/buildslave/unity/build/Runtime/Export/UnityEvent/UnityEvent/UnityEvent_1.cs:53)
VideoKit.VideoKitAudioManager.OnSampleBuffer (VideoKit.Devices.AudioBuffer audioBuffer) (at Library/PackageCache/ai.natml.videokit@0.0.15/Runtime/VideoKitAudioManager.cs:187)
VideoKit.Devices.AudioDevice+<>c__DisplayClass11_0.<StartRunning>b__0 (System.IntPtr sampleBuffer) (at Library/PackageCache/ai.natml.videokit@0.0.15/Runtime/Devices/AudioDevice.cs:63)
VideoKit.Devices.AudioDevice.OnAudioBuffer (System.IntPtr context, System.IntPtr sampleBuffer) (at Library/PackageCache/ai.natml.videokit@0.0.15/Runtime/Devices/AudioDevice.cs:185)
UnityEngine.Debug:LogException(Exception)
VideoKit.Devices.AudioDevice:OnAudioBuffer(IntPtr, IntPtr) (at Library/PackageCache/ai.natml.videokit@0.0.15/Runtime/Devices/AudioDevice.cs:188)
marvpaul commented 1 year ago

Bump I came across this issue in one of my other projects when trying to record from Microphone device using VideoKitRecorder. Would be great to see it fixed soon so I can add Videokit's VideoKitRecorder to my project instead of using my own recording logic.

marvpaul commented 1 year ago

Working now with 0.0.16, thank you!