# Python 3.10+: pip install comfy-sdk==0.4.0
import os
from comfy_sdk import Comfy
api_key = os.environ.get("COMFY_API_KEY", "").strip()
if not api_key: raise RuntimeError("Set COMFY_API_KEY")
os.environ.setdefault("COMFY_BASE_URL", "https://cloud.comfy.org")
client = Comfy(api_key=api_key)
workflow = client.workflows.from_json({
"1": {
"class_type": "FL_ChatterboxDialogTTS",
"inputs": {
"cfg_weight": 0.5,
"dialog_text": "SPEAKER A: Morning! Have you seen my tomatoes? They're nearly up to the gutter now.\nSPEAKER B: Up to the gutter? Mine passed the fence post on Tuesday, and I've got the photos to prove it.\nSPEAKER A: Photos can lie. Mine had nothing but compost, rain and a bit of encouragement.\nSPEAKER B: Encouragement? I heard a watering can out here at midnight, and it wasn't the rain.\nSPEAKER A: That was the cat. Honestly. Very thirsty cat.\nSPEAKER B: Right. Well, the cat's plants are lovely. How about a truce?\nSPEAKER A: Go on then. Your basil, my tomatoes, one big salad on Saturday.\nSPEAKER B: Deal. But I'm measuring them first.",
"exaggeration": 0.5,
"keep_model_loaded": False,
"seed": 776764013,
"speaker_A_Audio": [
"2",
0
],
"speaker_B_Audio": [
"4",
0
],
"temperature": 0.8,
"use_cpu": False
},
"_meta": {
"title": "FL Chatterbox Dialog TTS"
}
},
"2": {
"class_type": "LoadAudio",
"inputs": {
"audio": "UPLOADED_speaker_a_FILENAME"
},
"_meta": {
"title": "Load Audio"
}
},
"3": {
"class_type": "LoadAudio",
"inputs": {
"audio": "UPLOADED_speaker_b_FILENAME"
},
"_meta": {
"title": "Load Audio"
}
},
"4": {
"class_type": "AudioCrop",
"inputs": {
"audio": [
"3",
0
],
"end_time": "0:20",
"start_time": "0:00"
},
"_meta": {
"title": "AudioCrop"
}
},
"5": {
"class_type": "SaveAudioMP3",
"inputs": {
"audio": [
"1",
0
],
"filename_prefix": "audio/ComfyUI",
"quality": "V0"
},
"_meta": {
"title": "Save Audio (MP3) (DEPRECATED)"
}
}
})
workflow.set_input("2", "audio", client.assets.from_url("https://comfy.org/catalog-media/bcdc3265-05c4-4b91-bb15-8a2046f97f6a/61fc447b-4601-4874-88c5-2e3f9cb8f36e"))
workflow.set_input("3", "audio", client.assets.from_url("https://comfy.org/catalog-media/2adf64b3-0d8e-4e2c-8609-27d9aa88edf5/d1c2e9d1-4384-42ae-885f-a9f668968a65"))
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)
for output in job.get_outputs("5"):
output.to_file(output.name)