def read_stems(<EOL>filename,<EOL>out_type=np.float_,<EOL>stem_id=None,<EOL>start=<NUM_LIT:0>,<EOL>duration=None,<EOL>info=None<EOL>):
if info is None:<EOL><INDENT>FFinfo = Info(filename)<EOL><DEDENT>else:<EOL><INDENT>FFinfo = info<EOL><DEDENT>if stem_id is not None:<EOL><INDENT>substreams = stem_id<EOL><DEDENT>else:<EOL><INDENT>substreams = FFinfo.audio_stream_idx()<EOL><DEDENT>if not isinstance(substreams, list):<EOL><INDENT>substreams = [substreams]<EOL><DEDENT>stems = []<EOL>tmps = [<EOL>tmp.NamedTemporaryFile(delete=False, suffix='<STR_LIT>')<EOL>for t in substreams<EOL>]<EOL>for tmp_id, stem in enumerate(substreams):<EOL><INDENT>rate = FFinfo.rate(stem)<EOL>channels = FFinfo.channels(stem)<EOL>cmd = [<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>', filename,<EOL>'<STR_LIT>', '<STR_LIT>' + str(stem),<EOL>'<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', str(rate),<EOL>'<STR_LIT>', str(channels),<EOL>'<STR_LIT>', '<STR_LIT:error>',<EOL>tmps[tmp_id].name<EOL>]<EOL>if start:<EOL><INDENT>cmd.insert(<NUM_LIT:3>, '<STR_LIT>')<EOL>cmd.insert(<NUM_LIT:4>, str(start))<EOL><DEDENT>if duration is not None:<EOL><INDENT>cmd.insert(-<NUM_LIT:1>, '<STR_LIT>')<EOL>cmd.insert(-<NUM_LIT:1>, str(duration))<EOL><DEDENT>sp.call(cmd)<EOL>audio, rate = sf.read(tmps[tmp_id].name)<EOL>tmps[tmp_id].close()<EOL>os.remove(tmps[tmp_id].name)<EOL>stems.append(audio)<EOL><DEDENT>stem_durations = np.array([t.shape[<NUM_LIT:0>] for t in stems])<EOL>if not (stem_durations == stem_durations[<NUM_LIT:0>]).all():<EOL><INDENT>warnings.warn("<STR_LIT>")<EOL>min_length = np.min(stem_durations)<EOL>stems = [t[:min_length, :] for t in stems]<EOL><DEDENT>stems = np.array(stems)<EOL>stems = np.squeeze(stems).astype(out_type)<EOL>return stems, rate<EOL>
Read STEMS format into numpy Tensor

    Parameters
    ----------
    filename : str
        Filename of STEMS format. Typically `filename.stem.mp4`.
    out_type : type
        Output type. Defaults to 32bit float aka `np.float32`.
    stem_id : int
        Stem ID (Stream ID) to read. Defaults to `None`, which reads all
        available stems.
    start : float
        Start position (seek) in seconds, defaults to 0.
    duration : float
        Read `duration` seconds. End position then is `start + duration`.
        Defaults to `None`: read till the end.
    info : object
        provide info object, useful if read_stems is called frequently on
        file with same configuration (#streams, #channels, samplerate).
    Returns
    -------
    stems : array_like
        The tensor of Matrix of stems. The data shape is formatted as
        :code:`stems x channels x samples`.

    Notes
    -----

    Input is expected to be in 16bit/44.1 kHz