CoolFace
Apppublic

singularity7/Muggier

sourceHugging Facecc-by-nc-4.0updated 3y agoView on Hugging Face
0likes
test_audiogen.py54 linesDownload Raw Back to models
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 7import pytest8import torch9 10from audiocraft.models import AudioGen11 12 13class TestAudioGenModel:14    def get_audiogen(self):15        ag = AudioGen.get_pretrained(name='debug', device='cpu')16        ag.set_generation_params(duration=2.0, extend_stride=2.)17        return ag18 19    def test_base(self):20        ag = self.get_audiogen()21        assert ag.frame_rate == 2522        assert ag.sample_rate == 1600023        assert ag.audio_channels == 124 25    def test_generate_continuation(self):26        ag = self.get_audiogen()27        prompt = torch.randn(3, 1, 16000)28        wav = ag.generate_continuation(prompt, 16000)29        assert list(wav.shape) == [3, 1, 32000]30 31        prompt = torch.randn(2, 1, 16000)32        wav = ag.generate_continuation(33            prompt, 16000, ['youpi', 'lapin dort'])34        assert list(wav.shape) == [2, 1, 32000]35 36        prompt = torch.randn(2, 1, 16000)37        with pytest.raises(AssertionError):38            wav = ag.generate_continuation(39                prompt, 16000, ['youpi', 'lapin dort', 'one too many'])40 41    def test_generate(self):42        ag = self.get_audiogen()43        wav = ag.generate(44            ['youpi', 'lapin dort'])45        assert list(wav.shape) == [2, 1, 32000]46 47    def test_generate_long(self):48        ag = self.get_audiogen()49        ag.max_duration = 3.50        ag.set_generation_params(duration=4., extend_stride=2.)51        wav = ag.generate(52            ['youpi', 'lapin dort'])53        assert list(wav.shape) == [2, 1, 16000 * 4]54