Skip to main content

Generator based tools for working with audio clips.

Project description

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

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.util.mixer(
        (audiogen.tone(440), audiogen.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.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.sampler.write_wav(sys.stdout, audiogen.tone(440))

Or just:

audiogen.sampler.play(audiogen.tone(440))

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

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

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

Soundcard output

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

import audiogen
import itertools
import sys

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

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

import audiogen
import itertools
import sys

audiogen.sampler.write_wav(
    sys.stdout,
    itertools.cycle(itertools.chain(audiogen.beep(), audiogen.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
$ pip install --allow-external PyAudio --allow-unverified PyAudio PyAudio

PyAudio is optional. If it’s not installed, playing audio via the soundcard with audiogen.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

See also

Projects built with audiogen:

  • koch, a Koch method Morse code trainer and audio generator

  • afsk, a ham radio APRS/Bell-202 audio frequency shift keying encoder

Contributing

Get the source and report any bugs on Github:

https://github.com/casebeer/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-0.2.0.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

audiogen-0.2.0-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

Details for the file audiogen-0.2.0.tar.gz.

File metadata

  • Download URL: audiogen-0.2.0.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for audiogen-0.2.0.tar.gz
Algorithm Hash digest
SHA256 0f9f29d469c010f9be3190d6c79591c3d0e1c80d14a6e4b51c48777583df24db
MD5 5d6b18db0cea43bca969e5035e026604
BLAKE2b-256 012e6fe8ad8f0a3b3c06f14873a8018db7117effaa5d418447b63053da3d27cb

See more details on using hashes here.

File details

Details for the file audiogen-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: audiogen-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 16.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for audiogen-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8839d381b2b4342a8347366000bb547b7d65d58a064787d7cf239b4d0f776ffb
MD5 671618670bde5bf54d2b77699397d1a4
BLAKE2b-256 be039d046900de775869769ae7df5f89982938567cbe648fec5ee3e9f1ea4fa7

See more details on using hashes here.

Supported by

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