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)

Metadata

Release files for hear 0.1.21

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

Source distribution (sdist)

Source distribution for hear 0.1.21
File Size Uploaded
hear-0.1.21.tar.gz 30.2 kB Details

Built distribution (wheel)

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

Total release size: 57.6 kB

Release files / hear-0.1.21.tar.gz

Download URL hear-0.1.21.tar.gz
Size 30.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d19ae9d8652188521be2be19d4ba1931a0f8f2f34a0bd1db6ea86d99156ba444
BLAKE2b-256 checksum
How to use checksums
bfd2b70b206c0abd8bc5bf43232d888c94e2db09dfc8e7c32b530d837d089854
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / hear-0.1.21-py3-none-any.whl

Download URL hear-0.1.21-py3-none-any.whl
Size 27.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3355b2677b1a95568519d4bccb11e2497cd6af14fe8fd55bfe2ebd167f534548
BLAKE2b-256 checksum
How to use checksums
4936ba9b96f25bf53797c4dbbe52a71a76078bf1257221f3355495b6b11e8366
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release history Release notifications | RSS feed

This release

0.1.21 This release

2 release files

0.1.20

1 release file

0.1.19

1 release file

0.1.18

1 release file

0.1.17

1 release file

0.1.16

1 release file

0.1.15

1 release file

0.1.14

1 release file

0.1.13

1 release file

0.1.12

1 release file

0.1.11

1 release file

0.1.10

1 release file

0.1.9

1 release file

0.1.8

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release 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