GithubHelp home page GithubHelp logo

corey-m / naudio.lame Goto Github PK

View Code? Open in Web Editor NEW
124.0 13.0 45.0 2.68 MB

Wrapper for libmp3lame.dll to add MP3 encoding support to NAudio.

License: MIT License

C# 100.00%
windows-native naudio mp3-encoding

naudio.lame's People

Contributors

brianavid avatar corey-m avatar developersthinksmartbox avatar meyfa avatar protogendelta avatar qwbarch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

naudio.lame's Issues

Usage in web application

Trying to get the library working from a .NET web application. I get a "unable to load dll libmp3lame.32.dll". I have checked and the file is in the bin folder.

Working fine in a console application, any hints?

Enhance LameConfig to support more VBR options

We would like to be able to control down sampling and also the minimum and maximum variable bitrate as well as set the algorithm quality

Lame command line options:
-a, -b, -B, -q, -F (when using a VBR option)

NAudio.Lame.dll dont copy to bin directory

Hello

I download NAudio.Lame 2.0.0 from NuGet

After compiling the project, the NAudio.Lame.pdb file is copied to the BIN / DEBUG directory instead of NAudio.Lame.dll

How can you fix this?

No .NET standard support

Is it possible to bump the framework version used? The NuGet package doesn't work with .NET Standard 2.0 libraries anymore since release 1.0.8

Signed dll

Hello,

I am attempting to include this functionality in a .net 4.7.2 website project.

Unfortunately I haven’t been able to execute the code, the project requiring signed dll’s.

I saw a closed issue here with someone else requesting signed dll:
#28

It was mentioned in that issue that NAudio was not signed, since that date it now is, as noted here:
naudio/NAudio#677

Would it be possible for you to create a signed version of this functionality please?

Unable to convert wav audio to mp3

Hi. I am looking for a way to convert a wav file into mp3 in MVC project. I used the method 'WaveToMP3' from the example code you've mentioned. It does create an mp3 file, But when I play it, there is just static noise. No original audio.

Am I doing something wrong here?

Please enable NAudio.Lame to be used with Linux

One of the advantages of Net Core applications is the ability to run on Linux and Mac in addition to Windows. I only see the shared libraries included for Windows, which makes me wonder if I can still use NAudio.Lame in a Linux container.

Running things in the cloud is a lot cheaper with Linux, and incorporating the conversion routines within a container would help my application be much more easily deployed.

If it is not possible to include the shared libraries for Mac and Linux, then at least have the library loader look for the libraries in the standard install place would be helpful. I.e. I can build an image with lame and its libraries installed, as long as NAudio.Lame simply uses the installed libraries.

Could not load file or assembly 'LameDLLWrap'

Hi
I use nadui.lame for convert wave to mp3 In .net core.
when I try to create instance of LameMP3FileWriter raise this error :

System.IO.FileLoadException: Could not load file or assembly 'LameDLLWrap, Version=1.0.6536.21689, Culture=neutral, PublicKeyToken=null'. Method does not exist. (Exception from HRESULT: 0x80131513) File name: 'LameDLLWrap, Version=1.0.6536.21689, Culture=neutral, PublicKeyToken=null' ---> System.MissingMethodException: Method not found: 'System.Reflection.Assembly System.Reflection.Assembly.Load(Byte[ ], Byte[], System.Security.SecurityContextSource)'. at NAudio.Lame.Loader.LoadLameWrapper(Object sender, ResolveEventArgs args) at System.AppDomain.InvokeResolveEvent(ResolveEventHandler eventHandler, RuntimeAssembly assembly, String name) at System.AppDomain.OnAssemblyResolveEvent(RuntimeAssembly assembly, String assemblyFullName) at NAudio.Lame.LameMP3FileWriter..ctor(Stream outStream, WaveFormat format, Int32 bitRate, ID3TagData id3) at NAudio.Lame.LameMP3FileWriter..ctor(String outFileName, WaveFormat format, Int32 bitRate, ID3TagData id3) at Mp3Convertor.Mp3Convertor.Convert(String path, String destPath) in D:\Source\SoundInfusion\Mp3Convertor\Class1.cs:line 11 at SoundInfusion.WebApi.Controllers.SampleController.Upload(IList1 model) in D:\Source\SoundInfusion\SoundInfusion.WebApi\Controllers\SampleController.cs:line 125
at lambda_method(Closure , Object )
at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult()
at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at System.Threading.Tasks.ValueTask1.get_Result() at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync() at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync() at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync() at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

Nuget Package structure prevents cont. integration builds and places dll in root proj folder

I'm working devops on a project which has several projects including the NAudion.Lame nuget package.

It is causing some problems that the Nuget package throws the libmp3lame.dlls into the root og the VS project using the Nuget package.

As one normally not wants to check in Nuget dependencies, then all dll's are ignored on commit.
All dll's are then restored into build output on build server using nuget package manager.

This is causing some problems with the ddl breaking this standard.

Is it possible to suggest that the libmp3lame.xx.dll are handles same way as the wrapper dll's, so they are restored into build output as part of standard Nuget restore on build.

Thanks a lot

Best regards, Peter Meldgaard, Denmark

Conversion producing sped up audio as of v1.1.1

We've been humming a long fine for quite a while but the upgrade to v1.1.1 has caused our WAV files, once converted to MP3, to be sped up in an unintelligible manner. Downgrading to v1.1.0 and we're good again.

Any idea what could be causing this? I imagine most people have been fine but we've tried a handful of different overloads of LameMP3FileWriter with different bitrate/presets and all are producing the same broken output.

64 bit NAudio.Lame.dll

I found that NAudio.Lame.dll is 32 bit.

image

I am getting Bad Image Exception, when creating windows installer.

image

can you update source code or change dll in nuget?
and I am also found that source code exist in github is not latest 1.0.4

Looks like 1.0.5 does not support .Net 4.0

It took me sometimes to get why LameMp3Writer was always returning :
Object reference not set to an instance of an object
from this code:

writer = new LameMP3FileWriter(
                        GetFileName(_path + insertArtistDir, _song, "mp3"),
                        waveIn.WaveFormat,
                        _bitrate,
                        tag);
                    return writer;

After downgrading to 1.0.4 everything was working fine. Just wanted to let you know. Maybe you added a note of this version on Nugget package but I did not see it. I'm not asking for a fix btw and also thanks for this great package.

edit: i'm up to date with NAudio : v1.8.2

NullReferenceException when setting the ID3Tag

For this line
var mp3Writer = new LameMP3FileWriter(outputPath, resultTrack.WaveFormat, 128, config.GetID3Tag());
I get a NullReferenceException. I saw that this happens only when I set the ID3Tag parameter.

From my debugging I found that the exception is thrown here: https://github.com/Corey-M/NAudio.Lame/blob/master/NAudio.Lame/LameMP3FileWriter.cs#L446 because data is null.
Why?
I saw that you have some tests around setting the ID3Tag but I don't understand how those pass.

Can I get some help?

ReportFunction usage

Hello,

Can the ReportFunction delegate be used to track progress of the conversion? Or is there another way to track progress?

Thanks

Unable to add reference to libmp3lame.dll

I cannot add the ibmp3lame.dll reference in my project. Neither the 32bit or 64bit.
Visual studio says make sure the file is accessible, and that it is a valid assembly or COM component.

Any ideas?

Dll not found exception

Hello all, while trying to convert wav to mp3, am getting the following exception
DllNotFoundException: winmm.dll
NAudio.Wave.WaveFileReader.ReadWaveHeader (System.IO.Stream stream, NAudio.Wave.WaveFormat& format, System.Int64& dataChunkPosition, System.Int32& dataChunkLength, System.Collections.Generic.List`1 chunks)
NAudio.Wave.WaveFileReader..ctor (System.IO.Stream inputStream)
NAudio.Wave.WaveFileReader..ctor (System.String waveFile)
(wrapper remoting-invoke-with-check) NAudio.Wave.WaveFileReader:.ctor (string)
ConvertWavToMp3.WaveToMP3 (System.String waveFileName, System.String mp3FileName, Int32 bitRate) (at Assets/ConvertWavToMp3.cs:54)

Can anyone help me to fix this?
When imported the package, I was getting an error related to the namespace using NAudio.Wave. Later I added the NAudio dll separately then the error resolved. But while trying to convert the wav, still stuck with above error

MP3 to Wave

Hello,
this is not an issue. just a question.
i have a situation to reduce mp3 file 128 to 64kbs. for that i need to convert into .wav and re convert to .mp3 i believe.
so, can i use this dll to convert from mp3 to wav?

Please advice me ,
Thank you

LameMP3FileWriter encodes with random bitrate value when using FileStream.Create to generate a File (Stream)

First of all, thanks a lot for this lib it's really useful,

So, I upgraded from 1.0.9 to 1.1.6, after upgrading NAudio to 1.10.0
Looks like it does not use the bitrate set when using Stream, when using string (path to file) it works:

  • Using: Bit rate used ABR_160
  • Issue: Instead of getting mp3 around 155-165 like before, it now goes between 20 to 190

code when I was using 1.0.9

// fileName: string pathname to file ("..\fileName.mp3")
// supportedWaveFormat : Naudio.WaveFormat (48kHz sample rate, 2 channels)
// _userSettings.Bitrate : LAMEPreset (one of those 4 : ABR_128, ABR_160, ABR_256, ABR_320)
var writer = new LameMP3FileWriter(fileName, supportedWaveFormat, _userSettings.Bitrate);

context : https://github.com/jwallet/spy-spotify/blob/1.8/EspionSpotify/Recorder.cs#L224

code used on 1.1.6 (after upgrading to NAudio 1.10.0)

// stream : Stream of FileStream.Create("..\fileName.mp3", FileMode.Create, FileAccess.Write, FileShare.Read)
// supportedWaveFormat : Naudio.WaveFormat (48kHz sample rate, 2 channels)
// _userSettings.Bitrate : LAMEPreset (one of those 4 : ABR_128, ABR_160, ABR_256, ABR_320)
var writer = new LameMP3FileWriter(stream, supportedWaveFormat, _userSettings.Bitrate);

context : https://github.com/jwallet/spy-spotify/blob/master/EspionSpotify/Recorder.cs#L249
used like so : https://github.com/jwallet/spy-spotify/blob/master/EspionSpotify/Recorder.cs#L201:L214

I know that's Average Bit Rate but it should be around the choosen rate, but using the latest version it encodes 1 song every 5 tracks at 35kbps which gives me a track with a length of 18minutes instead of 4minutes, when I play the song from start to finish it stop at 4min/18min.

So downgrading the lib to 1.0.9 seems to help it for me, still using NAudio 1.10.0, bitrates are less random, it goes in a range of 150 to 170 for a 160ABR, it used to be more accurate so the media length was actually the right one.

I will continue debugging it, I will close if it comes from another place

LAMEPreset V0 to V9 has no effect

It seems that the LAME-Presets are not having a effect on the conversions.
I've tried all 10 and they all produce the same file 80kb file.

This is on net core v. 3.1.302

`{

        using (var reader = new AudioFileReader("C:/tmp/source.wav")) 
        using (var writer = new LameMP3FileWriter("C:/tmp/LAMEPreset_V0.mp3", reader.WaveFormat, new LameConfig { Preset = NAudio.Lame.LAMEPreset.V0, Mode = NAudio.Lame.MPEGMode.JointStereo }))
        {
            reader.CopyTo(writer);
        }
        
        using (var reader = new AudioFileReader("C:/tmp/source.wav"))
        using (var writer = new LameMP3FileWriter("C:/tmp/LAMEPreset_V1.mp3", reader.WaveFormat, new LameConfig { Preset = NAudio.Lame.LAMEPreset.V1, Mode = NAudio.Lame.MPEGMode.JointStereo }))
        {
            reader.CopyTo(writer);
        }
        
        using (var reader = new AudioFileReader("C:/tmp/source.wav"))
        using (var writer = new LameMP3FileWriter("C:/tmp/LAMEPreset_V2.mp3", reader.WaveFormat, new LameConfig { Preset = NAudio.Lame.LAMEPreset.V2, Mode = NAudio.Lame.MPEGMode.JointStereo }))
        {
            reader.CopyTo(writer);
        }
        
        using (var reader = new AudioFileReader("C:/tmp/source.wav"))
        using (var writer = new LameMP3FileWriter("C:/tmp/LAMEPreset_V3.mp3", reader.WaveFormat, new LameConfig { Preset = NAudio.Lame.LAMEPreset.V3, Mode = NAudio.Lame.MPEGMode.JointStereo }))
        {
            reader.CopyTo(writer);
        }
        
        using (var reader = new AudioFileReader("C:/tmp/source.wav"))
        using (var writer = new LameMP3FileWriter("C:/tmp/LAMEPreset_V4.mp3", reader.WaveFormat, new LameConfig { Preset = NAudio.Lame.LAMEPreset.V4, Mode = NAudio.Lame.MPEGMode.JointStereo }))
        {
            reader.CopyTo(writer);
        }
        
        using (var reader = new AudioFileReader("C:/tmp/source.wav"))
        using (var writer = new LameMP3FileWriter("C:/tmp/LAMEPreset_V5.mp3", reader.WaveFormat, new LameConfig { Preset = NAudio.Lame.LAMEPreset.V5, Mode = NAudio.Lame.MPEGMode.JointStereo }))
        {
            reader.CopyTo(writer);
        }
        
        using (var reader = new AudioFileReader("C:/tmp/source.wav"))
        using (var writer = new LameMP3FileWriter("C:/tmp/LAMEPreset_V6.mp3", reader.WaveFormat, new LameConfig { Preset = NAudio.Lame.LAMEPreset.V6, Mode = NAudio.Lame.MPEGMode.JointStereo }))
        {
            reader.CopyTo(writer);
        }
        
        using (var reader = new AudioFileReader("C:/tmp/source.wav"))
        using (var writer = new LameMP3FileWriter("C:/tmp/LAMEPreset_V7.mp3", reader.WaveFormat, new LameConfig { Preset = NAudio.Lame.LAMEPreset.V7, Mode = NAudio.Lame.MPEGMode.JointStereo }))
        {
            reader.CopyTo(writer);
        }
        
        using (var reader = new AudioFileReader("C:/tmp/source.wav"))
        using (var writer = new LameMP3FileWriter("C:/tmp/LAMEPreset_V8.mp3", reader.WaveFormat, new LameConfig { Preset = NAudio.Lame.LAMEPreset.V8, Mode = NAudio.Lame.MPEGMode.JointStereo }))
        {
            reader.CopyTo(writer);
        }
        
        using (var reader = new AudioFileReader("C:/tmp/source.wav"))
        using (var writer = new LameMP3FileWriter("C:/tmp/LAMEPreset_V9.mp3", reader.WaveFormat, new LameConfig { Preset = NAudio.Lame.LAMEPreset.V9, Mode = NAudio.Lame.MPEGMode.JointStereo }))
        {
            reader.CopyTo(writer);
        }


    }

`

1.1.0-pre1 | .NET Core | Could not load file or assembly 'WrapLame'

Using the new 1.1.0-pre1 release found on Nuget with a .NET Core 2.2 app.

I've built a minimalist example console app to try and convert a .wav file to a .mp3 file Here's my code.

class Program
{
    static void Main(string[] args)
    {
        var directory = AppContext.BaseDirectory;
        var inputFile = Path.Combine(directory, "test.wav");
        var outputFileName = Path.Combine(directory, "test.mp3");

        WaveToMP3(inputFile, outputFileName);
    }

    // Convert WAV to MP3 using libmp3lame library
    public static void WaveToMP3(string waveFileName, string mp3FileName, int bitRate = 128)
    {
        using (var reader = new AudioFileReader(waveFileName))
        using (var writer = new LameMP3FileWriter(mp3FileName, reader.WaveFormat, bitRate))
            reader.CopyTo(writer);
    }
}

The code works on .Net Framework, however on Core we receive the below error.

'Could not load file or assembly 'WrapLame, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.'

image

Assemblies are not signed.

I am trying to reference in a SharePoint project which will deploy assemblies into GAC, I am getting error that assemblies are not signed. I have tried to sign the assemblies but then getting compile error. could you please upload signed assemblies package through Nuget?

Null reference exception on flush (or dispose)

I've been trying to find and fix an issue where on some PC's, in some cases, a null-reference exception is thrown when stopping the recording. Not sure if it's actually me doing something wrong, or a possible bug

This is the error:

System.NullReferenceException: De objectverwijzing is niet op een exemplaar van een object ingesteld.
bij LameDLLWrap.NativeMethods.lame_encode_buffer(IntPtr context, Int16[] buffer_l, Int16[] buffer_r, Int32 nSamples, Byte[] mp3buf, Int32 mp3buf_size)
bij NAudio.Lame.LameMP3FileWriter.Encode_pcm_16_mono()
bij NAudio.Lame.LameMP3FileWriter.Encode()
bij NAudio.Lame.LameMP3FileWriter.Flush()
bij _DM.AudioRecorderSingle.StopRecording()
bij _DM.TestRecordDialog.OnRecordTimedEvent(Object source, ElapsedEventArgs e)

This is the class I use for the recorder:

namespace _DM
{
    public enum RecorderStatus { Preparing, Recording, Paused, Stopped};
    public class AudioRecorderSingle
    {
        WaveInEvent waveIn;
        LameMP3FileWriter mp3Writer;

        RecorderStatus status = RecorderStatus.Preparing;
        public RecorderStatus Status
        {
            get { return status;  }
        }

        System.Timers.Timer timer;

        public AudioRecorderSingle()
        {
            Model model = Program.mainForm.model;
            int deviceID = model.UserSettings.DeviceID;
            if (deviceID < 0) deviceID = 0;
            if (deviceID >= WaveIn.DeviceCount) deviceID = WaveIn.DeviceCount - 1;

            waveIn = new WaveInEvent();
            waveIn.WaveFormat = new WaveFormat(44100, 16, 1); //44.1Khz 16-bit, mono
            waveIn.DeviceNumber = deviceID;
            Console.WriteLine("Recording with device ID {0}", deviceID);
        }

        public bool StartRecording(string filename)
        {
            if (status != RecorderStatus.Preparing) return false;
            try
            {
                
                mp3Writer = new LameMP3FileWriter(filename, waveIn.WaveFormat, 256);
                status = RecorderStatus.Recording;
                waveIn.DataAvailable += WaveIn_DataAvailable;
                waveIn.StartRecording();
                while (waveIn.GetPosition() == 0) ;
                return true;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Fout bij aanmaken geluidsbestand");
                status = RecorderStatus.Stopped;
                return false;
            }
        }

        private void WaveIn_DataAvailable(object sender, WaveInEventArgs e)
        {
            if (mp3Writer != null && status == RecorderStatus.Recording)
            {
                try
                {
                    mp3Writer.Write(e.Buffer, 0, e.BytesRecorded);
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.Message, "Fout bij schrijven naar geluidsbestand");
                }
            }
        }


        public void PauseRecording()
        {
            Debug.Assert(status == RecorderStatus.Recording);

            if (status != RecorderStatus.Recording) return;

            if (timer != null) timer.Enabled = false;
            timer = new System.Timers.Timer(250); //pause only after .25 seconds so it has some time to save buffer
            timer.AutoReset = false;
            timer.Elapsed += (sender, args) => status = RecorderStatus.Paused;
            timer.Start();
            //waveIn.StopRecording();

        }

        public void ResumeRecording()
        {
            Debug.Assert(status == RecorderStatus.Paused);

            if (status != RecorderStatus.Paused) return;

            status = RecorderStatus.Recording;
        }

        public void StopRecording()
        {
            if (status != RecorderStatus.Recording && status != RecorderStatus.Paused) return;
            status = RecorderStatus.Stopped;
            try
            {
                waveIn?.StopRecording();
                mp3Writer?.Flush();
                waveIn?.Dispose();
                mp3Writer?.Dispose();
            }
            catch(Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}

I really don't see what I'm doing wrong here, any clues?

libmp3lame.dll as (Embedded) Resource

Hi, can I embed libraries(libmp3lame.32.dll & libmp3lame.64.dll) as (embedded) resources? I'm trying to use Costura.Fody for creating a clean output directory. Its documentation says that it's able to handle unmanaged files. Can anyone help me to do this?

UPD: Can I use this lib in 3.5 Framework?

Incompatibility with NAudio 2.0.0-beta1

When traing to upgrade NAudio from 1.10 to 2.0 beta 1, the code does not compile anymore and throws an error:

Gravité	Code	Description	Projet	Fichier	Ligne	État de la suppression
Erreur	CS0012	Le type 'WaveFormat' est défini dans un assembly qui n'est pas référencé. Vous devez ajouter une référence à l'assembly 'NAudio, Version=1.10.0.0, Culture=neutral, PublicKeyToken=null'.	Common.Audio	C:\Users\Patrick\source\repos\Project\Common.Audio\CachedSound.cs	251	Actif

It is missing an assembly 'NAudio, Version=1.10.0.0, Culture=neutral, PublicKeyToken=null' and does not seem to recognize the new version.

The error occurs at this line of my code:

using (LameMP3FileWriter writer = new LameMP3FileWriter(fileName, mp3WaveFormat, bitRate))

The usings are (unchanged):

using NAudio.Wave;
using NAudio.Lame;

Reference to native dlls not added

When adding NAudio.Lame from nuget, reference to the native dlls(libmp3lame.32.dll, libmp3lame.64.dll) are not added to the project. These two dlls are not copied to the project output folder.

And running the project caused a System.DllNotFoundException : Unable to load DLL 'libmp3lame.64.dll'

And this is what the references are like
image

Found this problem in VS2017 in a Azure Function project.

NAudio.Lame and fody.costura

Hello

I am using fody.cosura in my project to include the .dll in the executable.
When I call LameMP3FileWriter, I get the error:
Could not load file or assembly "LameDLLWrap, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = null" or one of its dependencies. The parameter is set incorrectly. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

How can this problem be solved?

Using:
VS2019
NAudio.Lame last version

Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection

Hi,

I am trying to convert a WAV file to MP3 (this works fine for MP3 to MP3) using the following code:

using (var reader = new NAudio.Wave.AudioFileReader(Server.MapPath(my_upload_path))) { using (var writer = new NAudio.Lame.LameMP3FileWriter(Server.MapPath(my_converted_path), reader.WaveFormat, 64)) { reader.CopyTo(writer); } }

But I'm getting the following error:

System.ArgumentException: Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.
at System.IO.BinaryReader.Read(Byte[] buffer, Int32 index, Int32 count)
at NAudio.Wave.WaveFormat.FromFormatChunk(BinaryReader br, Int32 formatChunkLength)
at NAudio.FileFormats.Wav.WaveFileChunkReader.ReadWaveHeader(Stream stream)
at NAudio.Wave.WaveFileReader..ctor(Stream inputStream, Boolean ownInput)
at NAudio.Wave.WaveFileReader..ctor(String waveFile)
at NAudio.Wave.AudioFileReader.CreateReaderStream(String fileName)
at NAudio.Wave.AudioFileReader..ctor(String fileName)
at portal.UserControls.ModalAssessmentAudio.ConvertAudioFileUsingLame()
at portal.UserControls.ModalAssessmentAudio.ProcessAudioFile()]

Type `NAudio.Wave.WaveFileReader' does not contain a definition for `CopyTo'

Error Log:

error CS1061: Type NAudio.Wave.WaveFileReader' does not contain a definition forCopyTo' and no extension method CopyTo' of typeNAudio.Wave.WaveFileReader' could be found (are you missing a using directive or an assembly reference?)

What the codes are just the same as the example

    // Convert WAV to MP3 using libmp3lame library
    static void WaveToMP3(string waveFileName, string mp3FileName, int bitRate = 32)
    {
        var reader = new WaveFileReader(waveFileName);
        var writer = new LameMP3FileWriter(mp3FileName, reader.WaveFormat, bitRate);


        reader.CopyTo(writer);

    }

It is a really annoying problem, and I have no idea about how to fix it. Hope your help.

More control over output file

Currently, in NAudio.Lame I cannot find any way to do the following:

  • Mark as Copyrighted (this is a flag in addition to the ID3 Tag, LAME parameter "-c")
  • Support for the conversion mode (LAME parameter "-m")
    • Joint 'j'
    • Dual Mono 'd'
    • Mono 'm'
    • Left 'l'
    • Right 'r'
  • Support for "High Quality" parameter (LAME parameter "-h")

These are all things I need to ensure exist in my target MP3 file after conversion. I currently have a poor man's wrapper library that executes Lame as a separate process that applies these settings. I'd like to retire that library and use this one.

Issue with NAudio.Lame package in my asp.net core 3.1 project but got

I have installed NAudio.Lame package into my asp.net core 3.1 (Web Project) but after running I got error

DllNotFoundException: Unable to load DLL 'libmp3lame.64.dll'

I checked and see libraries are in the folder

\bin\Debug\netcoreapp3.1:

  • NAudio.Lame.dll
  • NAudio.dll
  • libmp3lame.32.dll
  • libmp3lame.64.dll

I'm using NAudio.Lame 1.1.2 version

I also tried to call code (as recomended ) but it didn't help.

// find path to 'bin' folder
var binPath = Path.Combine(new string[] { AppDomain.CurrentDomain.BaseDirectory, "bin" });
// get current search path from environment
var path = Environment.GetEnvironmentVariable("PATH") ?? "";

        // add 'bin' folder to search path if not already present
        if (!path.Split(Path.PathSeparator).Contains(binPath, StringComparer.CurrentCultureIgnoreCase))
        {
            path = string.Join(Path.PathSeparator.ToString(), new string[] { path, binPath });
            Environment.SetEnvironmentVariable("PATH", path);
        }

But It's working if I'm running console application in the .net core 3.1

Any suggestion how to get it worked?

Missing properties assignment in lame initialization

Since your rework of the lame initialization in this commit, the InputSampleRate and NumChannels properties of the LibMp3Lame class are not set anymore (previously done here and here).

Is it just a small oversight or is there a new way to set thoses properties ?

Thank you anyway for this very useful wrapper !

Sample code throws 'System.DllNotFoundException' in LameDLLWrap

Attempting to run sample code

// Convert WAV to MP3 using libmp3lame library
    public static void WaveToMP3(string waveFileName, string mp3FileName, int bitRate = 128)
    {
        using (var reader = new AudioFileReader(waveFileName))
        using (var writer = new LameMP3FileWriter(mp3FileName, reader.WaveFormat, bitRate))
            reader.CopyTo(writer);
    }

throws DllNotFoundException.

I don't have any DLL's anywhere on my machine that start with libmp3lame... should those be included with NuGet package?

ConvertSourceToMP3 0xffffe885

Convert Amr To MP3 Error!

/code/
public void ConvertSourceToMP3(string inputFilePath = "test.amr", string outFilePath = "test.mp3")
{
//using (var reader = new AudioFileReader(inputFilePath))
//using (var writer = new LameMP3FileWriter(outFilePath, new WaveFormat(16000, 1), 128))
// reader.CopyTo(writer);

        using (var reader = new MediaFoundationReader(inputFilePath))
            MediaFoundationEncoder.EncodeToMp3(reader, outFilePath, 128000);
    }

please help! thanks

libmp3lame.64.dll can't be deleted

Hi - I am using your library to convert wav files to mp3 files in a web api. Everything works fine except when trying to build or deploy which will try to overwrite the libmp3lame.64.dll in the bin folder of the web api project. It says its not able to replace the file because its being used by the IIS worker process.

I have been trying to test this to see what is going on and not too sure how to solve this? Seems like the dll reference is not being closed after using it?

I am simply doing the following in the web api

public static byte[] ConvertWavToMp3(byte[] wavFile)
{
using (var retMs = new MemoryStream())
using (var ms = new MemoryStream(wavFile))
using (var rdr = new WaveFileReader(ms))
using (var wtr = new LameMP3FileWriter(retMs, rdr.WaveFormat, 128))
{
rdr.CopyTo(wtr);
return retMs.ToArray();
}
}

How to get best audio quality

Okay, I have built a ripper program hoping to get the best audio quality for the Plex media server I am setting up. Before I rip hundreds of CD's, I want to check if I am using the best options to obtain the best quality this library is capable of giving. So, here is what I am using:

` ID3TagData tag = new ID3TagData
{
Title = strTrackName,
Artist = strArtist,
Album = strAlbum,
Year = strYear,
Genre = strFinalGenre
};

        LameConfig config = new LameConfig
        {
            VBR = VBRMode.ABR,
            VBRQuality = 0,
            ABRRateKbps = 320,
            VBRMinimumRateKbps = 256,
            VBREnforceMinimum = true,
            OutputSampleRate = 48000,
            ID3 = tag
        };

`
The few tests that I have made sound okay to me. But, I wear hearing aids. They are supposed to correct things to near normal for every day use, but maybe not for my purposes here. I would like someone with more experience using the library to give me a hand setting up the options before I rip all these CD's. The audience will thank you!

Call LameMP3FileWriter.Write() from Task.Run()

Hello
How can I solve this problem?
SendData() is called from the program.
stream - network

I have code:
_mp3Writer = new LameMP3FileWriter(stream,...);
...
private ConcurrentQueue<short[]> queue = new ConcurrentQueue<short[]>();
public async void SendData(short[] data)
{
if (_mp3Writer == null || !IsConnected) return;
queue.Enqueue(data);
// WriteAsync not handled by LameMP3FileWriter :(
await Task.Run(() => SendDataFromQueue());
}
private void SendDataFromQueue()
{
if (queue.TryDequeue(out short[] data))
{
byte[] bytes = new byte[data.Length * sizeof(short)];
Buffer.BlockCopy(data, 0, bytes, 0, bytes.Length);
_mp3Writer.Write(bytes, 0, bytes.Length);
^^^^^^^^^^^^^^^^^^^^^^^^^^^
}
}

I get exception:
Managed Debugging Helper 'CallbackOnCollectedDelegate' : "A delegate of type 'LameDLLWrap!LameDLLWrap.delReportFunction::Invoke' received by the garbage collector was called back. This can cause application crashes and data corruption or loss. Passing delegates to unmanaged code, managed application must keep them alive until it is guaranteed that they will never be called again."

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.