CoolFace
Apppublic

softwareweaver/MusicGen

sourceHugging Facecc-by-nc-4.0updated 11mo agoView on Hugging Face
0likes
notebook.py33 linesDownload Raw Back to utils
1# Copyright (c) Meta Platforms, Inc. and affiliates.2# All rights reserved.3#4# This source code is licensed under the license found in the5# LICENSE file in the root directory of this source tree.6 7try:8    import IPython.display as ipd  # type: ignore9except ImportError:10    # Note in a notebook...11    pass12 13 14import torch15 16 17def display_audio(samples: torch.Tensor, sample_rate: int):18    """Renders an audio player for the given audio samples.19 20    Args:21        samples (torch.Tensor): a Tensor of decoded audio samples22            with shapes [B, C, T] or [C, T]23        sample_rate (int): sample rate audio should be displayed with.24    """25    assert samples.dim() == 2 or samples.dim() == 326 27    samples = samples.detach().cpu()28    if samples.dim() == 2:29        samples = samples[None, ...]30 31    for audio in samples:32        ipd.display(ipd.Audio(audio, rate=sample_rate))33