Skip to main content

DreamSound

DreamSound is a python package for sonic deep dream generation.

Description

Inspired by the DeepDream project, DreamSound plays a sound file to Yamnet, a pre-trained neural network, and Yamnet returns a dreamed sound.

Internally, DreamSound takes the gradients of a class from the pre-trained yamnet model and filters them with an original sound with some combination technique.

Example

Head to this Google Colab for a quick example on how to get started with the module. An old version can be accessible in this other Google Colab. Yet an older version is here, which goes hand in hand with an early paper we did on the matter of Convolutional Neural Network Activation Layer Sonification, or what we called DreamSound.

Install

Dreamsound depends on the following pip packages you can pip install:

requests
numpy
matplotlib
IPython
librosa
tensorflow
soundfile

First, install the dependencies

python3 -m pip install -r requirements.txt

Install the dreamsound package using pip:

python3 -m pip install dreamsound

The pip project is hosted at PyPi: https://pypi.org/project/dreamsound/

NOTE: you need to download the yamnet model before importing the dreamsound module. Please, continue reading.

Prepare

Create a directory for your project and relocate there.

mkdir dream_test
cd dream_test

Run the Yamnet Downloader.

The Yamnet Downloader file does not come with the pip distribution. However, it is distributed on this repository. If you do not want to clone this repository, simply do: curl -O https://raw.githubusercontent.com/fdch/dreamsound/main/yamnet_downloader.py on this same directory, and run:

python3 yamnet_downloader.py

Alternatively, you can get Yamnet yourself, crudely like this:

git clone https://github.com/fdch/models.git models
mv models/research/audioset/yamnet/* .
rm -rf models
curl -O https://storage.googleapis.com/audioset/yamnet.h5

Usage example

You must have the yamnet model on the same directory. Now, you can import the dreamsound module and use the class. This code loads some files from disk and passes them to the DreamSound class from the dreamsound module. This looks something like this:

>>> import dreamsound
INFO:tensorflow:Enabling eager execution
INFO:tensorflow:Enabling v2 tensorshape
INFO:tensorflow:Enabling resource variables
INFO:tensorflow:Enabling tensor equality
INFO:tensorflow:Enabling control flow v2
>>> ds = dreamsound.DreamSound(["../audio/original.wav", "../audio/cat.wav"])
Loading audio files...
Done.
I have now 2 audio files in memory.
Using last layer.
Yamnet loaded, using layer:activation_1
Dreamer started.

Filtering

There are two types of filtering, auto or targetted:

Auto Filtering:

Filter the first audio with it's dreamed self

>>> ds(audio_index=0)
Running step 0, class: Whistling...
...
Writing ./audio/Whistle-9-orig.wav...
Writing ./audio/Whistle-9-diff.wav...
Writing ./audio/Whistle-9-filt.wav...
Writing ./audio/Whistle-9-hard.wav...
Writing ./audio/Whistle-9-grad.wav...

Targetted Filtering:

Filter the first with a dreamed target

>>> ds(audio_index=0, tgt=1)
Target class: Animal...
Running step 0, class: Whistling...
Running step 1, class: Whistle...
Running step 2, class: Whistle...
Running step 3, class: Whistle...
Running step 4, class: Whistle...
Running step 5, class: Whistle...
Running step 6, class: Whistle...
Running step 7, class: Whistle...
Running step 8, class: Flute...
Running step 9, class: Whistle...
Writing ./audio/Whistle-9-orig-tgt-Animal.wav...
Writing ./audio/Whistle-9-diff-tgt-Animal.wav...
Writing ./audio/Whistle-9-filt-tgt-Animal.wav...
Writing ./audio/Whistle-9-hard-tgt-Animal.wav...
Writing ./audio/Whistle-9-grad-tgt-Animal.wav...

Recurse

Finally, you can pass no arguments to continue filtering recursively

>>> ds()
Target class: Animal...
Running step 10, class: Whistle...
Running step 11, class: Whistle...
Running step 12, class: Wind instrument, woodwind instrument...
Running step 13, class: Wind instrument, woodwind instrument...
Running step 14, class: Flute...
Running step 15, class: Flute...
Running step 16, class: Wind instrument, woodwind instrument...
Running step 17, class: Whistle...
Running step 18, class: Whistle...
Running step 19, class: Music...
Writing ./audio/Music-19-orig-tgt-Animal.wav...
Writing ./audio/Music-19-diff-tgt-Animal.wav...
Writing ./audio/Music-19-filt-tgt-Animal.wav...
Writing ./audio/Music-19-hard-tgt-Animal.wav...
Writing ./audio/Music-19-grad-tgt-Animal.wav...

Class Variables

You can change any of the following before or after calling the class:

sr          = 22050
max_dur     = 10
patch_hop   = 0.1
win_length  = 2048
hop_length  = 128
pad_end     = False
loss_power  = 0.001
plot_every  = 10
figsize     = (10,8)
top_db      = 80.0
step_size   = 0.95
output_type = 3
steps       = 10
threshold   = 1e-07
classid     = None
maxloss     = True
elapsed     = 0
recurse     = False
target      = None
power       = 1.0
audio_dir   = "./audio/"
image_dir   = "./image/"

Authors

Fede Camara Halac (https://github.com/fdch) Matias Delgadino (https://github.com/zaytam)

Acknowledgements

YamNet AudioSet

Metadata

Release files for dreamsound 0.1.6.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dreamsound 0.1.6.3
File Size Uploaded Provenance
dreamsound-0.1.6.3.tar.gz 18.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for dreamsound 0.1.6.3
File Interpreter ABI Platform
dreamsound-0.1.6.3-py3-none-any.whl Python 3 none any Details

Total release size: 35.8 kB

Release files / dreamsound-0.1.6.3.tar.gz

Download URL dreamsound-0.1.6.3.tar.gz
Size 18.4 kB
Tags Source
SHA-256 checksum
How to use checksums
991d115da253dfc095db87456866fb90b7cc1a7838a8a5e1d6a9325abdfdef58
BLAKE2b-256 checksum
How to use checksums
5b59409d4bd712b46e9bf0b683e0c0240cb5f0fc850e224cac4f3519ef078383
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

Release files / dreamsound-0.1.6.3-py3-none-any.whl

Download URL dreamsound-0.1.6.3-py3-none-any.whl
Size 17.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f91123ec78487a9dcf39079287299f729923d10a8e7fd3ef4b3f943438ce0e6d
BLAKE2b-256 checksum
How to use checksums
fe26df11fbb36d6b2476d77ba73ec204bc8e6550bb8bedc10e2a2bc1e55de703
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

Security for dreamsound 0.1.6.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page