Kapre: Keras Audio Preprocessors for Real-time GPU Processing

This repository profile is provided by osrepos.com, an open source repository discovery platform.

Kapre: Keras Audio Preprocessors for Real-time GPU Processing

Summary

Kapre is a powerful Python library that provides Keras layers for real-time audio preprocessing directly on GPUs. It enables efficient computation of STFT, Melspectrograms, and other audio features within your deep learning models. This integration simplifies model deployment, allows for DSP parameter optimization, and ensures consistency compared to traditional pre-computation or custom implementations.

Repository Information

Analyzed by OSRepos on May 3, 2026

Use at your own risk

OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of code from these repositories is the user's own responsibility. Always review the repository, source code, dependencies, licenses, and security implications before running or installing anything. OSRepos is not responsible for issues, damages, or losses resulting from third-party repositories.

Introduction

Kapre is a powerful Python library that offers Keras Audio Preprocessors, allowing you to compute essential audio features like STFT, ISTFT, Melspectrogram, and more, directly on the GPU in real-time. Designed for Python 3.8+ with type hints, Kapre integrates seamlessly into your deep learning workflow, making audio feature extraction an integral part of your Keras models.

Installation

Kapre can be easily installed using pip:

pip install kapre

Examples

Integrating Kapre into your Keras model is straightforward. Here's a one-shot example demonstrating how to add STFT and other processing layers to a sequential model:

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv2D, BatchNormalization, ReLU, GlobalAveragePooling2D, Dense, Softmax
from kapre import STFT, Magnitude, MagnitudeToDecibel
from kapre.composed import get_melspectrogram_layer, get_log_frequency_spectrogram_layer

# 6 channels (!), maybe 1-sec audio signal, for an example.
input_shape = (44100, 6)
sr = 44100
model = Sequential()
# A STFT layer
model.add(STFT(n_fft=2048, win_length=2018, hop_length=1024,
               window_name=None, pad_end=False,
               input_data_format='channels_last', output_data_format='channels_last',
               input_shape=input_shape))
model.add(Magnitude())
model.add(MagnitudeToDecibel())  # these three layers can be replaced with get_stft_magnitude_layer()
# Alternatively, you may want to use a melspectrogram layer
# melgram_layer = get_melspectrogram_layer()
# or log-frequency layer
# log_stft_layer = get_log_frequency_spectrogram_layer() 

# add more layers as you want
model.add(Conv2D(32, (3, 3), strides=(2, 2)))
model.add(BatchNormalization())
model.add(ReLU())
model.add(GlobalAveragePooling2D())
model.add(Dense(10))
model.add(Softmax())

# Compile the model
model.compile('adam', 'categorical_crossentropy') # if single-label classification

# train it with raw audio sample inputs
# for example, you may have functions that load your data as below.
x = load_x() # e.g., x.shape = (10000, 6, 44100)
y = load_y() # e.g., y.shape = (10000, 10) if it's 10-class classification
# then..
model.fit(x, y)
# Done!

For more examples and detailed usage, refer to the example folder in the GitHub repository.

Why Use Kapre?

Kapre offers significant advantages over traditional audio preprocessing methods:

Versus Pre-computation

  • You can optimize DSP parameters directly within your model training.
  • Model deployment becomes simpler and more consistent, with fewer external dependencies.
  • Your code and model have reduced dependencies.

Versus Your Own Implementation

  • Quick and Easy: Integrate complex audio processing with minimal effort.
  • Consistency: Ensures consistent handling with 1D/2D TensorFlow batch shapes and is data format agnostic (channels_first and channels_last).
  • Less Error Prone: Kapre layers are rigorously tested against established libraries like Librosa, ensuring accuracy in tricky operations like STFT and decibel conversion.
  • Extended APIs: Provides enhanced functionalities beyond default tf.signals implementations, such as a perfectly invertible STFT and InverseSTFT pair, and Mel-spectrogram with more options.
  • Reproducibility: Available on pip with versioning for reliable use.

Links

  • GitHub Repository: https://github.com/keunwoochoi/kapre
  • API Documentation: https://kapre.readthedocs.io
  • Citation: If you use Kapre in your work, please cite the following paper:
    @inproceedings{choi2017kapre,
      title={Kapre: On-GPU Audio Preprocessing Layers for a Quick Implementation of Deep Neural Network Models with Keras},
      author={Choi, Keunwoo and Joo, Deokjin and Kim, Juho},
      booktitle={Machine Learning for Music Discovery Workshop at 34th International Conference on Machine Learning},
      year={2017},
      organization={ICML}
    }
    

Related repositories

Similar repositories that may be relevant next.

A-MEM: Self-Evolving Memory for Coding Agents

A-MEM: Self-Evolving Memory for Coding Agents

August 17, 2026

A-MEM is an innovative self-evolving memory system designed for coding agents, organizing knowledge into a dynamic Zettelkasten-style graph. It allows memories to evolve and connect over time, enhancing an agent's ability to recall and utilize information effectively. This system offers both semantic and structural search capabilities for a richer knowledge base.

PythonAILLM
Agent Sandbox: Secure Local Development for AI Coding Agents

Agent Sandbox: Secure Local Development for AI Coding Agents

August 17, 2026

Agent Sandbox provides a robust and secure local development environment specifically designed for collaborating with AI coding agents. It ensures minimal filesystem access, configurable network egress policies, and secure secret injection, protecting your local machine from potentially risky agent operations. This project supports various AI agents and integrates seamlessly with both CLI and popular IDE devcontainer setups.

agent-harnessagent-sandboxagents
AMD Skills: Empowering AI Agents with AMD's Optimized Software Stack

AMD Skills: Empowering AI Agents with AMD's Optimized Software Stack

August 16, 2026

AMD Skills is the official catalog of AI agent skills from AMD, designed to empower AI agents with optimized software for AMD hardware. This repository provides knowledge, scripts, and conventions for working with AMD's stack, enabling seamless integration with major coding agents like Cursor, Claude Code, OpenAI Codex, and Gemini CLI.

PythonAI AgentsMachine Learning
agent-tackle-box: A Terminal Debugger for LangGraph & LangChain Agents

agent-tackle-box: A Terminal Debugger for LangGraph & LangChain Agents

August 15, 2026

agent-tackle-box is a comprehensive toolkit for developing AI agents, featuring the powerful `agent-debugger`. This terminal debugger provides deep insights into LangGraph and LangChain agents. It allows developers to inspect state, monitor tool calls, and step through Python code, all within a unified Textual UI.

agent-debuggerai-agentslangchain

Source repository

Open the original repository on GitHub.

19 counted GitHub visits

View on GitHub
OS
OSRepos

Analysis and discovery of open source repositories. Find interesting projects and follow their updates.

Monitor your website with YourWebsiteScore

OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of third-party repository code is at your own risk. Always review source code, dependencies, licenses, and security implications before running anything.

© 2025 OSRepos. Built with Nuxt 3 and lots of ❤️