Giter Club home page Giter Club logo

kaldi-native-fbank's Introduction

Introduction

Kaldi-compatible online fbank feature extractor without external dependencies.

Tested on the following architectures and operating systems:

  • Linux
  • macOS
  • Windows
  • Android
  • x86
  • arm
  • aarch64

Usage

See the following CMake-based speech recognition (i.e., text-to-speech) projects for its usage:

They use kaldi-native-fbank to compute fbank features for real-time speech recognition.

Python APIs

First, please install kaldi-native-fbank by

git clone https://github.com/csukuangfj/kaldi-native-fbank
cd kaldi-native-fbank
python3 setup.py install

or use

pip install kaldi-native-fbank

To check that you have installed kaldi-native-fbank successfully, please use

python3 -c "import kaldi_native_fbank; print(kaldi_native_fbank.__version__)"

which should print the version you have installed.

Please refer to https://github.com/csukuangfj/kaldi-native-fbank/blob/master/kaldi-native-fbank/python/tests/test_online_fbank.py for usages.

For easier reference, we post the above file below:

#!/usr/bin/env python3

import sys

try:
    import kaldifeat
except:
    print("Please install kaldifeat first")
    sys.exit(0)

import kaldi_native_fbank as knf
import torch


def main():
    sampling_rate = 16000
    samples = torch.randn(16000 * 10)

    opts = kaldifeat.FbankOptions()
    opts.frame_opts.dither = 0
    opts.mel_opts.num_bins = 80
    opts.frame_opts.snip_edges = False
    opts.mel_opts.debug_mel = False

    online_fbank = kaldifeat.OnlineFbank(opts)

    online_fbank.accept_waveform(sampling_rate, samples)

    opts = knf.FbankOptions()
    opts.frame_opts.dither = 0
    opts.mel_opts.num_bins = 80
    opts.frame_opts.snip_edges = False
    opts.mel_opts.debug_mel = False

    fbank = knf.OnlineFbank(opts)
    fbank.accept_waveform(sampling_rate, samples.tolist())

    assert online_fbank.num_frames_ready == fbank.num_frames_ready
    for i in range(fbank.num_frames_ready):
        f1 = online_fbank.get_frame(i)
        f2 = torch.from_numpy(fbank.get_frame(i))
        assert torch.allclose(f1, f2, atol=1e-3), (i, (f1 - f2).abs().max())


if __name__ == "__main__":
    torch.manual_seed(20220825)
    main()
    print("success")

kaldi-native-fbank's People

Contributors

csukuangfj avatar haujetzhao avatar karelvesely84 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

Watchers

 avatar  avatar  avatar  avatar

kaldi-native-fbank's Issues

请教,如何不使用循环就得到全部的特征呢?

[fbank.get_frame(i) for i in range(fbank.num_frames_ready)]

现在的情况是通过for循环以及get_frame函数,得到全部的fbank特征。假如已经知道了fbank的维度(1000,80),那能否不使用循环直接得到呢?

高版本android ndk编译.c文件不编译

我用的android-ndk-r19c,编译时候发现缺少rdft,查看编译log发现,fftsg.c没有编译进去
image

image

我的编译命令是这样的 cmake -DCMAKE_TOOLCHAIN_FILE=$ndk_dir/build/cmake/android.toolchain.cmake \ -DARCH=${target} \ -DANDROID_TOOLCHAIN=clang -DANDROID_ABI=${ABI} -DANDROID_PLATFORM=android-21 \ -DCMAKE_BUILD_TYPE=${build_type} ../../../

Can't compile

Hi,

This looks like an amazing project, thank you!

I get the following error when trying to compile it on linux-amd64 with the command python3 setup.py install

#32 0.461 /usr/local/lib/python3.10/dist-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
#32 0.461   warnings.warn(
#32 0.461 running install
#32 0.498 /usr/local/lib/python3.10/dist-packages/setuptools/command/easy_install.py:144: EasyInstallDeprecationWarning: easy_install command is deprecated. Use build and pip and other standards-based tools.
#32 0.498   warnings.warn(
#32 0.504 running bdist_egg
#32 0.507 running egg_info
#32 0.507 creating kaldi_native_fbank.egg-info
#32 0.508 writing kaldi_native_fbank.egg-info/PKG-INFO
#32 0.508 writing dependency_links to kaldi_native_fbank.egg-info/dependency_links.txt
#32 0.508 writing top-level names to kaldi_native_fbank.egg-info/top_level.txt
#32 0.508 writing manifest file 'kaldi_native_fbank.egg-info/SOURCES.txt'
#32 0.511 reading manifest file 'kaldi_native_fbank.egg-info/SOURCES.txt'
#32 0.511 reading manifest template 'MANIFEST.in'
#32 0.514 adding license file 'LICENSE'
#32 0.515 writing manifest file 'kaldi_native_fbank.egg-info/SOURCES.txt'
#32 0.515 installing library code to build/bdist.linux-x86_64/egg
#32 0.515 running install_lib
#32 0.515 running build_py
#32 0.515 creating build
#32 0.515 creating build/lib.linux-x86_64-cpython-310
#32 0.515 creating build/lib.linux-x86_64-cpython-310/kaldi_native_fbank
#32 0.515 copying kaldi-native-fbank/python/kaldi_native_fbank/__init__.py -> build/lib.linux-x86_64-cpython-310/kaldi_native_fbank
#32 0.516 running build_ext
#32 0.604 -- The CXX compiler identification is GNU 11.3.0
#32 0.664 -- The C compiler identification is GNU 11.3.0
#32 0.671 -- Detecting CXX compiler ABI info
#32 0.771 -- Detecting CXX compiler ABI info - done
#32 0.783 -- Check for working CXX compiler: /usr/bin/c++ - skipped
#32 0.783 -- Detecting CXX compile features
#32 0.784 -- Detecting CXX compile features - done
#32 0.787 -- Detecting C compiler ABI info
#32 0.866 -- Detecting C compiler ABI info - done
#32 0.879 -- Check for working C compiler: /usr/bin/cc - skipped
#32 0.880 -- Detecting C compile features
#32 0.880 -- Detecting C compile features - done
#32 0.881 -- CMAKE_BUILD_TYPE: Release
#32 0.881 -- BUILD_SHARED_LIBS: ON
#32 0.881 -- KALDI_NATIVE_FBANK_ENABLE_CHECK: ON
#32 0.882 -- Downloading pybind11
#32 1.865 -- pybind11 is downloaded to /tmp/kaldi-native-fbank/build/temp.linux-x86_64-cpython-310/_deps/pybind11-src
#32 1.870 -- pybind11 v2.9.2 
#32 1.893 -- Found PythonInterp: /usr/bin/python3 (found version "3.10.6") 
#32 1.912 -- Found PythonLibs: /usr/lib/x86_64-linux-gnu/libpython3.10.so
#32 1.915 -- Performing Test HAS_FLTO
#32 2.061 -- Performing Test HAS_FLTO - Success
#32 2.062 -- CMAKE_CXX_FLAGS: 
#32 2.062 -- CMAKE_INSTALL_PREFIX: /tmp/kaldi-native-fbank/build/temp.linux-x86_64-cpython-310/install
#32 2.063 -- Looking for C++ include cxxabi.h
#32 2.167 -- Looking for C++ include cxxabi.h - found
#32 2.168 -- Looking for C++ include execinfo.h
#32 2.262 -- Looking for C++ include execinfo.h - found
#32 2.268 -- Configuring done
#32 2.274 -- Generating done
#32 2.275 -- Build files have been written to: /tmp/kaldi-native-fbank/build/temp.linux-x86_64-cpython-310
#32 2.279 make: *** No rule to make target '_kaldi_native_fbank'.  Stop.
#32 2.280 Setting PYTHON_EXECUTABLE to /usr/bin/python3
#32 2.280 build command is:
#32 2.280 
#32 2.280                 cd build/temp.linux-x86_64-cpython-310
#32 2.280 
#32 2.280                 cmake -DCMAKE_BUILD_TYPE=Release -DPYTHON_EXECUTABLE=/usr/bin/python3 -DKALDI_NATIVE_FBANK_BUILD_TESTS=OFF  -DCMAKE_INSTALL_PREFIX=/tmp/kaldi-native-fbank/build/lib.linux-x86_64-cpython-310/kaldi_native_fbank  /tmp/kaldi-native-fbank
#32 2.280 
#32 2.280 
#32 2.280                 make -j _kaldi_native_fbank install
#32 2.280             
#32 2.280 Traceback (most recent call last):
#32 2.280   File "/tmp/kaldi-native-fbank/setup.py", line 32, in <module>
#32 2.280     setuptools.setup(
#32 2.280   File "/usr/local/lib/python3.10/dist-packages/setuptools/__init__.py", line 87, in setup
#32 2.280     return distutils.core.setup(**attrs)
#32 2.280   File "/usr/local/lib/python3.10/dist-packages/setuptools/_distutils/core.py", line 185, in setup
#32 2.280     return run_commands(dist)
#32 2.280   File "/usr/local/lib/python3.10/dist-packages/setuptools/_distutils/core.py", line 201, in run_commands
#32 2.280     dist.run_commands()
#32 2.280   File "/usr/local/lib/python3.10/dist-packages/setuptools/_distutils/dist.py", line 969, in run_commands
#32 2.281     self.run_command(cmd)
#32 2.281   File "/usr/local/lib/python3.10/dist-packages/setuptools/dist.py", line 1208, in run_command
#32 2.281     super().run_command(command)
#32 2.281   File "/usr/local/lib/python3.10/dist-packages/setuptools/_distutils/dist.py", line 988, in run_command
#32 2.281     cmd_obj.run()
#32 2.281   File "/usr/local/lib/python3.10/dist-packages/setuptools/command/install.py", line 74, in run
#32 2.281     self.do_egg_install()
#32 2.281   File "/usr/local/lib/python3.10/dist-packages/setuptools/command/install.py", line 123, in do_egg_install
#32 2.281     self.run_command('bdist_egg')
#32 2.281   File "/usr/local/lib/python3.10/dist-packages/setuptools/_distutils/cmd.py", line 318, in run_command
#32 2.282     self.distribution.run_command(command)
#32 2.282   File "/usr/local/lib/python3.10/dist-packages/setuptools/dist.py", line 1208, in run_command
#32 2.282     super().run_command(command)
#32 2.282   File "/usr/local/lib/python3.10/dist-packages/setuptools/_distutils/dist.py", line 988, in run_command
#32 2.282     cmd_obj.run()
#32 2.282   File "/usr/local/lib/python3.10/dist-packages/setuptools/command/bdist_egg.py", line 165, in run
#32 2.282     cmd = self.call_command('install_lib', warn_dir=0)
#32 2.282   File "/usr/local/lib/python3.10/dist-packages/setuptools/command/bdist_egg.py", line 151, in call_command
#32 2.282     self.run_command(cmdname)
#32 2.282   File "/usr/local/lib/python3.10/dist-packages/setuptools/_distutils/cmd.py", line 318, in run_command
#32 2.283     self.distribution.run_command(command)
#32 2.283   File "/usr/local/lib/python3.10/dist-packages/setuptools/dist.py", line 1208, in run_command
#32 2.283     super().run_command(command)
#32 2.283   File "/usr/local/lib/python3.10/dist-packages/setuptools/_distutils/dist.py", line 988, in run_command
#32 2.283     cmd_obj.run()
#32 2.283   File "/usr/local/lib/python3.10/dist-packages/setuptools/command/install_lib.py", line 11, in run
#32 2.283     self.build()
#32 2.283   File "/usr/local/lib/python3.10/dist-packages/setuptools/_distutils/command/install_lib.py", line 112, in build
#32 2.283     self.run_command('build_ext')
#32 2.283   File "/usr/local/lib/python3.10/dist-packages/setuptools/_distutils/cmd.py", line 318, in run_command
#32 2.284     self.distribution.run_command(command)
#32 2.284   File "/usr/local/lib/python3.10/dist-packages/setuptools/dist.py", line 1208, in run_command
#32 2.284     super().run_command(command)
#32 2.284   File "/usr/local/lib/python3.10/dist-packages/setuptools/_distutils/dist.py", line 988, in run_command
#32 2.284     cmd_obj.run()
#32 2.284   File "/usr/local/lib/python3.10/dist-packages/setuptools/command/build_ext.py", line 84, in run
#32 2.284     _build_ext.run(self)
#32 2.284   File "/usr/local/lib/python3.10/dist-packages/setuptools/_distutils/command/build_ext.py", line 346, in run
#32 2.284     self.build_extensions()
#32 2.284   File "/usr/local/lib/python3.10/dist-packages/setuptools/_distutils/command/build_ext.py", line 468, in build_extensions
#32 2.285     self._build_extensions_serial()
#32 2.285   File "/usr/local/lib/python3.10/dist-packages/setuptools/_distutils/command/build_ext.py", line 494, in _build_extensions_serial
#32 2.285     self.build_extension(ext)
#32 2.285   File "/tmp/kaldi-native-fbank/cmake/cmake_extension.py", line 122, in build_extension
#32 2.285     raise Exception(
#32 2.285 Exception: 
#32 2.285 Build kaldi-native-fbank failed. Please check the error message.
#32 2.285 You can ask for help by creating an issue on GitHub.
#32 2.285 
#32 2.285 Click:
#32 2.285       https://github.com/csukuangfj/kaldi-native-fbank/issues/new
#32 2.285 

如何同时支持mfcc特征

您好,请问如果增加mfcc特征支持,是将kaldi中feat的mfcc.cc,放进去可以吗?需要有很多代码修改嘛

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.