Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug WasapiLoopbackCapture #1176

Open
zdypll opened this issue Aug 5, 2024 · 5 comments
Open

Bug WasapiLoopbackCapture #1176

zdypll opened this issue Aug 5, 2024 · 5 comments

Comments

@zdypll
Copy link

zdypll commented Aug 5, 2024

Bug1:
System.TypeLoadException: Could not resolve type with token 0100001e from typeref (expected class 'System.OperatingSystem' in assembly 'System.Runtime.Extensions, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
at NAudio.Wave.WasapiLoopbackCapture.GetDefaultLoopbackCaptureDevice () [0x00000] in <1b3f595e963c4b8ab8ee799323fffe28>:0
at NAudio.Wave.WasapiLoopbackCapture..ctor () [0x00000] in <1b3f595e963c4b8ab8ee799323fffe28>:0
at AudioCapture.Start () [0x00002] in D:\Live2D Editor\Assets\Script\AudioCapture.cs:32
UnityEngine.Debug:Log (object)
AudioCapture:Start () (at Assets/Script/AudioCapture.cs:48)

c# Script

//NAudio.dll Save => Plugins

using NAudio.Wave;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEngine;

public class AudioCapture : MonoBehaviour
{
public int bytesLength;
public byte[] bytes;

//private void Microphone()
//{
//    WaveInEvent waveIn = new WaveInEvent();
//    waveIn.DataAvailable += (sender, e) =>
//    {
//        e.Buffer.ToList().CopyTo(0, bytes, 0, bytes.Length);
//    };
//    waveIn.WaveFormat = new WaveFormat(44100, 16, 1);
//    waveIn.StartRecording();
//}

private void Start()
{
    try
    {
        WasapiLoopbackCapture cap = new WasapiLoopbackCapture();
        cap.DataAvailable += (sender, e) =>
        {
            e.Buffer.ToList().CopyTo(0, bytes, 0, bytes.Length);

            //float[] listByte = Enumerable
            //.Range(0, e.BytesRecorded / 4)
            //.Select(i => BitConverter.ToSingle(e.Buffer))
            //.ToArray();
        };

        cap.StartRecording();

    }
    catch (Exception error)
    {
        Debug.Log(error);
    }
}

}

Bug2:WasapiLoopbackCapture cap = new WasapiLoopbackCapture();//Unity Debug Show dll in code is null error

1.An error occurred while installing NAudio on Nuget in Visual Studio, and the reference name could not be found. After exploring for a long time, the current solution is to copy the DLL file to the plugins special folder of the Unity project.

2.try-catch, code no run, But unity debug show Null error. DLL internal error, unable to catch exception

3.Permission issue, causing Unity to be unable to use NAudio and unable to use it. The Unity Hub and Unity Engine have been set to administrator privileges, but they are invalid

@zdypll
Copy link
Author

zdypll commented Aug 5, 2024

NAudio.Core 2.2.1
NAudio.Wasapi 2.2.1

@zdypll
Copy link
Author

zdypll commented Aug 5, 2024

I have been trying for a long time and have been researching NAudio for 3 days now, but I feel disappointed

@zdypll
Copy link
Author

zdypll commented Aug 5, 2024

By the way, it is necessary to use a framework, even if Unity officially abandons this technology, and it must be used in lower versions of Unity 2022. If NAudio gives up, it means giving up Unity creativity

@zdypll
Copy link
Author

zdypll commented Aug 6, 2024

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

@zdypll
Copy link
Author

zdypll commented Sep 19, 2024

COMException
System.Runtime.InteropServices.Marshal.ThrowExceptionForHR
cap.StartRecording();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant