Git Product home page Git Product logo

speexdsp-python's Introduction

speexdsp for python

Build Status

Requirements

  • swig
  • compile toolchain
  • python
  • libspeexdsp-dev

Build

There are two ways to build the package.

  1. using setup.py

    sudo apt install libspeexdsp-dev
    git clone https://github.com/xiongyihui/speexdsp-python.git
    cd speexdsp-python
    python setup.py install
    
  2. using Makefile

    git clone https://github.com/xiongyihui/speexdsp-python.git
    cd speexdsp-python/src
    make
    

Get started

"""Acoustic Echo Cancellation for wav files."""

import wave
import sys
from speexdsp import EchoCanceller


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


frame_size = 256

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

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

out = wave.open(sys.argv[3], '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()))
print('far - rate: {}, channels: {}'.format(far.getframerate(), far.getnchannels()))



echo_canceller = EchoCanceller.create(frame_size, 2048, near.getframerate())

in_data_len = frame_size
in_data_bytes = frame_size * 2
out_data_len = frame_size
out_data_bytes = frame_size * 2

while True:
    in_data = near.readframes(in_data_len)
    out_data = far.readframes(out_data_len)
    if len(in_data) != in_data_bytes or len(out_data) != out_data_bytes:
        break

    in_data = echo_canceller.process(in_data, out_data)

    out.writeframes(in_data)

near.close()
far.close()
out.close()

speexdsp-python's People

Contributors

xiongyihui avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

speexdsp-python's Issues

fatal error: speex/speex_echo.h: No such file or directory

您好,我尝试使用您的移植库时编译出现问题,看起来是因为我使用了python3的虚拟环境而系统的sudo执行环境之下的python是2.7,导致了编译的问题。但是如果如此,则说明安装python包的时候没有安装到虚拟环境之中。请问您有什么建议吗?

building 'speexdsp._speexdsp' extension
swigging src/speexdsp.i to src/speexdsp_wrap.cpp
swig -python -c++ -Isrc -o src/speexdsp_wrap.cpp src/speexdsp.i
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Isrc -I/usr/include/python2.7 -c src/echo_canceller.cpp -o build/temp.linux-x86_64-2.7/src/echo_canceller.o
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ [enabled by default]
src/echo_canceller.cpp:6:30: fatal error: speex/speex_echo.h: No such file or directory
#include "speex/speex_echo.h"
^
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

Error about Type Error

您好,我在使用EchoCanceller处理音频时,报出如下错误:
TypeError: in method 'EchoCanceller_process', argument 2 of type 'std::string const &'

我按照您目录里的test读取音频来处理,运行到
in_data = echo_canceller.process(in_data, out_data)
这一行代码时报出如上所示的错误。

LINK : fatal error LNK1181: 無法開啟輸入檔 'speexdsp.lib'

Hello, I would like to try this library about echo cancellation,.
I don't really realize about the message, I can't find speexdsp.lib in my file, can you help me fix the problem?

Thanks a lot!!

I use visual studio 2017 and windows 10, python3.5
(Does it only work on Ubuntu or Linux environment ?!)

Error about Makefile

您好,我用setup.py安装后没问题,但是用您写的Makefile编译后导入时会出现下面的错误:

import speexdsp
Traceback (most recent call last):
File "", line 1, in
File "/home/lair/speexdsp-python/src/speexdsp.py", line 15, in
import _speexdsp
ImportError: /home/lair/speexdsp-python/src/_speexdsp.so: undefined symbol: PyInstance_Type
想请问以下您该怎么处理

test_data

hello,would u like to upload some test data for ur code? thx

ImportError: No module named speexdsp

运用sudo apt-get install libspeexdsp-dev 安装完依赖后,运用setup.py装上了,但好像无法使用,在terminal里使用ipython 无法import speexdsp 和from speexdsp import EchoCanceller ,但在用pycharm写一个.py时,import speexdsp似乎没有问题,但from speexdsp import EchoCanceller却不行,最后运行的时候会报错

error encountered in setting up the module

Hi yihui,

I'm currently on a machine anomaly detection project and willing to utilize this module for filtering out the background noise like ventilation from the source signal that I gathered.

× Running setup.py install for speexdsp did not run successfully. │ exit code: 1 ╰─> [19 lines of output] running install /usr/local/lib/python3.8/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools. warnings.warn( running build running build_py creating build creating build/lib.macosx-11-x86_64-3.8 creating build/lib.macosx-11-x86_64-3.8/speexdsp copying src/__init__.py -> build/lib.macosx-11-x86_64-3.8/speexdsp copying src/speexdsp.py -> build/lib.macosx-11-x86_64-3.8/speexdsp running build_ext building 'speexdsp._speexdsp' extension swigging src/speexdsp.i to src/speexdsp_wrap.cpp swig -python -c++ -Isrc -o src/speexdsp_wrap.cpp src/speexdsp.i creating build/temp.macosx-11-x86_64-3.8 creating build/temp.macosx-11-x86_64-3.8/src clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -I/usr/local/opt/zlib/include -I/usr/local/opt/bzip2/include -Isrc -I/usr/local/Cellar/[email protected]/3.8.13_1/Frameworks/Python.framework/Versions/3.8/include/python3.8 -c src/echo_canceller.cpp -o build/temp.macosx-11-x86_64-3.8/src/echo_canceller.o xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun error: command '/usr/bin/clang' failed with exit code 1 [end of output]

Really want to try this library out, it would be great if you can help!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.