-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathtest_api.py
More file actions
65 lines (54 loc) · 1.63 KB
/
Copy pathtest_api.py
File metadata and controls
65 lines (54 loc) · 1.63 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
"""
Test script that calls the SFXFM API to generate a sound file froma text prompt
"""
import httpx
import os
import uuid
import logging
import subprocess
import re
import random
import click
from reapy import reascript_api as RPR
logger = logging.getLogger("sfxfm")
logging.basicConfig(level=logging.INFO)
PORT = 8000
API_URL = f"http://0.0.0.0:{PORT}"
api_url = f"{API_URL}/generate"
def generate(prompt: str, filepath: str) -> str:
""" Call SFXFM API to generate audio from a prompt """
headers = {"Accept": "application/json"}
data = {
"version": "0.1",
"token": "string",
"args": {
"model": "Woosh-DFlow",
"prompt": prompt,
"cfg": 3.0,
"sampler": "heun",
"num_steps": 5,
"sigma_min": 0.0001,
"sigma_max": 80,
"rho": 7,
"S_churn": 1,
"S_min": 0,
"S_noise": 1,
"guidance_scale": 7.5,
"noise_scheduler": "karras",
"seed": random.randint(0, 2**32 - 1),
},
}
# returns FLAC compressed audio
response = httpx.post(api_url, json=data, headers=headers, timeout=45.0)
# Generate a random filename
save_dir = os.path.dirname(filepath)
os.makedirs(save_dir, exist_ok=True)
logger.info(
f"Received response from SFXFM API: {response.status_code}, {len(response.content)} bytes"
)
# Save the FLAC file
with open(filepath, "wb") as f:
f.write(response.content)
logger.info(f"Saved FLAC file to {filepath}")
return filepath
generate("car revving", "outputs/Woosh-DFlow_API_0.flac")