Skip to content

Commit

Permalink
Merge b4c463c into 0591cb8
Browse files Browse the repository at this point in the history
  • Loading branch information
rabitt committed May 23, 2020
2 parents 0591cb8 + b4c463c commit 4a499dc
Show file tree
Hide file tree
Showing 10 changed files with 807 additions and 239 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ 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:
the tests locally to make sure everything behaves as expected, by simply running:

```
pytest tests/
pytest
```

# Examples
Expand All @@ -75,10 +75,12 @@ 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
status, audio_out, err = tfm.build(input_filepath='path/to/input_audio.wav')
array_out = tfm.build_array(input_filepath='path/to/input_audio.wav')
# see the applied effects
tfm.effects_log
> ['trim', 'compand', 'fade']
Expand All @@ -98,15 +100,15 @@ tfm = sox.Transformer()
# shift the pitch up by 2 semitones
tfm.pitch(2)
# compute transformation in-memory
status, y_out, err = tfm.build(input_array=y, sample_rate_in=sample_rate)
y_out = tfm.build_array(input_array=y, sample_rate_in=sample_rate)
# instead, save output to a file
tfm.build(
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(
tfm.build_file(
input_array=y, sample_rate_in=sample_rate,
output_filepath='path/to/output_8k.wav'
)
Expand Down
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import sys
import os
import shlex
import imp

# If extensions (or modules to document with autodoc) are in another directory,
Expand Down
12 changes: 7 additions & 5 deletions docs/example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Transform audio files
:linenos:
import sox
# create trasnformer
# create transformer
tfm = sox.Transformer()
# trim the audio between 5 and 10.5 seconds.
tfm.trim(5, 10.5)
Expand All @@ -18,10 +18,12 @@ Transform audio files
# 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
status, audio_out, err = tfm.build(input_filepath='path/to/input_audio.wav')
array_out = tfm.build_array(input_filepath='path/to/input_audio.wav')
# see the applied effects
tfm.effects_log
> ['trim', 'compand', 'fade']
Expand All @@ -42,15 +44,15 @@ Transform in-memory arrays
# shift the pitch up by 2 semitones
tfm.pitch(2)
# compute transformation in-memory
status, y_out, err = tfm.build(input_array=y, sample_rate_in=sample_rate)
y_out = tfm.build_array(input_array=y, sample_rate_in=sample_rate)
# instead, save output to a file
tfm.build(
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(
tfm.build_file(
input_array=y, sample_rate_in=sample_rate,
output_filepath='path/to/output_8k.wav'
)
Expand Down
32 changes: 32 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,38 @@
Welcome to pysox's documentation!
=================================

pysox is a Python wrapper around the amazing `SoX <(http://sox.sourceforge.net/)>`_ command line tool.

.. code-block:: python
import sox
Installation
------------

On Linux

.. code-block:: shell
# optional - if you want support for mp3, flac and ogg files
apt-get install libsox-fmt-all
# install the sox command line tool
apt-get install sox
# install pysox
pip install sox
On Mac

.. code-block:: shell
# optional - if you want support for mp3, flac and ogg files
brew install sox --with-lame --with-flac --with-libvorbis
# install the sox command line tool
brew install sox
# install pysox
pip install sox
Examples
--------
.. toctree::
Expand Down
4 changes: 3 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
[metadata]
description-file = README.md
[bdist_wheel]
universal = 1
universal = 1
5 changes: 3 additions & 2 deletions sox/combine.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def build(self, input_filepath_list, output_filepath, combine_type,
_validate_volumes(input_volumes)

input_format_list = _build_input_format_list(
input_filepath_list, input_volumes, self.input_format
input_filepath_list, input_volumes,
self.input_format
)

try:
Expand All @@ -94,7 +95,7 @@ def build(self, input_filepath_list, output_filepath, combine_type,
input_args = _build_input_args(input_filepath_list, input_format_list)
args.extend(input_args)

args.extend(self.output_format)
args.extend(self._output_format_args(self.output_format))
args.append(output_filepath)
args.extend(self.effects)

Expand Down

0 comments on commit 4a499dc

Please sign in to comment.