Skip to main content

Generator based tools for working with audio clips.

Project description

The audiogen_p3 package provides time domain audio processing tools using Python generators.

Please note, this is a forked repository from “audiogen” by user “casebeer” updated to work with Python3 since the original package has been unmaintained for a few years. The only modifications to this package were to allow use in Python 3. The remainder of the code is all original work by Christopher H. Casebeer

This makes some types of audio sample generation and processing pretty easy:

# mix 440 Hz and 445 Hz tones to get 5 Hz beating
beats = audiogen_p3.mixer(
    (audiogen_p3.tone(440), audiogen_p3.tone(445)),
    [(constant(1), constant(1)),]
)

The actual samples won’t be generated or stored in memory until they’re actually consumed – for instance, when they’re being written out to disk in a wave file:

with open("output.wav", "wb") as f:
    audiogen_p3.sampler.write_wav(f, beats)

Generators’ at-consumption-time computation also allows creating infinitely long output, e.g. to stream to speakers rather than a file on disk:

audiogen_p3.sampler.write_wav(sys.stdout, audiogen_p3.tone(440))

Or just:

audiogen_p3.sampler.play(audiogen_p3.tone(440))

You can also use standard generator tools, e.g. the itertools module, to handle audio data:

beep_silence = itertools.chain(audiogen_p3.beep(), audiogen_p3.silence(0.5))
infinite_beeps = itertools.cycle(beep_silence)

audiogen_p3.sampler.write_wav(sys.stdout, infinite_beeps)

Soundcard output

The easiest way to play directly to a soundcard output is to use the audiogen_p3.sampler.play function, which will play your samples using PyAudio:

import audiogen_p3
import itertools
import sys

audiogen_p3.sampler.play(
    itertools.cycle(itertools.chain(audiogen_p3.beep(), audiogen_p3.silence(0.5)))
)

Alternatively, you could write your wave data to stdout, e.g. myaudio.py:

import audiogen_p3
import itertools
import sys

audiogen_p3.sampler.write_wav(
    sys.stdout,
    itertools.cycle(itertools.chain(audiogen_p3.beep(), audiogen_p3.silence(0.5)))
)

Then pipe to a command line audio player like Sox:

python myaudio.py | play -t wav -

Installation

Install with:

$ pip install audiogen_p3
$ pip install --allow-external PyAudio --allow-unverified PyAudio PyAudio

PyAudio is optional. If it’s not installed, playing audio via the soundcard with audiogen_p3.sampler.play() will not be available, but generating Wave files – including for piping to an external player, like sox – will work just fine.

Note that to install PyAudio on Mac OS X, you’ll need to first install portaudio:

$ brew install portaudio

Contributing

Get the source and report any bugs on Github:

https://github.com/rguisewite/audiogen_p3

Original Code from Christopher H. Casebeer (casebeer):

https://github.com/rguisewite/audiogen

Version history

  • 0.1.2 - Add band pass and band stop IIR filters; custom beep lengths from @jhobbs

  • 0.1.1 - Fix multiplexing bug causing increase in pitch when using mixer() to produce more than one output channel

  • 0.1.0 - Breaking changes: new arguments to tone(), play() blocks by default

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

audiogen_p3-0.0.1.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

audiogen_p3-0.0.1-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file audiogen_p3-0.0.1.tar.gz.

File metadata

  • Download URL: audiogen_p3-0.0.1.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.2

File hashes

Hashes for audiogen_p3-0.0.1.tar.gz
Algorithm Hash digest
SHA256 7bd642f8ce9bce6acd6ca4b287735b10c5a54fbf2dbfdd1ab8ae81ae8a0f0857
MD5 1347a53059b19d51e0c8efe90aa53340
BLAKE2b-256 2aa3535cd85f00c7c6d57036b1bd072b1f15df0f4e812b4adbf15987b8283af1

See more details on using hashes here.

File details

Details for the file audiogen_p3-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: audiogen_p3-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 13.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.2

File hashes

Hashes for audiogen_p3-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 961cb38a6ee3d4edd1f4a7fff8d6b17050950b094e8a95b8ae6c28e29152c219
MD5 f1c665558e3a330cb1e4556452fddf6d
BLAKE2b-256 8d882bbbe4df949c5c05f2dae867161e96dd814950efb140210d46d799a94e29

See more details on using hashes here.

Supported by

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