sox


Namesox JSON
Version 1.4.1 PyPI version JSON
download
home_pagehttps://github.com/rabitt/pysox
SummaryPython wrapper around SoX.
upload_time2020-09-30 01:20:26
maintainer
docs_urlNone
authorRachel Bittner
requires_python
licenseBSD-3-Clause
keywords audio effects sox
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pysox
Python wrapper around sox. [Read the Docs here](http://pysox.readthedocs.org).

[![PyPI version](https://badge.fury.io/py/sox.svg)](https://badge.fury.io/py/sox)
[![Documentation Status](https://readthedocs.org/projects/resampy/badge/?version=latest)](http://pysox.readthedocs.io/en/latest/?badge=latest)
[![GitHub license](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://raw.githubusercontent.com/rabitt/pysox/master/LICENSE.md)
[![PyPI](https://img.shields.io/pypi/pyversions/Django.svg?maxAge=2592000)]()

[![Build Status](https://travis-ci.org/rabitt/pysox.svg?branch=master)](https://travis-ci.org/rabitt/pysox)
[![Coverage Status](https://coveralls.io/repos/github/rabitt/pysox/badge.svg?branch=master)](https://coveralls.io/github/rabitt/pysox?branch=master)

![PySocks](https://s-media-cache-ak0.pinimg.com/736x/62/6f/bc/626fbcae9618eccee1c4c7c947bf9d94.jpg)

This library was presented in the following paper:

[R. M. Bittner](https://github.com/rabitt), [E. J. Humphrey](https://github.com/ejhumphrey) and J. P. Bello, "[pysox: Leveraging the Audio Signal Processing Power of SoX in Python](https://wp.nyu.edu/ismir2016/wp-content/uploads/sites/2294/2016/08/bittner-pysox.pdf)", in Proceedings of the 17th International Society for Music Information Retrieval Conference Late Breaking and Demo Papers, New York City, USA, Aug. 2016.


# Install

This requires that [SoX](http://sox.sourceforge.net/) version 14.4.2 or higher is installed.

To install SoX on Mac with Homebrew:

```brew install sox```

If you want support for `mp3`, `flac`, or `ogg` files, add the following flags:

```brew install sox --with-lame --with-flac --with-libvorbis```

on Linux:

```apt-get install sox```

or install [from source](https://sourceforge.net/projects/sox/files/sox/).



To install the most up-to-date release of this module via PyPi:

```pip install sox```

To install the master branch:

```pip install git+https://github.com/rabitt/pysox.git```

or

```
git clone https://github.com/rabitt/pysox.git
cd pysox
python setup.py install
```


# Tests

If you have a different version of SoX installed, it's recommended that you run
the tests locally to make sure everything behaves as expected, by simply running:

```
pytest
```

# Examples

```python
import sox
# create transformer
tfm = sox.Transformer()
# trim the audio between 5 and 10.5 seconds.
tfm.trim(5, 10.5)
# apply compression
tfm.compand()
# apply a fade in and fade out
tfm.fade(fade_in_len=1.0, fade_out_len=0.5)
# create an output file.
tfm.build_file('path/to/input_audio.wav', 'path/to/output/audio.aiff')
# or equivalently using the legacy API
tfm.build('path/to/input_audio.wav', 'path/to/output/audio.aiff')
# get the output in-memory as a numpy array
# by default the sample rate will be the same as the input file
array_out = tfm.build_array(input_filepath='path/to/input_audio.wav')
# see the applied effects
tfm.effects_log
> ['trim', 'compand', 'fade']

```

Transform in-memory arrays:
```python
import numpy
import sox
# sample rate in Hz
sample_rate = 44100
# generate a 1-second sine tone at 440 Hz
y = np.sin(2 * np.pi * 440.0 * np.arange(sample_rate * 1.0) / sample_rate)
# create a transformer
tfm = sox.Transformer()
# shift the pitch up by 2 semitones
tfm.pitch(2)
# transform an in-memory array and return an array
y_out = tfm.build_array(input_array=y, sample_rate_in=sample_rate)
# instead, save output to a file
tfm.build_file(
    input_array=y, sample_rate_in=sample_rate,
    output_filepath='path/to/output.wav'
)
# create an output file with a different sample rate
tfm.set_output_format(rate=8000)
tfm.build_file(
    input_array=y, sample_rate_in=sample_rate,
    output_filepath='path/to/output_8k.wav'
)
```

Concatenate 3 audio files:
```python
import sox
# create combiner
cbn = sox.Combiner()
# pitch shift combined audio up 3 semitones
cbn.pitch(3.0)
# convert output to 8000 Hz stereo
cbn.convert(samplerate=8000, n_channels=2)
# create the output file
cbn.build(
    ['input1.wav', 'input2.wav', 'input3.wav'], 'output.wav', 'concatenate'
)
# the combiner does not currently support array input/output
```

Get file information:
```python
import sox
# get the sample rate
sample_rate = sox.file_info.sample_rate('path/to/file.mp3')
# get the number of samples
n_samples = sox.file_info.num_samples('path/to/file.wav')
# determine if a file is silent
is_silent = sox.file_info.silent('path/to/file.aiff')
# file info doesn't currently support array input
```



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/rabitt/pysox",
    "name": "sox",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "audio effects SoX",
    "author": "Rachel Bittner",
    "author_email": "rachel.bittner@nyu.edu",
    "download_url": "https://files.pythonhosted.org/packages/5b/53/0de2626feb9d3d43ae56c42c35e8048daf09de7ea1124657ef8834582ca0/sox-1.4.1.tar.gz",
    "platform": "",
    "description": "# pysox\nPython wrapper around sox. [Read the Docs here](http://pysox.readthedocs.org).\n\n[![PyPI version](https://badge.fury.io/py/sox.svg)](https://badge.fury.io/py/sox)\n[![Documentation Status](https://readthedocs.org/projects/resampy/badge/?version=latest)](http://pysox.readthedocs.io/en/latest/?badge=latest)\n[![GitHub license](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://raw.githubusercontent.com/rabitt/pysox/master/LICENSE.md)\n[![PyPI](https://img.shields.io/pypi/pyversions/Django.svg?maxAge=2592000)]()\n\n[![Build Status](https://travis-ci.org/rabitt/pysox.svg?branch=master)](https://travis-ci.org/rabitt/pysox)\n[![Coverage Status](https://coveralls.io/repos/github/rabitt/pysox/badge.svg?branch=master)](https://coveralls.io/github/rabitt/pysox?branch=master)\n\n![PySocks](https://s-media-cache-ak0.pinimg.com/736x/62/6f/bc/626fbcae9618eccee1c4c7c947bf9d94.jpg)\n\nThis library was presented in the following paper:\n\n[R. M. Bittner](https://github.com/rabitt), [E. J. Humphrey](https://github.com/ejhumphrey) and J. P. Bello, \"[pysox: Leveraging the Audio Signal Processing Power of SoX in Python](https://wp.nyu.edu/ismir2016/wp-content/uploads/sites/2294/2016/08/bittner-pysox.pdf)\", in Proceedings of the 17th International Society for Music Information Retrieval Conference Late Breaking and Demo Papers, New York City, USA, Aug. 2016.\n\n\n# Install\n\nThis requires that [SoX](http://sox.sourceforge.net/) version 14.4.2 or higher is installed.\n\nTo install SoX on Mac with Homebrew:\n\n```brew install sox```\n\nIf you want support for `mp3`, `flac`, or `ogg` files, add the following flags:\n\n```brew install sox --with-lame --with-flac --with-libvorbis```\n\non Linux:\n\n```apt-get install sox```\n\nor install [from source](https://sourceforge.net/projects/sox/files/sox/).\n\n\n\nTo install the most up-to-date release of this module via PyPi:\n\n```pip install sox```\n\nTo install the master branch:\n\n```pip install git+https://github.com/rabitt/pysox.git```\n\nor\n\n```\ngit clone https://github.com/rabitt/pysox.git\ncd pysox\npython setup.py install\n```\n\n\n# Tests\n\nIf you have a different version of SoX installed, it's recommended that you run\nthe tests locally to make sure everything behaves as expected, by simply running:\n\n```\npytest\n```\n\n# Examples\n\n```python\nimport sox\n# create transformer\ntfm = sox.Transformer()\n# trim the audio between 5 and 10.5 seconds.\ntfm.trim(5, 10.5)\n# apply compression\ntfm.compand()\n# apply a fade in and fade out\ntfm.fade(fade_in_len=1.0, fade_out_len=0.5)\n# create an output file.\ntfm.build_file('path/to/input_audio.wav', 'path/to/output/audio.aiff')\n# or equivalently using the legacy API\ntfm.build('path/to/input_audio.wav', 'path/to/output/audio.aiff')\n# get the output in-memory as a numpy array\n# by default the sample rate will be the same as the input file\narray_out = tfm.build_array(input_filepath='path/to/input_audio.wav')\n# see the applied effects\ntfm.effects_log\n> ['trim', 'compand', 'fade']\n\n```\n\nTransform in-memory arrays:\n```python\nimport numpy\nimport sox\n# sample rate in Hz\nsample_rate = 44100\n# generate a 1-second sine tone at 440 Hz\ny = np.sin(2 * np.pi * 440.0 * np.arange(sample_rate * 1.0) / sample_rate)\n# create a transformer\ntfm = sox.Transformer()\n# shift the pitch up by 2 semitones\ntfm.pitch(2)\n# transform an in-memory array and return an array\ny_out = tfm.build_array(input_array=y, sample_rate_in=sample_rate)\n# instead, save output to a file\ntfm.build_file(\n    input_array=y, sample_rate_in=sample_rate,\n    output_filepath='path/to/output.wav'\n)\n# create an output file with a different sample rate\ntfm.set_output_format(rate=8000)\ntfm.build_file(\n    input_array=y, sample_rate_in=sample_rate,\n    output_filepath='path/to/output_8k.wav'\n)\n```\n\nConcatenate 3 audio files:\n```python\nimport sox\n# create combiner\ncbn = sox.Combiner()\n# pitch shift combined audio up 3 semitones\ncbn.pitch(3.0)\n# convert output to 8000 Hz stereo\ncbn.convert(samplerate=8000, n_channels=2)\n# create the output file\ncbn.build(\n    ['input1.wav', 'input2.wav', 'input3.wav'], 'output.wav', 'concatenate'\n)\n# the combiner does not currently support array input/output\n```\n\nGet file information:\n```python\nimport sox\n# get the sample rate\nsample_rate = sox.file_info.sample_rate('path/to/file.mp3')\n# get the number of samples\nn_samples = sox.file_info.num_samples('path/to/file.wav')\n# determine if a file is silent\nis_silent = sox.file_info.silent('path/to/file.aiff')\n# file info doesn't currently support array input\n```\n\n\n",
    "bugtrack_url": null,
    "license": "BSD-3-Clause",
    "summary": "Python wrapper around SoX.",
    "version": "1.4.1",
    "project_urls": {
        "Download": "http://github.com/rabitt/pysox/releases",
        "Homepage": "https://github.com/rabitt/pysox"
    },
    "split_keywords": [
        "audio",
        "effects",
        "sox"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3f671810e9a69956eb236967b7174c11fd8d8c2cdab051509286f72e6c7e147e",
                "md5": "23a73d333360183c6cca4b5dc47e6902",
                "sha256": "2458c8e71e229e7fb1a088874ad07906e0aedfb2874a6c4f0430efd6e7587129"
            },
            "downloads": -1,
            "filename": "sox-1.4.1-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "23a73d333360183c6cca4b5dc47e6902",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 39686,
            "upload_time": "2020-09-30T01:20:24",
            "upload_time_iso_8601": "2020-09-30T01:20:24.830786Z",
            "url": "https://files.pythonhosted.org/packages/3f/67/1810e9a69956eb236967b7174c11fd8d8c2cdab051509286f72e6c7e147e/sox-1.4.1-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5b530de2626feb9d3d43ae56c42c35e8048daf09de7ea1124657ef8834582ca0",
                "md5": "9dc509286d5841c871155fa863609036",
                "sha256": "b0f2d13692450b889cd3f66127e96f801942ec2aac5bb21653dfd150e0d71055"
            },
            "downloads": -1,
            "filename": "sox-1.4.1.tar.gz",
            "has_sig": false,
            "md5_digest": "9dc509286d5841c871155fa863609036",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 62423,
            "upload_time": "2020-09-30T01:20:26",
            "upload_time_iso_8601": "2020-09-30T01:20:26.086214Z",
            "url": "https://files.pythonhosted.org/packages/5b/53/0de2626feb9d3d43ae56c42c35e8048daf09de7ea1124657ef8834582ca0/sox-1.4.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2020-09-30 01:20:26",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "rabitt",
    "github_project": "pysox",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "sox"
}
        
Elapsed time: 0.20574s