xiph / rnnoise

Recurrent neural network for audio noise reduction
BSD 3-Clause "New" or "Revised" License
3.97k stars 890 forks source link

Output file generated using demo code is not playable #155

Closed rawatnaresh closed 3 years ago

rawatnaresh commented 3 years ago

Just to simplify things I've pasted everything into a folder rnnoise

I've copied :

Screen Shot 2021-01-18 at 07 29 52

then I ran

gcc rnnoise_demo.c -L. -lrnnoise.0 -o rnnoise

and

./rnnoise test_noise.wav new.wav

but it gave the error

dyld: Library not loaded: /usr/local/lib/librnnoise.0.dylib
  Referenced from: /Users/nareshrawat/Desktop/rnnoise/./rnnoise
  Reason: image not found
[1]    2856 abort      ./rnnoise test_noise.wav new.wav

so to fix that

install_name_tool -change /usr/local/lib/librnnoise.0.dylib ~/Desktop/rnnoise/librnnoise.0.dylib rnnoise

and ran the command again

./rnnoise test_noise.wav new.wav

I can see the new file but it's not playable AudioFiles.zip

am I missing some steps here?

Environments

GCC version

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.0 (clang-1200.0.32.2)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

and macOS Catalina 10.15.7

j-schultz commented 3 years ago

rnnoise doesn't write WAV files, it just writes raw signed 16-bit PCM data without a header (it also only reads raw PCM data, so it will interpret the WAV header in your input file as audio data). If you want to read the file, you either need to prepend a WAV header to the data, or import it into an audio editor that can handle raw data (most editors can).

Also note that your input file is 44.1 kHz and stereo, but rnnoise only processes 48 kHz mono data. This may be one reason why the generated output doesn't sound very good.

rawatnaresh commented 3 years ago

@j-schultz Thank you so much for your quick response. šŸ˜Š I tried a couple of ways but I'm still confused. šŸ˜•

Does it have to be a .wav file to use this module? I'd like to perform noise suppression on raw data. Let's say I'm recording 48kHz mono audio from the microphone and I'm storing all the buffers in a .raw file.

./rnnoise test.raw out.wav

and I using that raw file as an input to rnnoise and after the output is generated I'm prepending the WAV headers just like you suggested. I'm able to play the outputted WAV file but I hear nothing(just some random noise)

I cannot just store the recorded file as a WAV file because, as you mentioned, it'll interpret the WAV headers as data and that can add noise to the output audio.

I'm confused about how I can use this with simple raw data.

j-schultz commented 3 years ago

As mentioned, the example code takes raw, 16-bit audio (mono, 48000 Hz) and outputs raw audio in the same format. The data you put into the example code shouldn't have WAV headers, and the data that is output will not contain them either, unless you modify it.

fpaupier commented 2 years ago

@rawatnaresh, I encountered the same issue to get a playable file afterward.

I managed to create a valid .wav file from the raw PCM data generated by this lib using audacity.

I can see it's encoded with 16 bits, uses 2 channels, and has a sample rate of 44 100 Hz

Tada! Your file should be playable and you can export it to another format