diff --git a/MANIFEST.in b/MANIFEST.in index e69de29..7d9c95c 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -0,0 +1 @@ +include tests/data/The Easton Ellises - Falcon 69.stem.mp4 \ No newline at end of file diff --git a/README.md b/README.md index 94b72fd..eba773f 100644 --- a/README.md +++ b/README.md @@ -38,13 +38,15 @@ pip install stempeg ## Usage -There are very few freely available stem files. We [included](https://raw.githubusercontent.com/faroit/stempeg/master/tests/data/The%20Easton%20Ellises%20-%20Falcon%2069.stem.mp4) a small test track from the Canadian rock-band _The Easton Ellises_. The band [released them](https://www.heise.de/ct/artikel/c-t-Remix-Wettbewerb-The-Easton-Ellises-2542427.html) under Creative Commons license CC BY-NC-SA 3.0. +There are very few freely available stem files. We included a small test track from the Canadian rock-band _The Easton Ellises_. The band [released them](https://www.heise.de/ct/artikel/c-t-Remix-Wettbewerb-The-Easton-Ellises-2542427.html) under Creative Commons license CC BY-NC-SA 3.0. + +To use the included stem example you can use `stempeg.example_stem_path()`. ### Reading stems ```python import stempeg -S, rate = stempeg.read_stems("input.stem.mp4") +S, rate = stempeg.read_stems(stempeg.example_stem_path()) ``` `S` is the stem tensor that includes the time domain signals scaled to `[-1..1]`. The shape is `(stems, samples, channels)`. @@ -54,7 +56,7 @@ S, rate = stempeg.read_stems("input.stem.mp4") you can read individual substreams of the stem file by passing the corresponding stem id (starting from 0): ```python -S, rate = stempeg.read_stems("input.stem.mp4", stem_id=[0, 1]) +S, rate = stempeg.read_stems(stempeg.example_stem_path(), stem_id=[0, 1]) ``` ### Read excerpts (set seek position) @@ -62,7 +64,7 @@ S, rate = stempeg.read_stems("input.stem.mp4", stem_id=[0, 1]) to read an excerpt from the stem instead of the full file, you can provide start (`start`) and duration (`duration`) in seconds to `read_stems`: ```python -S, _ = stempeg.read_stems("input.stem.mp4", start=1, duration=1.5) +S, _ = stempeg.read_stems(stempeg.example_stem_path(), start=1, duration=1.5) # read from second 1.0 to second 2.5 ``` @@ -71,8 +73,9 @@ S, _ = stempeg.read_stems("input.stem.mp4", start=1, duration=1.5) if `read_stems` is called repeatedly, it always does two system calls, one for getting the [file info](https://github.com/faroit/stempeg/blob/a56349d2a8297ccf5db13712fc16048029503b26/stempeg/read.py#L120) and one for the [actual reading](https://github.com/faroit/stempeg/blob/a56349d2a8297ccf5db13712fc16048029503b26/stempeg/read.py#L160). To speed this up you could provide the `Info` object to `read_stems` if the number of streams, the number of channels and the samplerate is identical. ```python -info = stempeg.Info("input.stem.mp4") -S, _ = stempeg.read_stems("input.stem.mp4", info=info) +file_path = stempeg.example_stem_path() +info = stempeg.Info(file_path) +S, _ = stempeg.read_stems(file_path, info=info) ``` ### Writing stems @@ -92,5 +95,5 @@ _stempeg_ provides a convenient cli tool to convert a stem to multiple wavfiles. ```bash -stem2wav tests/data/The Easton Ellises - Falcon 69.stem.mp4 -s 1.0 -t 2.5 +stem2wav The Easton Ellises - Falcon 69.stem.mp4 -s 1.0 -t 2.5 ``` diff --git a/setup.py b/setup.py index b277cee..004af6d 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ setup( name='stempeg', - version='0.1.5', + version='0.1.6', description='Read and write stem multistream audio files', long_description=long_description, long_description_content_type='text/markdown', @@ -55,4 +55,5 @@ project_urls={ # Optional 'Bug Reports': 'https://github.com/faroit/stempeg/issues', }, -) \ No newline at end of file + include_package_data=True +) diff --git a/stempeg/__init__.py b/stempeg/__init__.py index c7cb555..fa95ccf 100644 --- a/stempeg/__init__.py +++ b/stempeg/__init__.py @@ -10,8 +10,23 @@ from os import path as op import soundfile as sf import argparse +import pkg_resources -__version__ = "0.1.5" +__version__ = "0.1.6" + + +def example_stem_path(): + """Get the path to an included stem file. + + Returns + ------- + filename : str + Path to the stem file + """ + return pkg_resources.resource_filename( + __name__, + 'data/The Easton Ellises - Falcon 69.stem.mp4' + ) def ffmpeg_version(): diff --git a/tests/data/The Easton Ellises - Falcon 69.stem.mp4 b/stempeg/data/The Easton Ellises - Falcon 69.stem.mp4 similarity index 100% rename from tests/data/The Easton Ellises - Falcon 69.stem.mp4 rename to stempeg/data/The Easton Ellises - Falcon 69.stem.mp4 diff --git a/tests/test_read.py b/tests/test_read.py index def0a80..6d89bbb 100644 --- a/tests/test_read.py +++ b/tests/test_read.py @@ -19,28 +19,24 @@ def duration(request): def test_stem_id(): - S, _ = stempeg.read_stems( - "tests/data/The Easton Ellises - Falcon 69.stem.mp4" - ) + S, _ = stempeg.read_stems(stempeg.example_stem_path()) for k in range(S.shape[0]): Sk, _ = stempeg.read_stems( - "tests/data/The Easton Ellises - Falcon 69.stem.mp4", + stempeg.example_stem_path(), stem_id=k ) assert Sk.ndim == 2 def test_shape(): - S, _ = stempeg.read_stems( - "tests/data/The Easton Ellises - Falcon 69.stem.mp4" - ) + S, _ = stempeg.read_stems(stempeg.example_stem_path()) assert S.shape[0] == 5 assert ((S.shape[1] % 1024) == 0 and S.shape[1] > 200000) assert S.shape[2] == 2 def test_duration(start, duration): - fp = "tests/data/The Easton Ellises - Falcon 69.stem.mp4" + fp = stempeg.example_stem_path() info = stempeg.Info(fp) if start: if start < min(info.duration_streams): @@ -60,13 +56,13 @@ def test_duration(start, duration): def test_outtype(dtype): S, rate = stempeg.read_stems( - "tests/data/The Easton Ellises - Falcon 69.stem.mp4", + stempeg.example_stem_path(), out_type=dtype ) assert S.dtype == dtype def test_info(): - fp = "tests/data/The Easton Ellises - Falcon 69.stem.mp4" + fp = stempeg.example_stem_path() info = stempeg.Info(fp) S, rate = stempeg.read_stems(fp, info=info) diff --git a/tests/test_write.py b/tests/test_write.py index 781597f..9e64384 100644 --- a/tests/test_write.py +++ b/tests/test_write.py @@ -3,7 +3,5 @@ def test_write(): - S, rate = stempeg.read_stems( - "tests/data/The Easton Ellises - Falcon 69.stem.mp4" - ) + S, rate = stempeg.read_stems(stempeg.example_stem_path()) stempeg.write_stems(S, "./stems.mp4")