File size: 6,465 Bytes
b347b70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env python3
"""Direct ACE-Step generation using repo's AceStepHandler."""
import sys
import os
import shutil
from pathlib import Path

REPO_DIR = Path("/ssd_data/dataset/ai_music_dataset/models/ACE-Step-1.5")
sys.path.insert(0, str(REPO_DIR))
os.chdir(REPO_DIR)

from acestep.handler import AceStepHandler
from tqdm import tqdm

PROMPTS = [
    "Upbeat pop song with catchy synth melody and female vocals",
    "Smooth jazz trio with piano, upright bass, and brushed drums",
    "Classical orchestral piece with sweeping strings and French horns",
    "EDM festival banger with heavy bass drops and saw-wave synths",
    "Acoustic folk ballad with fingerpicked guitar and harmonica",
    "K-pop dance track with layered vocal harmonies and electronic beats",
    "Lo-fi hip-hop with vinyl crackle, mellow keys, and boom-bap drums",
    "Heavy metal with distorted guitars, double bass drums, and growling vocals",
    "R&B slow jam with silky vocals, Rhodes piano, and 808 bass",
    "Country song with steel guitar, fiddle, and storytelling lyrics",
    "Reggaeton with dembow rhythm, Latin percussion, and autotune vocals",
    "Ambient electronic with evolving pads, field recordings, and reverb",
    "Funk groove with slap bass, wah guitar, and tight horn section",
    "Bossa nova with nylon guitar, soft percussion, and breathy vocals",
    "Trap beat with hi-hat rolls, 808 sub bass, and dark melody",
    "Indie rock with jangly guitars, driving drums, and earnest vocals",
    "Cinematic epic with choir, taiko drums, and orchestral brass",
    "Disco with four-on-the-floor kick, funky bass, and string stabs",
    "Blues shuffle with overdriven guitar, walking bass, and organ",
    "Synthwave with arpeggiated synths, gated reverb drums, and retro pads",
    "Latin salsa with congas, timbales, piano montuno, and brass",
    "Chill electronic with soft pads, gentle beats, and atmospheric textures",
    "Progressive rock with odd time signatures, synth solos, and dynamic changes",
    "Gospel choir with powerful vocals, organ, and hand claps",
    "Drum and bass with fast breakbeats, deep sub bass, and chopped vocals",
    "Afrobeat with polyrhythmic drums, talking drum, and horn riffs",
    "New age meditation music with crystal bowls, gentle flute, and nature sounds",
    "Punk rock with fast power chords, shouted vocals, and crashing cymbals",
    "Swing jazz with walking bass, big band horns, and brush drums",
    "Minimal techno with hypnotic loops, subtle variations, and deep kick",
    "Grunge with heavy distortion, angsty vocals, and loud-quiet dynamics",
    "Tropical house with steel drums, marimba, and laid-back beats",
    "Chamber music with string quartet playing romantic era melodies",
    "Hip-hop with boom-bap drums, scratching, and conscious rap flow",
    "Psychedelic rock with wah pedal, phaser effects, and extended jams",
    "Celtic folk with tin whistle, bodhrán drum, and fiddle",
    "Future bass with supersaw chords, pitched vocals, and heavy sidechain",
    "Musical theater ballad with piano accompaniment and emotional vocals",
    "Dubstep with wobble bass, half-time drums, and aggressive synths",
    "World fusion with sitar, tabla, and electronic production",
]


def main():
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument("--target", type=int, default=5000)
    parser.add_argument("--output-dir", type=str, required=True)
    parser.add_argument("--duration", type=float, default=60.0)
    args = parser.parse_args()

    output_dir = Path(args.output_dir)
    output_dir.mkdir(parents=True, exist_ok=True)

    existing = len(list(output_dir.glob("*.wav")) + list(output_dir.glob("*.mp3")))
    if existing >= args.target:
        print(f"Already at target: {existing}/{args.target}")
        return

    import os
    # Don't fake VRAM limit — let it use real available memory

    handler = AceStepHandler()

    checkpoint_dir = REPO_DIR / "checkpoints"
    dit_model_path = str(checkpoint_dir / "acestep-v15-turbo")

    print(f"Initializing ACE-Step handler (~6GB VRAM mode)...")
    print(f"  DiT model: {dit_model_path}")
    handler.initialize_service(
        project_root=str(REPO_DIR),
        config_path=dit_model_path,
        device="auto",
        offload_to_cpu=True,
        offload_dit_to_cpu=False,
    )

    generated = existing
    pbar = tqdm(total=args.target, initial=existing, desc="ACE-Step")

    while generated < args.target:
        prompt = PROMPTS[generated % len(PROMPTS)]
        try:
            result = handler.generate_music(
                captions=prompt,
                inference_steps=8,
                guidance_scale=7.0,
                audio_duration=args.duration,
                batch_size=1,
                task_type="text2music",
                use_random_seed=True,
            )

            # Result should contain audio files or data
            if result is None:
                continue

            # Check if result has audio data
            if hasattr(result, 'audio_paths') and result.audio_paths:
                for ap in result.audio_paths:
                    src = Path(ap)
                    if src.exists():
                        dst = output_dir / f"acestep_{generated:05d}{src.suffix}"
                        shutil.move(str(src), str(dst))
                        generated += 1
                        pbar.update(1)
            elif hasattr(result, 'audios') and result.audios:
                import soundfile as sf
                for audio_data in result.audios:
                    dst = output_dir / f"acestep_{generated:05d}.wav"
                    if isinstance(audio_data, tuple):
                        sf.write(str(dst), audio_data[0], audio_data[1])
                    generated += 1
                    pbar.update(1)
            else:
                # Try to find generated files in temp/output dirs
                for wav in sorted(REPO_DIR.glob("output*/*.wav"), key=lambda p: p.stat().st_mtime):
                    dst = output_dir / f"acestep_{generated:05d}.wav"
                    shutil.move(str(wav), str(dst))
                    generated += 1
                    pbar.update(1)
                    break

        except Exception as e:
            print(f"Error at {generated}: {e}")
            continue

    pbar.close()
    print(f"Done. Generated {generated} tracks in {output_dir}")


if __name__ == "__main__":
    main()