-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathnodes.py
More file actions
726 lines (637 loc) · 26.2 KB
/
nodes.py
File metadata and controls
726 lines (637 loc) · 26.2 KB
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
import json
import base64
import io
import struct
import wave
import os
import numpy as np
import torch
import requests
# =============================================================================
# Persistent API key storage
# =============================================================================
_CONFIG_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), ".config")
_API_KEY_FILE = os.path.join(_CONFIG_DIR, "api_key")
def _save_api_key(key):
os.makedirs(_CONFIG_DIR, exist_ok=True)
with open(_API_KEY_FILE, "w", encoding="utf-8") as f:
f.write(key)
def _load_api_key():
try:
with open(_API_KEY_FILE, "r", encoding="utf-8") as f:
return f.read().strip()
except FileNotFoundError:
return ""
# =============================================================================
# HTTP / audio helpers
# =============================================================================
def _resolve_api_key(api_key: str) -> str:
resolved = api_key.strip() if api_key else ""
if resolved:
_save_api_key(resolved)
os.environ["ACESTEP_API_KEY"] = resolved
else:
resolved = os.environ.get("ACESTEP_API_KEY", "") or _load_api_key()
return resolved
def _make_headers(api_key: str) -> dict:
headers = {
"Content-Type": "application/json",
"User-Agent": "AceMusic-ComfyUI/2.0",
}
resolved = _resolve_api_key(api_key)
if resolved:
headers["Authorization"] = f"Bearer {resolved}"
return headers
def _post_json(url: str, body: dict, headers: dict, timeout: int = 600) -> dict:
try:
resp = requests.post(
url,
data=json.dumps(body, ensure_ascii=False).encode("utf-8"),
headers=headers,
timeout=timeout,
)
resp.raise_for_status()
return resp.json()
except requests.exceptions.HTTPError:
raise RuntimeError(f"API error {resp.status_code}: {resp.text}")
except requests.exceptions.ConnectionError as e:
raise RuntimeError(f"Cannot connect to server: {e}")
except requests.exceptions.Timeout:
raise RuntimeError("Request timed out")
def _tensor_to_wav_b64(waveform, sample_rate) -> str:
n_channels = waveform.shape[0]
clamped = waveform.clamp(-1.0, 1.0)
pcm = (clamped * 32767).to(torch.int16)
interleaved = pcm.T.contiguous().reshape(-1)
raw = struct.pack(f"<{interleaved.numel()}h", *interleaved.tolist())
buf = io.BytesIO()
with wave.open(buf, "wb") as wf:
wf.setnchannels(n_channels)
wf.setsampwidth(2)
wf.setframerate(sample_rate)
wf.writeframes(raw)
return base64.b64encode(buf.getvalue()).decode("utf-8")
def _encode_audio_b64(audio) -> str:
waveform = audio["waveform"].squeeze(0)
return _tensor_to_wav_b64(waveform, audio["sample_rate"])
def _parse_wav_bytes(audio_bytes: bytes):
"""Parse WAV bytes manually to support PCM (fmt=1) and float32 (fmt=3)."""
if audio_bytes[:4] != b"RIFF" or audio_bytes[8:12] != b"WAVE":
raise RuntimeError("Not a valid WAV file")
pos = 12
fmt_tag = n_channels = sample_rate = sampwidth = 0
data_offset = data_size = 0
while pos < len(audio_bytes) - 8:
chunk_id = audio_bytes[pos:pos+4]
chunk_size = struct.unpack_from("<I", audio_bytes, pos+4)[0]
pos += 8
if chunk_id == b"fmt ":
fmt_tag = struct.unpack_from("<H", audio_bytes, pos)[0]
n_channels = struct.unpack_from("<H", audio_bytes, pos+2)[0]
sample_rate = struct.unpack_from("<I", audio_bytes, pos+4)[0]
sampwidth = struct.unpack_from("<H", audio_bytes, pos+14)[0] // 8
elif chunk_id == b"data":
data_offset = pos
data_size = chunk_size
break
pos += chunk_size
if data_offset == 0:
raise RuntimeError("WAV data chunk not found")
raw = audio_bytes[data_offset:data_offset + data_size]
n_frames = data_size // (n_channels * sampwidth)
if fmt_tag == 1: # PCM int
if sampwidth == 2:
samples = np.frombuffer(raw, dtype=np.int16).astype(np.float32) / 32768.0
elif sampwidth == 4:
samples = np.frombuffer(raw, dtype=np.int32).astype(np.float32) / 2147483648.0
else:
raise RuntimeError(f"Unsupported PCM sample width: {sampwidth}")
elif fmt_tag == 3: # IEEE float32
samples = np.frombuffer(raw, dtype=np.float32).copy()
else:
raise RuntimeError(f"Unsupported WAV format tag: {fmt_tag}")
samples = samples.reshape(n_frames, n_channels).T
tensor = torch.from_numpy(samples).unsqueeze(0)
return tensor, sample_rate
def _decode_audio_data_url(data_url: str):
if "," in data_url:
b64_data = data_url.split(",", 1)[1]
else:
b64_data = data_url
audio_bytes = base64.b64decode(b64_data)
return _parse_wav_bytes(audio_bytes)
def _parse_audio_response(result: dict):
choices = result.get("choices", [])
audio_items = []
text_content = ""
if choices:
message = choices[0].get("message", {})
text_content = message.get("content", "")
audio_items = message.get("audio", [])
else:
audio_items = result.get("audio", [])
text_content = json.dumps(result.get("metadata", {}), ensure_ascii=False)
if result.get("lyrics"):
text_content += f"\n\nLyrics:\n{result['lyrics']}"
if not audio_items:
raise RuntimeError(
f"API returned no audio. Response: {text_content or json.dumps(result)}"
)
waveforms = []
sample_rate = None
for item in audio_items:
url = ""
if isinstance(item, dict):
url = item.get("audio_url", {}).get("url", "") or item.get("url", "")
if not url:
continue
wf, sr = _decode_audio_data_url(url)
waveforms.append(wf)
sample_rate = sr
if not waveforms:
raise RuntimeError("API returned no valid audio data")
max_len = max(w.shape[-1] for w in waveforms)
padded = []
for wf in waveforms:
if wf.shape[-1] < max_len:
wf = torch.nn.functional.pad(wf, (0, max_len - wf.shape[-1]))
padded.append(wf)
audio_tensor = torch.cat(padded, dim=0)
return {"waveform": audio_tensor, "sample_rate": sample_rate}, text_content
def _build_multimodal_content(prompt: str, audio_list: list) -> list | str:
if not audio_list:
return prompt
parts = []
if prompt:
parts.append({"type": "text", "text": prompt})
for audio in audio_list:
b64 = _encode_audio_b64(audio)
parts.append({
"type": "input_audio",
"input_audio": {"data": b64, "format": "wav"},
})
return parts
# =============================================================================
# Constants
# =============================================================================
VALID_LANGUAGES = [
"en", "zh", "ja", "ko", "es", "fr", "de", "pt", "ru", "it",
"ar", "az", "bg", "bn", "ca", "cs", "da", "el", "fa", "fi",
"he", "hi", "hr", "ht", "hu", "id", "is", "la", "lt", "ms",
"ne", "nl", "no", "pa", "pl", "ro", "sa", "sk", "sr", "sv",
"sw", "ta", "te", "th", "tl", "tr", "uk", "ur", "vi", "yue",
"unknown",
]
DEFAULT_CAPTION = (
"tight and groovy disco-funk track driven by a hyper-articulate slap "
"bassline weaving syncopated sixteenth-note grooves with percussive thumb "
"pops and ghost-note textures, locked into a crisp four-on-the-floor drum "
"machine beat. Clean, funky guitar provides sparse chord stabs to leave "
"sonic space for the bass, while filtered synth pads swell subtly in the "
"background. The smooth male lead vocal glides over the infectious groove. "
"The arrangement builds through verses and catchy choruses, then strips "
"down to drums and bass for an extended, harmonically adventurous solo "
"section: the bassist unleashes a technically explosive showcase\u2014rapid "
"double-thumb slaps morph into tapped harmonics, chromatic walking lines "
"resolve into chordal double-stops, and envelope-filter sweeps cascade "
"into distorted octave leaps. After the solo\u2019s climax, wah-drenched funk "
"guitar re-enters for a call-and-response exchange with the bass before "
"the full band drops into a final chorus and a gradual fade out, with the "
"bassline\u2019s final harmonic ringing into silence."
)
DEFAULT_LYRICS = (
"[Intro]\n"
"[Heavy guitar riff and drums]\n"
"[Vocal scream] Yeah!\n"
"\n"
"[Guitar Solo]\n"
"\n"
"[Verse 1]\n"
"\n"
"[Pre-Chorus]\n"
"\n"
"[Chorus]\n"
"\n"
"[Verse 2]\n"
"\n"
"[Pre-Chorus]\n"
"\n"
"[Chorus]\n"
"\n"
"[Bridge]\n"
"\n"
"[Guitar Solo]\n"
"\n"
"[Chorus]\n"
"\n"
"[Outro]\n"
"[Song ends abruptly]"
)
# =============================================================================
# Node: Audio Codes (editable passthrough)
# =============================================================================
class AceStepAudioCodes:
"""Editable audio codes passthrough.
Paste codes manually, or receive from Text2Music Server generation output."""
CATEGORY = "api node/audio/ACE-Step"
FUNCTION = "process"
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("audio_codes",)
OUTPUT_NODE = True
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"audio_codes": ("STRING", {
"default": "",
"multiline": True,
"tooltip": "Audio codes (<|audio_code_N|> tokens). "
"Edit manually or receive from audio_codes_in.",
}),
},
"optional": {
"audio_codes_in": ("STRING", {
"default": "",
"forceInput": True,
"tooltip": "Auto-fill from Text2Music Server output or paste manually",
}),
},
}
def process(self, audio_codes="", audio_codes_in=""):
resolved = audio_codes_in.strip() if audio_codes_in and audio_codes_in.strip() else audio_codes.strip()
return {"ui": {"audio_codes": [resolved]}, "result": (resolved,)}
# =============================================================================
# Node: Text2music Gen Params
# =============================================================================
class AceStepText2MusicGenParams:
"""Generation parameters for text2music / cover / remix / repaint."""
CATEGORY = "api node/audio/ACE-Step"
FUNCTION = "build"
RETURN_TYPES = ("ACESTEP_GEN_PARAMS",)
RETURN_NAMES = ("gen_params",)
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"sample_mode": ("BOOLEAN", {
"default": False,
"tooltip": "ON: use sample_query to let LLM generate caption/lyrics/metadata. "
"OFF: use manual caption and lyrics below.",
}),
"vocal_language": (VALID_LANGUAGES, {"default": "en"}),
},
"optional": {
"sample_query": ("STRING", {
"default": "a funk rock song with groovy bass and punchy drums",
"multiline": True,
"placeholder": "Describe the music you want (e.g. a funk rock song with groovy bass)",
"tooltip": "Natural language description for LLM to generate caption/lyrics/metadata",
}),
"is_instrumental": ("BOOLEAN", {
"default": False,
"tooltip": "Generate instrumental only (no vocals).",
}),
"caption": ("STRING", {
"default": DEFAULT_CAPTION,
"multiline": True,
"placeholder": "Music style description (e.g. deep house, dreamy, atmospheric)",
"tooltip": "Music style description / caption",
}),
"lyrics": ("STRING", {
"default": DEFAULT_LYRICS,
"multiline": True,
"placeholder": "Song lyrics with [verse], [chorus] tags... (empty = instrumental)",
"tooltip": "Song lyrics (leave empty for instrumental)",
}),
"auto": ("BOOLEAN", {
"default": True,
"tooltip": "ON: bpm/key left for LM to decide. "
"OFF: use manual values.",
}),
"cover_strength": ("FLOAT", {
"default": 0.0, "min": 0.0, "max": 1.0, "step": 0.05,
"tooltip": "Cover strength (only used when src_audio is connected)",
}),
"remix_strength": ("FLOAT", {
"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.05,
"tooltip": "Remix noise strength (only used when src_audio is connected)",
}),
"is_repaint": ("BOOLEAN", {
"default": False,
"tooltip": "Enable repaint mode (requires src_audio). "
"Regenerates a time range within the source audio.",
}),
"bpm": ("INT", {
"default": 120, "min": 0, "max": 300, "step": 1,
"tooltip": "Beats per minute (0 = auto)",
}),
"key": ("STRING", {
"default": "",
"tooltip": "e.g. 'C major', 'D minor'",
}),
"duration": ("FLOAT", {
"default": 30.0, "min": -1.0, "max": 600.0, "step": 1.0,
"tooltip": "Duration in seconds (-1 = model decides)",
}),
"time_signature": ("STRING", {
"default": "4",
"tooltip": "Time signature (e.g. 2, 3, 4, 6). Empty = auto.",
}),
"repaint_start": ("FLOAT", {
"default": 0.0, "min": 0.0, "max": 600.0, "step": 0.1,
"tooltip": "Repaint region start time in seconds",
}),
"repaint_end": ("FLOAT", {
"default": 0.0, "min": 0.0, "max": 600.0, "step": 0.1,
"tooltip": "Repaint region end time in seconds (0 = full length)",
}),
"refer_audio": ("AUDIO", {
"tooltip": "Reference audio for style/timbre guidance",
}),
"src_audio": ("AUDIO", {
"tooltip": "Source audio for cover/remix/repaint",
}),
"audio_codes": ("STRING", {
"default": "",
"forceInput": True,
"tooltip": "Audio codes from Audio Codes node",
}),
},
}
def build(self, sample_mode, vocal_language,
sample_query="", is_instrumental=False,
caption=DEFAULT_CAPTION, lyrics=DEFAULT_LYRICS,
auto=True, cover_strength=0.0, remix_strength=1.0, is_repaint=False,
bpm=120, key="", duration=30.0, time_signature="4",
repaint_start=0.0, repaint_end=0.0,
refer_audio=None, src_audio=None, audio_codes=""):
codes = audio_codes.strip() if audio_codes else ""
has_src = src_audio is not None
has_codes = bool(codes)
if is_repaint and has_src:
task_type = "repaint"
elif has_src or has_codes:
task_type = "cover"
else:
task_type = "text2music"
if sample_mode:
instrumental = is_instrumental
else:
instrumental = not lyrics.strip()
return ({
"task_type": task_type,
"sample_mode": sample_mode,
"sample_query": sample_query.strip() if sample_mode else "",
"caption": caption,
"lyrics": lyrics,
"vocal_language": vocal_language,
"instrumental": instrumental,
"bpm": 0 if auto else bpm,
"key_scale": "" if auto else key,
"duration": -1.0 if auto else duration,
"time_signature": "" if auto else time_signature,
"auto_metas": auto,
"cover_strength": cover_strength,
"remix_strength": remix_strength,
"repaint_start": repaint_start,
"repaint_end": repaint_end,
"refer_audio": refer_audio,
"src_audio": src_audio,
"audio_codes": codes,
},)
# =============================================================================
# Node: Settings
# =============================================================================
class AceStepSettings:
"""Inference settings: LM + DiT parameters."""
CATEGORY = "api node/audio/ACE-Step"
FUNCTION = "build"
RETURN_TYPES = ("ACESTEP_SETTINGS",)
RETURN_NAMES = ("settings",)
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"seed": ("STRING", {"default": "-1", "tooltip": "-1 = random"}),
"thinking": ("BOOLEAN", {
"default": True,
"tooltip": "Enable 5Hz LM audio code generation (llm_dit mode)",
}),
"use_cot_caption": ("BOOLEAN", {
"default": True,
"tooltip": "LLM rewrites/enhances caption via CoT",
}),
"use_cot_language": ("BOOLEAN", {
"default": True,
"tooltip": "LLM auto-detects vocal language",
}),
"temperature": ("FLOAT", {
"default": 0.85, "min": 0.0, "max": 2.0, "step": 0.05,
"tooltip": "LM sampling temperature",
}),
"lm_cfg_scale": ("FLOAT", {
"default": 2.0, "min": 1.0, "max": 5.0, "step": 0.1,
"tooltip": "LM classifier-free guidance scale",
}),
"lm_top_p": ("FLOAT", {
"default": 0.9, "min": 0.0, "max": 1.0, "step": 0.01,
"tooltip": "LM nucleus sampling top-p",
}),
"lm_top_k": ("INT", {
"default": 0, "min": 0, "max": 200, "step": 1,
"tooltip": "LM top-k sampling (0 = disabled)",
}),
"dit_guidance_scale": ("FLOAT", {
"default": 7.0, "min": 0.0, "max": 20.0, "step": 0.5,
"tooltip": "DiT classifier-free guidance scale",
}),
"dit_inference_steps": ("INT", {
"default": 8, "min": 1, "max": 200, "step": 1,
"tooltip": "DiT diffusion steps (turbo default = 8)",
}),
"dit_infer_method": (["ode", "sde"], {
"default": "ode",
"tooltip": "DiT ODE/SDE inference method",
}),
},
}
def build(self, seed, thinking, use_cot_caption, use_cot_language,
temperature, lm_cfg_scale, lm_top_p, lm_top_k,
dit_guidance_scale, dit_inference_steps, dit_infer_method):
return ({
"seed": seed,
"thinking": thinking,
"use_cot_caption": use_cot_caption,
"use_cot_language": use_cot_language,
"temperature": temperature,
"lm_cfg_scale": lm_cfg_scale,
"lm_top_p": lm_top_p,
"lm_top_k": lm_top_k,
"dit_guidance_scale": dit_guidance_scale,
"dit_inference_steps": dit_inference_steps,
"dit_infer_method": dit_infer_method,
},)
# =============================================================================
# Shared: build request body for text2music / repaint Server nodes
# =============================================================================
def _build_request_body(gen_params: dict, settings: dict) -> dict:
gp = gen_params
st = settings
is_sample_mode = gp.get("sample_mode", False)
sample_query = gp.get("sample_query", "")
audio_list = []
if gp.get("refer_audio") is not None:
audio_list.append(gp["refer_audio"])
if gp.get("src_audio") is not None:
audio_list.append(gp["src_audio"])
prompt = sample_query if is_sample_mode else gp.get("caption", "")
content = _build_multimodal_content(prompt, audio_list)
task_type = gp.get("task_type", "text2music")
has_src = gp.get("src_audio") is not None
has_codes = bool((gp.get("audio_codes", "") or "").strip())
if task_type == "text2music" and (has_src or has_codes):
task_type = "cover"
body = {
"model": "acemusic/acestep-v15-turbo",
"messages": [{"role": "user", "content": content}],
"modalities": ["audio"],
"stream": False,
"task_type": task_type,
"thinking": st.get("thinking", True),
"temperature": st.get("temperature", 0.85),
"top_p": st.get("lm_top_p", 0.9),
"use_cot_caption": st.get("use_cot_caption", True),
"use_cot_language": st.get("use_cot_language", True),
"use_cot_metas": gp.get("auto_metas", True),
"guidance_scale": st.get("dit_guidance_scale", 7.0),
"audio_config": {
"format": "wav",
"vocal_language": gp.get("vocal_language", "en"),
"instrumental": gp.get("instrumental", False),
},
}
if is_sample_mode:
body["sample_mode"] = True
lm_cfg = st.get("lm_cfg_scale")
if lm_cfg is not None:
body["lm_cfg_scale"] = lm_cfg
lm_top_k = st.get("lm_top_k", 0)
if lm_top_k and lm_top_k > 0:
body["top_k"] = lm_top_k
steps = st.get("dit_inference_steps")
if steps is not None:
body["inference_steps"] = steps
method = st.get("dit_infer_method")
if method:
body["infer_method"] = method
duration = gp.get("duration", -1.0)
if duration and duration > 0:
body["audio_config"]["duration"] = duration
bpm = gp.get("bpm", 0)
if bpm and bpm > 0:
body["audio_config"]["bpm"] = bpm
key_scale = (gp.get("key_scale", "") or "").strip()
if key_scale:
body["audio_config"]["key_scale"] = key_scale
time_sig = gp.get("time_signature", "")
if time_sig:
body["audio_config"]["time_signature"] = time_sig
lyrics = gp.get("lyrics", "")
if lyrics and not is_sample_mode:
body["lyrics"] = lyrics
seed_str = str(st.get("seed", "-1")).strip().split(",")[0].strip()
if seed_str and seed_str != "-1":
try:
int(seed_str)
except ValueError:
raise RuntimeError(f"Invalid seed: '{seed_str}'")
body["seed"] = seed_str
# Cover/remix: server handles audio2code internally
if task_type == "cover":
body["thinking"] = False
body["use_cot_caption"] = False
body["use_cot_language"] = False
body["use_cot_metas"] = False
rs = gp.get("remix_strength", 1.0)
if rs is not None:
body["audio_cover_strength"] = rs
cs = gp.get("cover_strength", 0.0)
if cs is not None and cs > 0:
body["cover_noise_strength"] = cs
# Repaint: LM is not used
if task_type == "repaint":
body["thinking"] = False
body["use_cot_caption"] = False
body["use_cot_language"] = False
body["use_cot_metas"] = False
body["repainting_start"] = gp.get("repaint_start", 0.0)
rend = gp.get("repaint_end", 0.0)
if rend and rend > 0:
body["repainting_end"] = rend
audio_codes = gp.get("audio_codes", "")
if body.get("thinking", False):
pass
elif audio_codes:
body["audio_codes"] = audio_codes
return body
# =============================================================================
# Node: Text2music Server
# =============================================================================
class AceStepText2MusicServer:
"""Text2music / cover / remix / repaint server.
Inputs: serve_config fields + gen_params + settings.
Outputs: audio + info + audio_codes."""
CATEGORY = "api node/audio/ACE-Step"
FUNCTION = "generate"
RETURN_TYPES = ("AUDIO", "STRING", "STRING")
RETURN_NAMES = ("audio", "info", "audio_codes")
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"mode": (["cloud", "local"], {"default": "cloud"}),
"server_url": ("STRING", {"default": "https://api.acemusic.ai"}),
"gen_params": ("ACESTEP_GEN_PARAMS", {}),
"settings": ("ACESTEP_SETTINGS", {}),
},
"optional": {
"api_key": ("STRING", {"default": ""}),
},
}
@classmethod
def IS_CHANGED(cls, **kwargs):
return float("NaN")
def generate(self, mode, server_url, gen_params, settings, api_key=""):
url = server_url.strip()
if not url:
url = "http://127.0.0.1:8002" if mode == "local" else "https://api.acemusic.ai"
base = url.rstrip("/")
headers = _make_headers(api_key)
body = _build_request_body(gen_params, settings)
result = _post_json(f"{base}/v1/chat/completions", body, headers)
audio, text_content = _parse_audio_response(result)
out_codes = ""
choices = result.get("choices", [])
if choices:
msg = choices[0].get("message", {})
out_codes = msg.get("audio_codes", "") or ""
return (audio, text_content, out_codes)
# =============================================================================
# Node: Show Text (minimal text display, no external dependencies)
# =============================================================================
class AceStepShowText:
"""Display any STRING input as text."""
CATEGORY = "api node/audio/ACE-Step"
FUNCTION = "show"
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("text",)
OUTPUT_NODE = True
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"text": ("STRING", {"forceInput": True}),
},
}
def show(self, text):
return {"ui": {"text": [text]}, "result": (text,)}