1.0.15 • Published 5 years ago

audio-processing v1.0.15

Weekly downloads
7
License
MIT
Repository
github
Last release
5 years ago

Audio-Processing

A handy nodejs package for audio processing.

For example, it can extract frequencies from the audio and compute the pitch.

The source code can be found on https://github.com/fengzhang2011/audio-processing.

The npm package is on https://www.npmjs.com/package/audio-processing.

1. HOW TO USE

1.1 A simple test on the library

Just execute the following command.

$ cd build
$ cmake ..
$ make
$ ./audio_processing

1.2 Use it in the Javascript

This package has been published into the npm repository. Therefore, it can be installed via npm.

$ mkdir your_project
$ cd your_project
$ npm init
$ npm install audio-processing

NOTE:

If you encounter some issues like permission denied while installing it, especially in a docker container, try the following command. Reason: The unsafe-perm boolean set to true to suppress the UID/GID switching when running package scripts.

# npm config set unsafe-perm true

Now you could use the code. The example code is as follows.

const ap = require('audio-processing');

console.log(ap.hello());

async function test() {
let audio = await ap.readAudio("./wav/female.wav");
  console.log(audio.samplerate);
  ap.saveAudio("haha.wav", audio.wavdataL, audio.wavdataR, audio.samplerate, audio.bitdepth, audio.channels);
  console.log(ap.detectPitch(audio.wavdataL, audio.samplerate, 'acorr'));
  console.log(ap.detectPitch(audio.wavdataL, audio.samplerate, 'yin'));
  console.log(ap.detectPitch(audio.wavdataL, audio.samplerate, 'mpm'));
  // console.log(ap.detectPitch(audio.wavdataL, audio.samplerate, 'goertzel'));
  // console.log(ap.detectPitch(audio.wavdataL, audio.samplerate, 'dft'));

  let ampfreq = await ap.ampfreq(audio.wavdataL, audio.samplerate);
  // console.log('ampfreq=', ampfreq);

  let data = new Float32Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]);
  // console.log(data);

  let freq_data = await ap.fft(data);
  // console.log(freq_data);

  let td_data = await ap.ifft(freq_data.real, freq_data.imag);
  // console.log(td_data);
}

test();

2. CREDITS

This code uses the FFTS, Pitch-Detection, AudioFile, Opencore-AMR, MiniMp3, and libsamplerate.

Thanks for their great work.

The detailed versions in use are as follows:

#ProjectVersionDate
1FFTSfe86885Jun-17-2017
2Pitch-Detection7799a62Oct-07-2018
3AudioFilea6430a0Jun-06-2017
4Opencore-AMR0.1.5Mar-16-2017
5MiniMp37295650Sep-26-2018
6libsamplerate313685aMar-07-2019

3. THIRD-PARTY LIBRARIES

3.1 Supported Audio Format

3.1.1 Format: .wav (WAV)

Copy the AudioFile source code

$ git clone https://github.com/adamstark/AudioFile
$ cd AudioFile
$ mkdir build
$ cd build
$ g++ -ansi -pedantic -Werror -O3 -std=c++17 -fPIC -fext-numeric-literals -ffast-math -c ../*.cpp
$ ar rcs libaudiofile.a *.o

Once these commands are done, the libaudiofile.a will be generated under the build folder.

Copy the header file src/AudioFile.h and libaudiofile.a to ./include and ./lib folders, respectively, into this repository.

3.1.2 Format: .amr (AMR)

OpenAMR WB/NB

https://sourceforge.net/projects/opencore-amr/files/opencore-amr/

3.1.3 Format: .mp3 (MP3)

MP3 decoder

https://github.com/lieff/minimp3

3.2 Resample

3.2.1 Sample Rate Converter

libsamplerate

$ git clone https://github.com/anthonix/libsamplerate.git
$ cd libsamplerate
$ echo "set(CMAKE_C_FLAGS \"\${CMAKE_C_FLAGS} -fPIC\")" >> CMakeLists.txt
$ mkdir build
$ cd build
$ cmake ..
$ make

3.3 FFT and MFCC

3.3.1 Compile the FFTS static library

$ git clone https://github.com/anthonix/ffts.git
$ cd ffts
$ echo "set(CMAKE_C_FLAGS \"\${CMAKE_C_FLAGS} -fPIC\")" >> CMakeLists.txt
$ mkdir build
$ cd build
$ cmake ..
$ make ffts_static

NOTE: We must enable the -fPIC flag when compiling the ffts static library, to enable the "Position Independent Code". Otherwise, it will generate the follow error:

/usr/bin/ld: ../lib/libffts.a(ffts.c.o): relocation R_X86_64_32S against `.text' can not be used when making a shared object; recompile with -fPIC
../lib/libffts.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
make: *** [Release/obj.target/ssrc.node] Error 1

Once these commands are done, the libffts.a will be generated under the build folder.

Copy the header file include/ffts.h and libffts.a to ./include and ./lib folders, respectively, into this repository.

3.3.2 MFCC compuation

The code are written based on these great documents. Thanks for the authors.

3.4 Audio features

3.4.1 Pitch

Compile the Pitch-Detection static library

$ git clone https://github.com/sevagh/pitch-detection.git
$ cd pitch-detection
$ mkdir build
$ cd build
$ g++ -I../include -ansi -pedantic -Werror -Wall -O3 -std=c++17 -fPIC -fext-numeric-literals -ffast-math -c ../src/*.cpp
$ ar rcs --plugin $(gcc --print-file-name=liblto_plugin.so) libpitch_detection.a *.o

Once these commands are done, the libpitch_detection.a will be generated under the build folder.

Copy the header file include/pitch_detection.h and libpitch_detection.a to ./include and ./lib folders, respectively, into this repository.

3.5 Noise reduction

3.5.1 Weiner filter for Noise Reduction and speech enhancement.

Pascal Scalart. Wiener Noise Suppressor based on Decision-Directed method with TSNR and HRNR algorithms.

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago