Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork105
💬 SpeechPy - A Library for Speech Processing and Recognition:http://speechpy.readthedocs.io/en/latest/
License
astorfi/speechpy
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation

This library provides most frequent used speech features including MFCCs and filterbank energies alongside with the log-energy of filterbanks.If you are interested to see what are MFCCs and how they are generated please refer to thiswiki page.
Please refer to the following links for further informations:
SpeechPy Official Project Documentation
Currently, the package has been tested and verified using Python2.7,3.4 and3.5.
If you used this package, please kindly cite it as follows:
@article{torfi2018speechpy, title={SpeechPy-A Libraryfor Speech Processing and Recognition}, author={Torfi, Amirsina}, journal={arXiv preprint arXiv:1803.01094}, year={2018} }There are two possible ways for installation of this package: local installation and PyPi.
For local installation at first the repository must be cloned:
git clone https://github.com/astorfi/speech_feature_extraction.git
After cloning the reposity, root to the repository directory then execute:
python setup.py develop
The package is available on PyPi. For direct installation simply execute the following:
pip install speechpy
- Mel Frequency Cepstral Coefficients(MFCCs)
- Filterbank Energies
- Log Filterbank Energies
Please refer toSpeechPy Official Project Documentation for details about the supported features.
The supported attributes for generating MFCC features can be seen by investigating the related function:
defmfcc(signal,sampling_frequency,frame_length=0.020,frame_stride=0.01,num_cepstral=13,num_filters=40,fft_length=512,low_frequency=0,high_frequency=None,dc_elimination=True):"""Compute MFCC features from an audio signal. :param signal: the audio signal from which to compute features. Should be an N x 1 array :param sampling_frequency: the sampling frequency of the signal we are working with. :param frame_length: the length of each frame in seconds. Default is 0.020s :param frame_stride: the step between successive frames in seconds. Default is 0.02s (means no overlap) :param num_filters: the number of filters in the filterbank, default 40. :param fft_length: number of FFT points. Default is 512. :param low_frequency: lowest band edge of mel filters. In Hz, default is 0. :param high_frequency: highest band edge of mel filters. In Hz, default is samplerate/2 :param num_cepstral: Number of cepstral coefficients. :param dc_elimination: hIf the first dc component should be eliminated or not. :returns: A numpy array of size (num_frames x num_cepstral) containing mfcc features. """
defmfe(signal,sampling_frequency,frame_length=0.020,frame_stride=0.01,num_filters=40,fft_length=512,low_frequency=0,high_frequency=None):"""Compute Mel-filterbank energy features from an audio signal. :param signal: the audio signal from which to compute features. Should be an N x 1 array :param sampling_frequency: the sampling frequency of the signal we are working with. :param frame_length: the length of each frame in seconds. Default is 0.020s :param frame_stride: the step between successive frames in seconds. Default is 0.02s (means no overlap) :param num_filters: the number of filters in the filterbank, default 40. :param fft_length: number of FFT points. Default is 512. :param low_frequency: lowest band edge of mel filters. In Hz, default is 0. :param high_frequency: highest band edge of mel filters. In Hz, default is samplerate/2 :returns: features: the energy of fiterbank: num_frames x num_filters frame_energies: the energy of each frame: num_frames x 1 """
The attributes forlog_filterbank energies are the same forfilterbank energies too.
deflmfe(signal,sampling_frequency,frame_length=0.020,frame_stride=0.01,num_filters=40,fft_length=512,low_frequency=0,high_frequency=None):"""Compute log Mel-filterbank energy features from an audio signal. :param signal: the audio signal from which to compute features. Should be an N x 1 array :param sampling_frequency: the sampling frequency of the signal we are working with. :param frame_length: the length of each frame in seconds. Default is 0.020s :param frame_stride: the step between successive frames in seconds. Default is 0.02s (means no overlap) :param num_filters: the number of filters in the filterbank, default 40. :param fft_length: number of FFT points. Default is 512. :param low_frequency: lowest band edge of mel filters. In Hz, default is 0. :param high_frequency: highest band edge of mel filters. In Hz, default is samplerate/2 :returns: features: the energy of fiterbank: num_frames x num_filters frame_log_energies: the log energy of each frame: num_frames x 1 """
InStack_Frames function, the stack of frames will be generated from the signal.
defstack_frames(sig,sampling_frequency,frame_length=0.020,frame_stride=0.020,Filter=lambdax:numpy.ones((x,)),zero_padding=True):"""Frame a signal into overlapping frames. :param sig: The audio signal to frame of size (N,). :param sampling_frequency: The sampling frequency of the signal. :param frame_length: The length of the frame in second. :param frame_stride: The stride between frames. :param Filter: The time-domain filter for applying to each frame. By default it is one so nothing will be changed. :param zero_padding: If the samples is not a multiple of frame_length(number of frames sample), zero padding will be done for generating last frame. :returns: Array of frames. size: number_of_frames x frame_len. """
There are some post-processing operation that are supported inspeechpy.
This function performs global cepstral mean and variance normalization(CMVN) to remove the channel effects. The code assumes that there is oneobservation per row.
defcmvn(vec,variance_normalization=False):""" This function is aimed to perform global ``cepstral mean and variance normalization`` (CMVN) on input feature vector "vec". The code assumes that there is one observation per row. :param: vec: input feature matrix (size:(num_observation,num_features)) variance_normalization: If the variance normilization should be performed or not. :return: The mean(or mean+variance) normalized feature vector. """
This function performs local cepstral mean and variance normalization(CMVN) over sliding windows. The code assumes that there is oneobservation per row.
defcmvnw(vec,win_size=301,variance_normalization=False):""" This function is aimed to perform local cepstral mean and variance normalization on a sliding window. (CMVN) on input feature vector "vec". The code assumes that there is one observation per row. :param vec: input feature matrix (size:(num_observation,num_features)) win_size: The size of sliding window for local normalization and should be odd. default=301 which is around 3s if 100 Hz rate is considered(== 10ms frame stide) variance_normalization: If the variance normilization should be performed or not. :return: The mean(or mean+variance) normalized feature vector. """
SpeechPy includes some unit tests. To run the tests,cd into thespeechpy/tests directory and run:
python -m pytest
For installing the requirements you only need to installpytest.
The test example can be seen intest/test.py as below:
importscipy.io.wavfileaswavimportnumpyasnpimportspeechpyimportosfile_name=os.path.join(os.path.dirname(os.path.abspath(__file__)),'Alesis-Sanctuary-QCard-AcoustcBas-C2.wav')fs,signal=wav.read(file_name)signal=signal[:,0]# Example of pre-emphasizing.signal_preemphasized=speechpy.processing.preemphasis(signal,cof=0.98)# Example of staching framesframes=speechpy.processing.stack_frames(signal,sampling_frequency=fs,frame_length=0.020,frame_stride=0.01,filter=lambdax:np.ones((x,)),zero_padding=True)# Example of extracting power spectrumpower_spectrum=speechpy.processing.power_spectrum(frames,fft_points=512)print('power spectrum shape=',power_spectrum.shape)############# Extract MFCC features #############mfcc=speechpy.feature.mfcc(signal,sampling_frequency=fs,frame_length=0.020,frame_stride=0.01,num_filters=40,fft_length=512,low_frequency=0,high_frequency=None)mfcc_cmvn=speechpy.processing.cmvnw(mfcc,win_size=301,variance_normalization=True)print('mfcc(mean + variance normalized) feature shape=',mfcc_cmvn.shape)mfcc_feature_cube=speechpy.feature.extract_derivative_feature(mfcc)print('mfcc feature cube shape=',mfcc_feature_cube.shape)############# Extract logenergy features #############logenergy=speechpy.feature.lmfe(signal,sampling_frequency=fs,frame_length=0.020,frame_stride=0.01,num_filters=40,fft_length=512,low_frequency=0,high_frequency=None)logenergy_feature_cube=speechpy.feature.extract_derivative_feature(logenergy)print('logenergy features=',logenergy.shape)
For extracting the feature at first, the signal samples will be stacked into frames. The features are computed for each frame in the stacked frames collection.
Two packages ofScipy andNumPy are the required dependencies which will be installed automatically by running thesetup.py file.
This work is based upon a work supported by the Center for Identification Technology Research and the National Science Foundation under Grant #1650474.
When contributing to this repository, you are more than welcome to discuss your feedback with any of the owners of this repository.For typos, please do not create a pull request. Instead, declare them in issues or email the repository owner. For technical and conceptual questions please feel free todirectly contact the repository owner. Before asking general questions related to the concepts and techniques provided in this project,please make sure to read and understand its associated paper.
Please consider the following criterions in order to help us in a better way:
- The pull request is mainly expected to be a code script suggestion or improvement.
- A pull request related to non-code-script sections is expected to make a significant difference in the documentation. Otherwise, it is expected to be announced in the issues section.
- Ensure any install or build dependencies are removed before the end of the layer when doing abuild and creating a pull request.
- Add comments with details of changes to the interface, this includes new environmentvariables, exposed ports, useful file locations and container parameters.
- You may merge the Pull Request in once you have the sign-off of at least one other developer, or if youdo not have permission to do that, you may request the owner to merge it for you if you believe all checks are passed.
For declaring issues, you can directly email the repository owner. However, preferably please create an issue as it might bethe issue that other repository followers may encounter. That way, the question to other developers will be answered as well.
We are looking forward to your kind feedback. Please help us to improve this open source project and make our work better.For contribution, please create a pull request and we will investigate it promptly. Once again, we appreciateyour kind feedback and elaborate code inspections.
Although by dramatic chages, some portion of this library is inspired by thepython speech features library.
We clain the following advantages for our library:
- More accurate operations have been performed for the mel-frequency calculations.
- The package supports different
Pythonversions. - The feature are generated in a more organized way as cubic features.
- The package is well-tested and integrated.
- The package is up-to-date and actively developing.
- The package has been used for research purposes.
- Exceptions and extreme cases are handled in this library.
About
💬 SpeechPy - A Library for Speech Processing and Recognition:http://speechpy.readthedocs.io/en/latest/
Topics
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.


