Team Ai
Apppublic

unity2009/MusicGenAI

sourceHugging Facecc-by-nc-4.0updated 3y agoView on Hugging Face
0likes
wav_utils.py30 linesDownload Raw Back to common_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 7from pathlib import Path8 9import torch10 11from audiocraft.data.audio import audio_write12 13 14def get_white_noise(chs: int = 1, num_frames: int = 1):15    wav = torch.randn(chs, num_frames)16    return wav17 18 19def get_batch_white_noise(bs: int = 1, chs: int = 1, num_frames: int = 1):20    wav = torch.randn(bs, chs, num_frames)21    return wav22 23 24def save_wav(path: str, wav: torch.Tensor, sample_rate: int):25    assert wav.dim() == 2, wav.shape26    fp = Path(path)27    assert fp.suffix in ['.mp3', '.ogg', '.wav', '.flac'], fp28    audio_write(fp.parent / fp.stem, wav, sample_rate, fp.suffix[1:],29                normalize=False, strategy='clip', peak_clip_headroom_db=0)30