def load_audio(
        file: Union[str, bytes, BinaryIO],
        sr: int = None,
        verbose: Optional[bool] = True,
        only_ffmpeg: bool = False,
        mono: bool = True

):
    """
    Open an audio file and read as mono waveform then resamples as necessary.

    Parameters
    ----------
    file : str or bytes or BinaryIO
        The audio file to open, bytes of file, or URL to audio/video.
    sr : int, default whisper.model.SAMPLE_RATE
        The sample rate to resample the audio if necessary.
    verbose : bool or None, default True
        Verbosity for yd-dlp and displaying content metadata when ``file`` is a URL. If not ``None``, display metadata.
        For yd-dlp: ``None`` is "--quiet"; ``True`` is "--progress"; ``False`` is "--progress" + "--quiet".
    only_ffmpeg : bool, default False
        Whether to use only FFmpeg (instead of yt-dlp) for URls.
    mono : bool, default True
        Whether to load as mono audio.

    Returns
    -------
    numpy.ndarray
        A array containing the audio waveform in float32.
    """
    if sr is None:
        sr = SAMPLE_RATE
    file = load_source(file, verbose=verbose, only_ffmpeg=only_ffmpeg, return_dict=False)
    try:
        # This launches a subprocess to decode audio while down-mixing and resampling as necessary.
        # Requires the ffmpeg CLI in PATH.
        cmd = [
            "ffmpeg",
            "-nostdin",
            "-threads", "0",
            "-i", file if isinstance(file, str) else "pipe:",
            "-f", "s16le",
            "-ac", "1" if mono else "2",
            "-acodec", "pcm_s16le",
            "-ar", str(sr),
            "-"
        ]
        if isinstance(file, str):
            out = subprocess.run(cmd, capture_output=True, check=True).stdout
        else:
            cmd = cmd[:1] + ["-loglevel", "error"] + cmd[1:]
            stdin = subprocess.PIPE if isinstance(file, bytes) else file
            out = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=stdin)
            out = out.communicate(input=file if isinstance(file, bytes) else None)[0]
            if not out:
                raise RuntimeError(f"FFmpeg failed to load audio from bytes ({len(file)}).")
    except (subprocess.CalledProcessError, subprocess.SubprocessError) as e:
        raise RuntimeError(f"FFmpeg failed to load audio: {e.stderr.decode()}") from e

    waveform = np.frombuffer(out, np.int16).flatten().astype(np.float32) / 32768.0
    if not mono:
        return waveform.reshape(-1, 2).transpose(1, 0)
    return waveform

    Open an audio file and read as mono waveform then resamples as necessary.

    Parameters
    ----------
    file : str or bytes or BinaryIO
        The audio file to open, bytes of file, or URL to audio/video.
    sr : int, default whisper.model.SAMPLE_RATE
        The sample rate to resample the audio if necessary.
    verbose : bool or None, default True
        Verbosity for yd-dlp and displaying content metadata when ``file`` is a URL. If not ``None``, display metadata.
        For yd-dlp: ``None`` is "--quiet"; ``True`` is "--progress"; ``False`` is "--progress" + "--quiet".
    only_ffmpeg : bool, default False
        Whether to use only FFmpeg (instead of yt-dlp) for URls.
    mono : bool, default True
        Whether to load as mono audio.

    Returns
    -------
    numpy.ndarray
        A array containing the audio waveform in float32.
    
stable_whisper/audio/utils.py