Spaces:
Running on Zero
Running on Zero
File size: 1,953 Bytes
e3290cf 3b029ca e3290cf 3b029ca e3290cf 3b029ca e3290cf 3b029ca e3290cf 3b029ca e3290cf 3b029ca e3290cf 3b029ca e3290cf 3b029ca e3290cf 3b029ca | 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 | """Example client for the OmniVoice ZeroGPU batch endpoint (Gradio API).
Usage:
pip install gradio_client
python client_example.py salmanbvps/omnivoice-batch-tts [ref.wav "ref transcript"]
Sends a batch (auto + voice-design, and -- if a ref wav is given -- voice-clone)
in a single API call and writes out_0.wav, out_1.wav, ...
"""
import base64
import json
import sys
from gradio_client import Client
def b64_file(path: str) -> str:
with open(path, "rb") as f:
return base64.b64encode(f.read()).decode("ascii")
def main():
if len(sys.argv) < 2:
print(__doc__)
sys.exit(1)
space = sys.argv[1] # "owner/space" or full URL
items = [
{"text": "Hello from OmniVoice, generated in a single batched call.",
"language": "en"},
{"text": "This voice was designed from a text instruction.",
"language": "en", "instruct": "female, british accent"},
]
if len(sys.argv) >= 3:
items.append({
"text": "And this one is cloned from your reference audio.",
"language": "en",
"ref_audio_b64": b64_file(sys.argv[2]),
"ref_text": sys.argv[3] if len(sys.argv) >= 4 else None,
})
payload = {"items": items, "num_step": 32, "guidance_scale": 2.0,
"audio_format": "wav"}
client = Client(space)
result = client.predict(json.dumps(payload), api_name="/batch")
data = result if isinstance(result, dict) else json.loads(result)
if "error" in data:
print("Error:", data["error"])
sys.exit(1)
for r in data["results"]:
i = r["index"]
if r["status"] != "success":
print(f"[{i}] ERROR: {r.get('error')}")
continue
out = f"out_{i}.wav"
with open(out, "wb") as f:
f.write(base64.b64decode(r["audio_b64"]))
print(f"[{i}] {r['duration']}s -> {out}")
if __name__ == "__main__":
main()
|