yamachu / DotnetWorld

Other
11 stars 2 forks source link

.wav file created with naudio always returns :: fmt (2) error when passed to GetAudioLength #11

Open PythonCircuit opened 4 months ago

PythonCircuit commented 4 months ago

When using NAudio to save a .wav file from my recording, I cannot extract the proper length of the recording when passing to GetAudioLength from the lib.

As far as I can tell I am creating the .wav file as it should be created and it plays back audio perfectly fine... Do I need to change these parameters to work with the library?

Rate, Bits, Channels?

I.E. waveIn.WaveFormat = new WaveFormat(44100, 16, 1);

var x_length = Tools.GetAudioLength(fufilePath);

So this problem seems to be exclusive to my .wav files however if I use the .wav file you provided it works fine. Is there a specifics to the wav file creation you could provide?

yamachu commented 4 months ago

Thanks for reporting the Issue. If you read the README, you will see the purpose of this repository. It is a wrapper library for World and the original code can be found here

https://github.com/mmorise/World/blob/f8dd5fb289db6a7f7f704497752bf32b258f9151/tools/audioio.cpp#L172-L215

If you look at the CheckHeader function called from this code, you will see that it only targets wav files with a specific header. Make sure the wav file you created follows that format.

I do not use NAudio, so I cannot assist you in creating wav files when using NAudio.

If you are using linux or macos, you can check the format by using the file or xxd command.

example

 xxd sampleapp/sample_voice.wav|head -n3
00000000: 5249 4646 6c46 0400 5741 5645 666d 7420  RIFFlF..WAVEfmt
00000010: 1000 0000 0100 0100 803e 0000 007d 0000  .........>...}..
00000020: 0200 1000 6461 7461 4846 0400 1d00 3300  ....dataHF....3.

This header follows the

Make sure that the wav file fulfills these conditions, except for the sampling rate. Also make sure the wav file is not a toooooooooooooooooooooooo long file that exceeds the specifications.

Thanks