linto-ai / sfeatpy Goto Github PK
View Code? Open in Web Editor NEWLibrary to extract MFCC features from audio signal
License: GNU Affero General Public License v3.0
Library to extract MFCC features from audio signal
License: GNU Affero General Public License v3.0
import tensorflow.compat.v1 as tf
from tensorflow.python.ops import gen_audio_ops as audio_ops
import tensorflow as tf
import sounddevice as sd
rec_duration = 0.020
sample_rate = 16000
num_channels = 1
sd.default.never_drop_input= False
sd.default.latency= ('high', 'high')
sd.default.dtype= ('float32', 'float32')
sd.default.device = 'cap1'
upper_frequency_limit=7600
lower_frequency_limit=120
filterbank_channel_count=40
dct_coefficient_count=13
tf.compat.v1.disable_eager_execution()
def get_mfcc(waveform):
# Run the spectrogram and MFCC ops to get a 2D audio: Short-time FFTs
# background_clamp dims: [time, channels]
spectrogram = audio_ops.audio_spectrogram(
waveform,
window_size=320,
stride=160)
# spectrogram: [channels/batch, frames, fft_feature]
# extract mfcc features from spectrogram by audio_ops.mfcc:
# 1 Input is spectrogram frames.
# 2 Weighted spectrogram into bands using a triangular mel filterbank
# 3 Logarithmic scaling
# 4 Discrete cosine transform (DCT), return lowest dct_coefficient_count
mfccs = audio_ops.mfcc(
spectrogram=spectrogram,
sample_rate=sample_rate,
upper_frequency_limit=7600,
lower_frequency_limit=120,
filterbank_channel_count=40,
dct_coefficient_count=13)
# mfcc: [channels/batch, frames, dct_coefficient_count]
# remove channel dim
mfccs = tf.squeeze(mfccs, axis=0)
return mfccs
def sd_callback(rec, frames, time, status):
# Notify if errors
if status:
print('Error:', status)
mfcc = get_mfcc(rec)
print(mfcc)
# Start streaming from microphone
with sd.InputStream(channels=num_channels,
samplerate=sample_rate,
blocksize=int(sample_rate * rec_duration),
callback=sd_callback):
while True:
pass
Or
import sounddevice as sd
import numpy as np
import librosa
rec_duration = 0.020
sample_rate = 16000
num_channels = 1
sd.default.never_drop_input= False
sd.default.latency= ('high', 'high')
sd.default.dtype= ('float32', 'float32')
sd.default.device = 'cap1'
def get_mfcc(audio):
audio = np.squeeze(audio, 1)
mfccs = librosa.feature.mfcc(y=audio, n_mfcc=13, sr=sample_rate, n_fft=320, hop_length=160, n_mels=40, fmin=60.0, fmax=76000.0, htk=False )
return mfccs
def sd_callback(rec, frames, time, status):
# Notify if errors
if status:
print('Error:', status)
mfcc = get_mfcc(rec)
print(mfcc)
# Start streaming from microphone
with sd.InputStream(channels=num_channels,
samplerate=sample_rate,
blocksize=int(sample_rate * rec_duration),
callback=sd_callback):
while True:
pass
sfeatpy in comparison seems heavy
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.