{"id":15358872,"url":"https://github.com/warrenweckesser/wavio","last_synced_at":"2025-05-16T04:03:43.686Z","repository":{"id":24451187,"uuid":"27853698","full_name":"WarrenWeckesser/wavio","owner":"WarrenWeckesser","description":"A Python module for reading and writing WAV files using numpy arrays.","archived":false,"fork":false,"pushed_at":"2025-04-23T19:21:27.000Z","size":97,"stargazers_count":134,"open_issues_count":2,"forks_count":20,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-05-16T04:03:40.770Z","etag":null,"topics":["numpy","python","wav"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WarrenWeckesser.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2014-12-11T04:14:59.000Z","updated_at":"2025-04-23T19:21:31.000Z","dependencies_parsed_at":"2023-01-17T00:01:03.367Z","dependency_job_id":"d8376e4b-d350-4275-bb7b-ba345acc47b2","html_url":"https://github.com/WarrenWeckesser/wavio","commit_stats":{"total_commits":84,"total_committers":3,"mean_commits":28.0,"dds":0.04761904761904767,"last_synced_commit":"5bd0dabccbde5578fca00cc388f12fd7b9b0b1b9"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WarrenWeckesser%2Fwavio","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WarrenWeckesser%2Fwavio/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WarrenWeckesser%2Fwavio/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WarrenWeckesser%2Fwavio/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WarrenWeckesser","download_url":"https://codeload.github.com/WarrenWeckesser/wavio/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254464891,"owners_count":22075570,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["numpy","python","wav"],"created_at":"2024-10-01T12:43:16.539Z","updated_at":"2025-05-16T04:03:43.669Z","avatar_url":"https://github.com/WarrenWeckesser.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"wavio\n=====\n\n``wavio`` is a Python module that defines two functions:\n\n* ``wavio.read`` reads a WAV file and returns an object that holds the\n  sampling rate, sample width (in bytes), and a numpy array containing the\n  data.\n* ``wavio.write`` writes a numpy array to a WAV file, optionally using a\n  specified sample width.\n\nThe functions can read and write 8-, 16-, 24- and 32-bit integer WAV files.\n\nThe module uses the ``wave`` module in Python's standard library, so it has\nthe same limitations as that module.  In particular, the ``wave`` module\ndoes not support compressed WAV files, and it does not handle floating\npoint WAV files.  When floating point data is passed to ``wavio.write`` it\nis converted to integers before being written to the WAV file.\n\n``wavio`` requires Python 3.10 or later.\n\n``wavio`` depends on numpy (http://www.numpy.org).  NumPy version 1.21.3 or\nlater is required.    The unit tests in ``wavio`` require ``pytest``.\n\nThe API of the functions in ``wavio`` should not be considered stable.  There\nmay be backwards-incompatible API changes between releases.\n\nThe latest release of ``wavio`` is available on PyPI:\nhttps://pypi.org/project/wavio/\n\n*Important notice*\n\nIn version 0.0.5, the data handling in ``wavio.write`` has been changed in\na backwards-incompatible way.  The API for scaling the input in 0.0.4 was\na flexible interface that only its creator could love.  The new API is\nsimpler, and it is hoped that it does the right thing by default in\nmost cases.  In particular:\n\n* When the input data is an integer type, the values are not scaled or\n  shifted.  The only change that might happen is the data will be clipped\n  if the values do not fit in the output integer type.\n* If the input data is a floating point type, ``sampwidth`` must be given.\n  The default behavior is to scale input values in the range [-1.0, 1.0]\n  to the output range [min_int+1, max_int], where min_int and max_int are\n  the minimum and maximum values of the output data type determined by\n  ``sampwidth``.  See the description of ``scale`` in the docstring of\n  ``wavio.write`` for more options.  Regardless of the value of ``scale``,\n  the float input 0.0 is always mapped to the midpoint of the output type;\n  ``wavio.write`` will not translate the values up or down.\n* A warning is now generated if any data values are clipped.  A parameter\n  allows the generation of the warning to be disabled or converted to an\n  exception.\n\nExamples\n--------\n\nThe following examples are also found in the docstring of ``wavio.write``.\n\nCreate a 3 second 440 Hz sine wave, and save it in a 24-bit WAV file.\n\n    \u003e\u003e\u003e import numpy as np\n    \u003e\u003e\u003e import wavio\n\n    \u003e\u003e\u003e rate = 22050           # samples per second\n    \u003e\u003e\u003e T = 3                  # sample duration (seconds)\n    \u003e\u003e\u003e n = int(rate*T)        # number of samples\n    \u003e\u003e\u003e t = np.arange(n)/rate  # grid of time values\n\n    \u003e\u003e\u003e f = 440.0              # sound frequency (Hz)\n    \u003e\u003e\u003e x = np.sin(2*np.pi * f * t)\n\n`x` is a single sine wave with amplitude 1, so we can use the default\n`scale`.\n\n    \u003e\u003e\u003e wavio.write(\"sine24.wav\", x, rate, sampwidth=3)\n\nCreate a file that contains the 16 bit integer values -10000 and 10000\nrepeated 100 times.  Use a sample rate of 8000.\n\n    \u003e\u003e\u003e x = np.empty(200, dtype=np.int16)\n    \u003e\u003e\u003e x[::2] = -10000\n    \u003e\u003e\u003e x[1::2] = 10000\n    \u003e\u003e\u003e wavio.write(\"foo.wav\", x, 8000)\n\nCheck that the file contains what we expect.  The values are checked\nfor exact equality.  The input was an integer array, so the values are\nnot scaled.\n\n    \u003e\u003e\u003e w = wavio.read(\"foo.wav\")\n    \u003e\u003e\u003e np.all(w.data[:, 0] == x)\n    True\n\nWrite floating point data to a 16 bit WAV file.  The floating point\nvalues are assumed to be within the range [-2, 2], and we want the\nvalues 2 and -2 to correspond to the full output range, even if the\nactual values in the data do not fill this range.  We do that by\nspecifying `scale=2`.\n\n`T`, `rate` and `t` are from above.  The data is the sum of two\nsinusoids, with frequencies 440 and 880 Hz, modulated by a parabolic\ncurve that is zero at the start and end of the data.\n\n    \u003e\u003e\u003e envelope = (4/T**2)*(t * (T - t))\n    \u003e\u003e\u003e omega1 = 2*np.pi*440\n    \u003e\u003e\u003e omega2 = 2*np.pi*880\n    \u003e\u003e\u003e y = envelope*(np.sin(omega1*t) + 0.3*np.sin(omega2*t + 0.2))\n    \u003e\u003e\u003e y.min(), y.max()\n    (-1.1745469775555515, 1.093833464065767)\n\nWrite the WAV file, with `scale=2`.\n\n    \u003e\u003e\u003e wavio.write('harmonic.wav', y, rate, sampwidth=2, scale=2)\n\nCheck the minimum and maximum integers that were actually written\nto the file:\n\n    \u003e\u003e\u003e w = wavio.read(\"harmonic.wav\")\n    \u003e\u003e\u003e w.data.min(), w.data.max()\n    (-19243, 17921)\n\nIf we want the WAV file to use as much of the range of the output\ninteger type as possible (while still mapping 0.0 in the input to 0 in\nthe output), we set `scale=\"auto\"`.\n\n    \u003e\u003e\u003e wavio.write('harmonic_full.wav', y, rate, sampwidth=2, scale=\"auto\")\n\n    \u003e\u003e\u003e w = wavio.read('harmonic_full.wav')\n    \u003e\u003e\u003e w.data.min(), w.data.max()\n    (-32768, 30517)\n\n-----\n\nAuthor:     Warren Weckesser\n\nRepository: https://github.com/WarrenWeckesser/wavio\n\nLicense:    BSD 2-clause (http://opensource.org/licenses/BSD-2-Clause)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwarrenweckesser%2Fwavio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwarrenweckesser%2Fwavio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwarrenweckesser%2Fwavio/lists"}