Example #1
0
    def __init__(self,
                 path="None",
                 is_wav=False,
                 stem_id=None,
                 subset=None,
                 chunk_start=0,
                 chunk_duration=None):
        self.path = path
        self.subset = subset
        self.stem_id = stem_id
        self.is_wav = is_wav

        self.chunk_start = chunk_start
        self.chunk_duration = chunk_duration

        # load and store metadata
        if os.path.exists(self.path):
            if not self.is_wav:
                self.info = stempeg.Info(self.path)
                self.samples = int(self.info.samples(self.stem_id))
                self.duration = self.info.duration(self.stem_id)
                self.rate = self.info.rate(self.stem_id)
            else:
                self.info = sf.info(self.path)
                self.samples = self.info.frames
                self.duration = self.info.duration
                self.rate = self.info.samplerate
        else:
            # set to `None` if no path was set (fake file)
            self.info = None
            self.samples = None
            self.duration = None
            self.rate = None

        self._audio = None
def info_stempeg(fp):
    info = {}
    si = stempeg.Info(fp)
    info["sampling_rate"] = si.sample_rate(0)
    info["samples"] = si.samples(0)
    info["channels"] = si.channels(0)
    info["duration"] = si.duration(0)
    return info
Example #3
0
def test_duration(start, duration):
    fp = stempeg.example_stem_path()
    info = stempeg.Info(fp)
    if start:
        if start < min(info.duration_streams):
            S, _ = stempeg.read_stems(fp, start=start, duration=duration)
    else:
        S, rate = stempeg.read_stems(fp, start=start, duration=duration)
        if duration is not None:
            assert S.shape[1] == duration * rate
Example #4
0
def test_multistream_containers(audio, multistream_format, nb_stems):
    if nb_stems > 1:
        with tmp.NamedTemporaryFile(delete=False,
                                    suffix='.' +
                                    multistream_format) as tempfile:
            stem_names = [str(k) for k in range(nb_stems)]
            stempeg.write_stems(tempfile.name,
                                audio,
                                sample_rate=44100,
                                writer=stempeg.StreamsWriter(
                                    codec='aac', stem_names=stem_names))
            loaded_audio, rate = stempeg.read_stems(tempfile.name,
                                                    always_3d=True)
            assert audio.shape == loaded_audio.shape
            if multistream_format == "m4a":
                info = stempeg.Info(tempfile.name)
                loaded_stem_names = info.title_streams
                # check if titles could be extracted
                assert all(
                    [a == b for a, b in zip(stem_names, loaded_stem_names)])
Example #5
0
def test_info():
    fp = stempeg.example_stem_path()
    info = stempeg.Info(fp)
    S, rate = stempeg.read_stems(fp, info=info)
Example #6
0
"""Opens a stem file prints stream info
"""
import argparse
import stempeg

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('input', )
    args = parser.parse_args()

    # read stems
    i = stempeg.Info(args.input)