File size: 1,146 Bytes
2c9e5e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from musicgen_small import Musicgen_Small

import config
import os

# Test the local Musicgen_Small class with a 5 second music generation and assert file creation
def test_musicgen_small_local_model():
    musicgen_model = Musicgen_Small()
    prompt = "a very testy song, perfect to test the music generation model"
    audio_path = f"{config.AUDIO_DIR}/test_musicgen_small_local.wav"
    musicgen_model.generate_music(prompt, audio_path, use_local_musicgen=True)
    assert os.path.exists(audio_path)
    assert os.path.getsize(audio_path) > 0
    os.remove(audio_path)
    assert not os.path.exists(audio_path)

# Test the Musicgen_Small API with a 30 second music generation and assert file creation
def test_musicgen_small_api():
    musicgen_model = Musicgen_Small()
    prompt = "a very testy song, perfect to test the music generation model"
    audio_path = f"{config.AUDIO_DIR}/test_musicgen_small_api.wav"
    musicgen_model.generate_music(prompt, audio_path, use_local_musicgen=False)
    assert os.path.exists(audio_path)
    assert os.path.getsize(audio_path) > 0
    os.remove(audio_path)
    assert not os.path.exists(audio_path)