File size: 6,686 Bytes
ce5577d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
882133e
ce5577d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
882133e
ce5577d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
882133e
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
import gradio as gr

DESCRIPTION = """
# audio-studio

Local music generation studio wrapping **ACE-Step 1.5**.

Text-to-music, reference-audio melody borrowing, and reference-audio cover generation,
with configurable artist/album/track/genre texture hints.

## Features

- **Text-to-music**: Describe what you want, get a WAV file
- **Melody borrowing**: Provide a reference audio to borrow its BPM, key, and duration
- **Cover mode**: Full sound/texture conditioning from a reference (requires ace-step backend)
- **Texture hints**: Artist, album, track, and genre hints appended to prompts
- **Two backends**: `mlx-serve` (default, ~2.9GB) or `ace-step` (~17.8GB, for cover mode)

## Quick Start

```bash
# Clone and setup
git clone https://github.com/sm3222/audio-studio.git
cd audio-studio
uv sync

# Start the backend ( mlx-serve by default)
mlx-serve serve --port 8082 --model-dir ~/.mlx-serve/models

# Generate music
uv run audio-studio "a calm piano piece" --artist "Bob Marley" --output out.wav
```

## Links

- [GitHub Repository](https://github.com/sm3222/audio-studio)
- [ACE-Step 1.5 Paper](https://arxiv.org/abs/2503.02057)
- [mlx-serve](https://github.com/lucasnewman/mlx-serve)
"""

EXAMPLE_PROMPTS = [
    "a calm piano piece with soft strings",
    "upbeat electronic dance music with synth leads",
    "acoustic folk guitar with gentle vocals",
    "heavy rock drums with distorted guitar riffs",
    "ambient atmospheric soundscape with pads",
]


def build_command(prompt, artists, albums, tracks, genres, live, instrumental, backend, reference, cover):
    """Build the CLI command from user inputs."""
    parts = ["uv run audio-studio"]

    if prompt:
        parts.append(f'"{prompt}"')

    for artist in artists.split(","):
        artist = artist.strip()
        if artist:
            parts.append(f'--artist "{artist}"')

    for album in albums.split(","):
        album = album.strip()
        if album:
            parts.append(f'--album "{album}"')

    for track in tracks.split(","):
        track = track.strip()
        if track:
            parts.append(f'--track "{track}"')

    for genre in genres.split(","):
        genre = genre.strip()
        if genre:
            parts.append(f'--genre "{genre}"')

    if live:
        parts.append("--live")

    if not instrumental:
        parts.append("--no-instrumental")

    if backend != "mlx-serve":
        parts.append(f"--backend {backend}")

    if reference:
        parts.append(f'--reference "{reference}"')

    if cover:
        parts.append("--cover")

    parts.append("--output out.wav")
    return " \\\n  ".join(parts)


with gr.Blocks(title="audio-studio") as demo:
    gr.Markdown(DESCRIPTION)

    with gr.Tab("Command Builder"):
        with gr.Row():
            with gr.Column():
                prompt = gr.Textbox(
                    label="Prompt",
                    placeholder="Describe the music you want to generate...",
                    lines=3,
                )
                artists = gr.Textbox(
                    label="Artists (comma-separated)",
                    placeholder="e.g., Bob Marley, Lee Perry",
                )
                albums = gr.Textbox(label="Albums (comma-separated)")
                tracks = gr.Textbox(label="Tracks (comma-separated)")
                genres = gr.Textbox(label="Genres (comma-separated)")

            with gr.Column():
                live = gr.Checkbox(label="Live performance texture", value=False)
                instrumental = gr.Checkbox(label="Instrumental (no vocals)", value=True)
                backend = gr.Radio(
                    choices=["mlx-serve", "ace-step"],
                    value="mlx-serve",
                    label="Backend",
                )
                reference = gr.Textbox(
                    label="Reference audio path (optional)",
                    placeholder="/path/to/reference.wav",
                )
                cover = gr.Checkbox(
                    label="Cover mode (requires ace-step backend)",
                    value=False,
                )

        build_btn = gr.Button("Build Command", variant="primary")
        command_output = gr.Code(label="Generated Command")

        build_btn.click(
            fn=build_command,
            inputs=[prompt, artists, albums, tracks, genres, live, instrumental, backend, reference, cover],
            outputs=command_output,
        )

        gr.Examples(
            examples=[[p] for p in EXAMPLE_PROMPTS],
            inputs=prompt,
            label="Example Prompts",
        )

    with gr.Tab("Examples"):
        gr.Markdown("""
## Example Generations

```bash
# Simple text-to-music
uv run audio-studio "a calm piano piece" --output out.wav

# With artist hints
uv run audio-studio "heavy drums and bass" --artist "Bob Marley" --output out.wav

# With reference audio (melody only)
uv run audio-studio "electronic remix" --reference original.wav --output out.wav

# Full cover mode (requires ace-step backend)
uv run audio-studio "jazz cover" --reference original.wav --cover --backend ace-step --output out.wav

# Multiple hints
uv run audio-studio "ambient soundscape" \\
  --artist "Lee Perry" \\
  --genre "ambient" \\
  --live \\
  --output out.wav
```

## Texture Hints

Edit `config/hints.json` to add your own artist/album/track/genre hints:

```json
{
  "artist": {
    "bob marley": "heavy acoustic drums, analog tape echo",
    "lee perry": "heavy acoustic drums, analog tape echo"
  },
  "genre": {
    "ambient": "atmospheric pads, reverb-heavy, slow evolution"
  }
}
```
""")

    with gr.Tab("Architecture"):
        gr.Markdown("""
## Architecture

```
audio-studio/
β”œβ”€β”€ src/audio_studio/
β”‚   β”œβ”€β”€ cli.py              # CLI entrypoint
β”‚   β”œβ”€β”€ prompt.py           # Prompt construction with hints
β”‚   β”œβ”€β”€ analysis.py         # Reference audio analysis (librosa)
β”‚   β”œβ”€β”€ loop.py             # Generation loop (submit β†’ poll β†’ download)
β”‚   β”œβ”€β”€ acestep_client.py   # ACE-Step API client
β”‚   └── mlx_serve_client.py # mlx-serve API client
β”œβ”€β”€ config/hints.json       # Texture hint definitions
└── output/                 # Generated WAV files
```

## Backends

| Backend | Memory | Cover Mode | Notes |
|---------|--------|------------|-------|
| `mlx-serve` | ~2.9GB | No | Default, MLX-native, fast |
| `ace-step` | ~17.8GB | Yes | Original PyTorch/MPS, heavy |

## Dependencies

- Python 3.12+
- librosa (audio analysis)
- mlx-serve or ace-step API server running
- See `pyproject.toml` for full list
""")

if __name__ == "__main__":
    demo.launch(mcp_server=True, theme=gr.themes.Soft())