xiph / rnnoise

Recurrent neural network for audio noise reduction

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Output file generated using demo code is not playable

rawatnaresh opened this issue · comments

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

I've copied :

  • librnnoise.0.dylib from ./libs
  • rnnoise.h from ./include
  • rnnoise_demo.c from ./examples
    and also added test_noise.wav into the same directory

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

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.

@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.

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.

@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.

  • Open Audacity and go to File > Import > Raw data ...
  • Select your audio file
  • You'll see a prompt requiring the appropriate metadata to interpret the raw data. You can use a tool like exiftool to know what are your original file characstericts and apply them to your generated file.
    • For example, running exiftool noisy.wav returned:
ExifTool Version Number         : 12.26
File Name                       : noisy.wav
Directory                       : .
File Size                       : 294 MiB
File Modification Date/Time     : 2021:10:09 11:02:19+02:00
File Access Date/Time           : 2021:10:09 11:02:19+02:00
File Inode Change Date/Time     : 2021:10:09 11:02:19+02:00
File Permissions                : -rw-r--r--
File Type                       : WAV
File Type Extension             : wav
MIME Type                       : audio/x-wav
Encoding                        : Microsoft PCM
Num Channels                    : 2
Sample Rate                     : 44100
Avg Bytes Per Sec               : 176400
Bits Per Sample                 : 16
Cue Points                      : (Binary data 28 bytes, use -b option to extract)
Cue Point Label                 : 1 Tempo: 120.0
Description                     :
Originator                      : GarageBand
Originator Reference            :
Date/Time Original              : 2021:10:09 11:02:17
Time Reference                  : 1764000
BWF Version                     : 1
BWF UMID                        : 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005A001E79
Coding History                  :
Duration                        : 0:29:07

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

  • Finally report those info in audacity import raw data
    image

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