Skip to main content

A simple framework for room acoustics and audio processing in Python.

Project description

Pyroomacoustics logo
Documentation Status Test on mybinder Pyroomacoustics discord server

Summary

Pyroomacoustics is a software package aimed at the rapid development and testing of audio array processing algorithms. The content of the package can be divided into three main components:

  1. Intuitive Python object-oriented interface to quickly construct different simulation scenarios involving multiple sound sources and microphones in 2D and 3D rooms;

  2. Fast C++ implementation of the image source model and ray tracing for general polyhedral rooms to efficiently generate room impulse responses and simulate the propagation between sources and receivers;

  3. Reference implementations of popular algorithms for STFT, beamforming, direction finding, adaptive filtering, source separation, and single channel denoising.

Together, these components form a package with the potential to speed up the time to market of new algorithms by significantly reducing the implementation overhead in the performance evaluation step. Please refer to this notebook for a demonstration of the different components of this package.

Room Acoustics Simulation

Consider the following scenario.

Suppose, for example, you wanted to produce a radio crime drama, and it so happens that, according to the scriptwriter, the story line absolutely must culminate in a satanic mass that quickly degenerates into a violent shootout, all taking place right around the altar of the highly reverberant acoustic environment of Oxford’s Christ Church cathedral. To ensure that it sounds authentic, you asked the Dean of Christ Church for permission to record the final scene inside the cathedral, but somehow he fails to be convinced of the artistic merit of your production, and declines to give you permission. But recorded in a conventional studio, the scene sounds flat. So what do you do?

—Schnupp, Nelken, and King, Auditory Neuroscience, 2010

Faced with this difficult situation, pyroomacoustics can save the day by simulating the environment of the Christ Church cathedral!

At the core of the package is a room impulse response (RIR) generator based on the image source model that can handle

  • Convex and non-convex rooms

  • 2D/3D rooms

The core image source model and ray tracing modules are written in C++ for better performance.

The philosophy of the package is to abstract all necessary elements of an experiment using an object-oriented programming approach. Each of these elements is represented using a class and an experiment can be designed by combining these elements just as one would do in a real experiment.

Let’s imagine we want to simulate a delay-and-sum beamformer that uses a linear array with four microphones in a shoe box shaped room that contains only one source of sound. First, we create a room object, to which we add a microphone array object, and a sound source object. Then, the room object has methods to compute the RIR between source and receiver. The beamformer object then extends the microphone array class and has different methods to compute the weights, for example delay-and-sum weights. See the example below to get an idea of what the code looks like.

The Room class also allows one to process sound samples emitted by sources, effectively simulating the propagation of sound between sources and microphones. At the input of the microphones composing the beamformer, an STFT (short time Fourier transform) engine allows to quickly process the signals through the beamformer and evaluate the output.

Reference Implementations

In addition to its core image source model simulation, pyroomacoustics also contains a number of reference implementations of popular audio processing algorithms for

We use an object-oriented approach to abstract the details of specific algorithms, making them easy to compare. Each algorithm can be tuned through optional parameters. We have tried to pre-set values for the tuning parameters so that a run with the default values will in general produce reasonable results.

Datasets

In an effort to simplify the use of datasets, we provide a few wrappers that allow to quickly load and sort through some popular speech corpora. At the moment we support the following.

For more details, see the doc.

Quick Install

Install the package with pip:

pip install pyroomacoustics

A cookiecutter is available that generates a working simulation script for a few 2D/3D scenarios:

# if necessary install cookiecutter
pip install cookiecutter

# create the simulation script
cookiecutter gh:fakufaku/cookiecutter-pyroomacoustics-sim

# run the newly created script
python <chosen_script_name>.py

We have also provided a minimal Dockerfile example in order to install and run the package within a Docker container. Note that you should increase the memory of your containers to 4 GB. Less may also be sufficient, but this is necessary for building the C++ code extension. You can build the container with:

docker build -t pyroom_container .

And enter the container with:

docker run -it pyroom_container:latest /bin/bash

Dependencies

The minimal dependencies are:

numpy
scipy>=0.18.0
Cython
pybind11

where Cython is only needed to benefit from the compiled accelerated simulator. The simulator itself has a pure Python counterpart, so that this requirement could be ignored, but is much slower.

On top of that, some functionalities of the package depend on extra packages:

samplerate   # for resampling signals
matplotlib   # to create graphs and plots
sounddevice  # to play sound samples
mir_eval     # to evaluate performance of source separation in examples

The requirements.txt file lists all packages necessary to run all of the scripts in the examples folder.

This package is mainly developed under Python 3.6. The last supported version for Python 2.7 is 0.4.3.

Under Linux and Mac OS, the compiled accelerators require a valid compiler to be installed, typically this is GCC. When no compiler is present, the package will still install but default to the pure Python implementation which is much slower. On Windows, we provide pre-compiled Python Wheels for Python 3.5 and 3.6.

Example

Here is a quick example of how to create and visualize the response of a beamformer in a room.

import numpy as np
import matplotlib.pyplot as plt
import pyroomacoustics as pra

# Create a 4 by 6 metres shoe box room
room = pra.ShoeBox([4,6])

# Add a source somewhere in the room
room.add_source([2.5, 4.5])

# Create a linear array beamformer with 4 microphones
# with angle 0 degrees and inter mic distance 10 cm
R = pra.linear_2D_array([2, 1.5], 4, 0, 0.1)
room.add_microphone_array(pra.Beamformer(R, room.fs))

# Now compute the delay and sum weights for the beamformer
room.mic_array.rake_delay_and_sum_weights(room.sources[0][:1])

# plot the room and resulting beamformer
room.plot(freq=[1000, 2000, 4000, 8000], img_order=0)
plt.show()

More examples

A couple of detailed demos with illustrations are available.

A comprehensive set of examples covering most of the functionalities of the package can be found in the examples folder of the GitHub repository.

A video introduction to pyroomacoustics.

A video tutorial series on using pyroomacoustics covering many advanced topics.

Authors

  • Robin Scheibler

  • Ivan Dokmanić

  • Sidney Barthe

  • Eric Bezzam

  • Hanjie Pan

How to contribute

If you would like to contribute, please clone the repository and send a pull request.

For more details, see our CONTRIBUTING page.

Academic publications

This package was developed to support academic publications. The package contains implementations for DOA algorithms and acoustic beamformers introduced in the following papers.

  • H. Pan, R. Scheibler, I. Dokmanic, E. Bezzam and M. Vetterli. FRIDA: FRI-based DOA estimation for arbitrary array layout, ICASSP 2017, New Orleans, USA, 2017.

  • I. Dokmanić, R. Scheibler and M. Vetterli. Raking the Cocktail Party, in IEEE Journal of Selected Topics in Signal Processing, vol. 9, num. 5, p. 825 - 836, 2015.

  • R. Scheibler, I. Dokmanić and M. Vetterli. Raking Echoes in the Time Domain, ICASSP 2015, Brisbane, Australia, 2015.

If you use this package in your own research, please cite our paper describing it.

R. Scheibler, E. Bezzam, I. Dokmanić, Pyroomacoustics: A Python package for audio room simulations and array processing algorithms, Proc. IEEE ICASSP, Calgary, CA, 2018.

License

Copyright (c) 2014-2021 EPFL-LCAV

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyroomacoustics-0.7.5.tar.gz (1.1 MB view details)

Uploaded Source

Built Distributions

pyroomacoustics-0.7.5-cp312-cp312-win_amd64.whl (547.0 kB view details)

Uploaded CPython 3.12 Windows x86-64

pyroomacoustics-0.7.5-cp312-cp312-macosx_10_9_universal2.whl (1.1 MB view details)

Uploaded CPython 3.12 macOS 10.9+ universal2 (ARM64, x86-64)

pyroomacoustics-0.7.5-cp311-cp311-win_amd64.whl (545.7 kB view details)

Uploaded CPython 3.11 Windows x86-64

pyroomacoustics-0.7.5-cp311-cp311-macosx_10_9_universal2.whl (1.1 MB view details)

Uploaded CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64)

pyroomacoustics-0.7.5-cp310-cp310-win_amd64.whl (544.8 kB view details)

Uploaded CPython 3.10 Windows x86-64

pyroomacoustics-0.7.5-cp310-cp310-macosx_11_0_x86_64.whl (678.0 kB view details)

Uploaded CPython 3.10 macOS 11.0+ x86-64

pyroomacoustics-0.7.5-cp310-cp310-macosx_10_9_universal2.whl (1.1 MB view details)

Uploaded CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64)

pyroomacoustics-0.7.5-cp39-cp39-win_amd64.whl (545.4 kB view details)

Uploaded CPython 3.9 Windows x86-64

pyroomacoustics-0.7.5-cp39-cp39-macosx_11_0_x86_64.whl (678.8 kB view details)

Uploaded CPython 3.9 macOS 11.0+ x86-64

pyroomacoustics-0.7.5-cp38-cp38-win_amd64.whl (545.3 kB view details)

Uploaded CPython 3.8 Windows x86-64

pyroomacoustics-0.7.5-cp38-cp38-macosx_11_0_x86_64.whl (678.6 kB view details)

Uploaded CPython 3.8 macOS 11.0+ x86-64

File details

Details for the file pyroomacoustics-0.7.5.tar.gz.

File metadata

  • Download URL: pyroomacoustics-0.7.5.tar.gz
  • Upload date:
  • Size: 1.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.14

File hashes

Hashes for pyroomacoustics-0.7.5.tar.gz
Algorithm Hash digest
SHA256 aa654e08b2b8f4c247f7ef459d50b44907d65a8dc39577aedab650823953cb9e
MD5 625f22cc999d1cbd0b00cc4c50b8a890
BLAKE2b-256 aca6708cbdb5ac95fade610e17f86f9e2bdd53eceabe287827026b3f98b9470d

See more details on using hashes here.

File details

Details for the file pyroomacoustics-0.7.5-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for pyroomacoustics-0.7.5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 63df5528d7ed85282cfdbefd63d97c25201c12e1eac40c4101a7118642e93d1b
MD5 486b8a97ef6d7829e7b8a5866edd98d3
BLAKE2b-256 4c586a78adfe6f6aa4a3252ce3abd3d053d26824f404c47287b1d612e6bb5955

See more details on using hashes here.

File details

Details for the file pyroomacoustics-0.7.5-cp312-cp312-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for pyroomacoustics-0.7.5-cp312-cp312-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 e1c384e3d6a85b78fe5e09c40e034b6cae2eb59282ca30d21ad8fba4cccd773c
MD5 7d0fbae744e3126eff5261f3d582ce36
BLAKE2b-256 c2eb77c89f66bff30c765de44a2c3cd365418e9cf65dff9d493eb69f40018683

See more details on using hashes here.

File details

Details for the file pyroomacoustics-0.7.5-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for pyroomacoustics-0.7.5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 4312ad825e37925799c6490c593a5f990198a5c865df296efcadccb38f6e1279
MD5 51bdee6f21dc5d8b50f15690e31a59ed
BLAKE2b-256 3e7080e0cbb4bece21254cf5574ea2d5622e6a06ceb84f4e568948f0c62877e2

See more details on using hashes here.

File details

Details for the file pyroomacoustics-0.7.5-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for pyroomacoustics-0.7.5-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 88bdbce73dddf8bb2be2159a0024040513016bbe11249cfc3275152ac00bd1e6
MD5 deec8ba94045bebaeff60bdb446ac469
BLAKE2b-256 5f958d6908d37de30bbffe7c92bc26d31bca2db69eb1e3cc9b7f4b29cbc5f5ec

See more details on using hashes here.

File details

Details for the file pyroomacoustics-0.7.5-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for pyroomacoustics-0.7.5-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 b136eba766b9cd801c9d9d5ff01623dfb8d57258359228d7bc4be393d14528c4
MD5 d1148f6b09ee49123b4b946f304de55d
BLAKE2b-256 e3b5d3e9e8a5e9ac428cdc4bf26590dbaf16b6be180644fda16bed230fd24a5b

See more details on using hashes here.

File details

Details for the file pyroomacoustics-0.7.5-cp310-cp310-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for pyroomacoustics-0.7.5-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 7fff00f2ac43f67a633308fdf424fa8b1baea01cbc81910d78a97b4b14dbbc68
MD5 fefc2c2df743690dc6cd7c097b26ec60
BLAKE2b-256 19bafe69d6a072476e3d8d2b41a96860b00c9589f2a70dd6cbff991488c6cd7d

See more details on using hashes here.

File details

Details for the file pyroomacoustics-0.7.5-cp310-cp310-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for pyroomacoustics-0.7.5-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 4c4d36dfb1bdcd6b72c3f46ccf0eed87d464a8326774be79ccf77f259ceebbfd
MD5 2b938d98e4a21b67d87ac6cda2008fd8
BLAKE2b-256 72b48af33e286d5e517ce96379b5a1d350a02c3a6053fe83bde7547450775bda

See more details on using hashes here.

File details

Details for the file pyroomacoustics-0.7.5-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for pyroomacoustics-0.7.5-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 088899311f7799f9f9aa01859adb6e1bcad6be1bb6f24ff49628fc9de1efcd74
MD5 0a4763e2082c16f86703445f895d3af9
BLAKE2b-256 cea908bc36a69179a0f4f3d23c7d8ab202891b4a65c04b9c9c7edbd82168bff0

See more details on using hashes here.

File details

Details for the file pyroomacoustics-0.7.5-cp39-cp39-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for pyroomacoustics-0.7.5-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 c4265bb40a5f9923e7f542c1171de60a33e4de70d9e6ba9c27f643e78499fbca
MD5 ba1a792fd5eea59e289a8b57a3ca0eca
BLAKE2b-256 911108495ded8700e8bd2a021e111f9cfa9eedb199e0eafd6d993eb974802764

See more details on using hashes here.

File details

Details for the file pyroomacoustics-0.7.5-cp38-cp38-win_amd64.whl.

File metadata

File hashes

Hashes for pyroomacoustics-0.7.5-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 a6011f80e42ffda754aa10164dc6f0a9f192ede2843016494c1363b0043ac513
MD5 3dfd76879a856a034d922b8c1ac8af0f
BLAKE2b-256 83fb06ba14a3beeccfb8a5a8d023bb70eff7efdc89232c75a794e7d6407ca8e6

See more details on using hashes here.

File details

Details for the file pyroomacoustics-0.7.5-cp38-cp38-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for pyroomacoustics-0.7.5-cp38-cp38-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 a81ad786468ab8cd51fd0a7adf4d520f6e9ac033dff11519d459ef39f3dca3d9
MD5 6df3345a9403fe230dd557088cbef2ad
BLAKE2b-256 d3aa42b7744cdbddbe4b6bd877130797645ea878c2b25a73ff2b90233254b631

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page