import audioop


def convert_framerate(fragment, width, nchannels, framerate_in, framerate_out):
    """
    Convert framerate (sampling rate) of the input fragment.

    Parameters
    ----------
    fragment : bytes object
        Specifies the original fragment.
    width : int
        Specifies the fragment's original sampwidth.
    nchannels : int
        Specifies the fragment's original nchannels.
    framerate_in : int
        Specifies the fragment's original framerate.
    framerate_out : int
        Specifies the fragment's desired framerate.

    Returns
    -------
    bytes

    """
    if framerate_in == framerate_out:
        return fragment

    new_fragment, _ = audioop.ratecv(fragment, width, nchannels, framerate_in, framerate_out, None)
    return new_fragment