Metadata-Version: 2.4
Name: platypush_speexdsp_ns
Version: 0.1.2
Summary: Python bindings of speexdsp noise suppression library
Home-page: https://github.com/TeaPoly/speexdsp-ns-python
Author: Lucky Wong
License: BSD
Keywords: speexdsp_ns,acoustic noise suppression
Platform: Linux
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.6
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.2
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: C++
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: author
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: keywords
Dynamic: license
Dynamic: license-file
Dynamic: platform
Dynamic: summary

Python bindings of speexdsp noise suppression library
===================

Modified from https://github.com/xiongyihui/speexdsp-python

You can use it in Noise reduction model training as said in [Personalized PercepNet: Real-time, Low-complexity Target Voice Separation and Enhancement](https://arxiv.org/abs/2106.04129).
> Use a VAD and lightweight denoiser (SpeexDSP1) to eliminate the stationary noise before using this data for training.

## Requirements
+ swig
+ compile toolchain
+ python
+ libspeexdsp-dev

## Build
```shell
sudo apt install libspeexdsp-dev
sudo apt install swig
python setup.py install
```

## Get started

```python
"""Acoustic Noise Suppression for wav files."""

import wave
import sys
from speexdsp_ns import NoiseSuppression


if len(sys.argv) < 3:
    print('Usage: {} near.wav out.wav'.format(sys.argv[0]))
    sys.exit(1)


frame_size = 256

near = wave.open(sys.argv[1], 'rb')

if near.getnchannels() > 1:
    print('Only support mono channel')
    sys.exit(2)

out = wave.open(sys.argv[2], 'wb')
out.setnchannels(near.getnchannels())
out.setsampwidth(near.getsampwidth())
out.setframerate(near.getframerate())


print('near - rate: {}, channels: {}, length: {}'.format(
        near.getframerate(),
        near.getnchannels(),
        near.getnframes() / near.getframerate()))

noise_suppression = NoiseSuppression.create(frame_size, near.getframerate())

in_data_len = frame_size
in_data_bytes = frame_size * 2

while True:
    in_data = near.readframes(in_data_len)
    if len(in_data) != in_data_bytes:
        break

    in_data = noise_suppression.process(in_data)

    out.writeframes(in_data)

near.close()
out.close()
```

or

```python examples/main.py in.wav out.wav```

Noise suppression as show in figure below:

![image](examples/pic.jpg)
