Skip to main content

hear

Easy access to audio data.

To install: pip install hear

Examples

A wav serialization/deserialization transformer.

First let's make a very short waveform.

>>> from hear import WavSerializationTrans
>>> from numpy import sin, arange, pi
>>> n_samples = 5; sr = 44100;
>>> wf = sin(arange(n_samples) * 2 * pi * 440 / sr)
>>> wf
array([0.        , 0.06264832, 0.12505052, 0.18696144, 0.24813785])

An instance of WavSerializationTrans will allow you to

>>> trans = WavSerializationTrans(assert_sr=sr)  # if you want to write data you NEED to specify assert_sr
>>> wav_bytes = trans._data_of_obj(wf)
>>> wav_bytes[:44]  # the header bytes
b'RIFF.\x00\x00\x00WAVEfmt \x10\x00\x00\x00\x01\x00\x01\x00D\xac\x00\x00\x88X\x01\x00\x02\x00\x10\x00data\n\x00\x00\x00'
>>> wav_bytes[44:]  # the data bytes (5 * 2 = 10 bytes)
b'\x00\x00\x04\x08\x01\x10\xee\x17\xc2\x1f'

>>> wf_read_from_bytes = trans._obj_of_data(wav_bytes)
>>> wf_read_from_bytes
array([   0, 2052, 4097, 6126, 8130], dtype=int16)

Note that we've serialized floats, but they were deserialized as int16. This is the default behavior, but is cusomizable through dtype, subtype, etc. With this default dtype=int16 setting though, if you serialize int16 arrays, you'll recover them exactly.

>>> assert all(trans._obj_of_data(trans._data_of_obj(wf_read_from_bytes)) == wf_read_from_bytes)

The most common use of WavSerializationTrans through, is to make a class decorator for a store that provides wav bytes.

>>> @WavSerializationTrans.wrapper(assert_sr=sr)
... class MyWavStore(dict):
...     pass
>>> my_wav_store = MyWavStore(just_one=wav_bytes)
>>> my_wav_store['just_one']
array([   0, 2052, 4097, 6126, 8130], dtype=int16)

Download files

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

Source Distribution

hear-0.1.21.tar.gz (30.2 kB view details)

Uploaded Source

Built Distribution

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

hear-0.1.21-py3-none-any.whl (27.4 kB view details)

Uploaded Python 3

File details

Details for the file hear-0.1.21.tar.gz.

File metadata

  • Download URL: hear-0.1.21.tar.gz
  • Upload date:
  • Size: 30.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for hear-0.1.21.tar.gz
Algorithm Hash digest
SHA256 d19ae9d8652188521be2be19d4ba1931a0f8f2f34a0bd1db6ea86d99156ba444
MD5 4f6512cf6e2ed24f9984a0b2c379c9d5
BLAKE2b-256 bfd2b70b206c0abd8bc5bf43232d888c94e2db09dfc8e7c32b530d837d089854

See more details on using hashes here.

File details

Details for the file hear-0.1.21-py3-none-any.whl.

File metadata

  • Download URL: hear-0.1.21-py3-none-any.whl
  • Upload date:
  • Size: 27.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for hear-0.1.21-py3-none-any.whl
Algorithm Hash digest
SHA256 3355b2677b1a95568519d4bccb11e2497cd6af14fe8fd55bfe2ebd167f534548
MD5 aceb0c94c0cc80ca42abd55a2fc7c4b8
BLAKE2b-256 4936ba9b96f25bf53797c4dbbe52a71a76078bf1257221f3355495b6b11e8366

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.21 This release

2 files

0.1.20

1 file

0.1.19

1 file

0.1.18

1 file

0.1.17

1 file

0.1.16

1 file

0.1.15

1 file

0.1.14

1 file

0.1.13

1 file

0.1.12

1 file

0.1.11

1 file

0.1.10

1 file

0.1.9

1 file

0.1.8

1 file

0.1.7

1 file

0.1.6

1 file

0.1.5

1 file

0.1.4

1 file

0.1.3

1 file

0.1.2

1 file

0.1.1

1 file

0.1.0

1 file

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

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