-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtts_and_audio.py
More file actions
90 lines (76 loc) · 2.14 KB
/
tts_and_audio.py
File metadata and controls
90 lines (76 loc) · 2.14 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
"""Text-to-speech and music generation examples.
Demonstrates TTS synthesis (with voice options) and music composition.
Usage:
export DEAPI_API_KEY="sk-your-api-key"
python examples/tts_and_audio.py
"""
from deapi import DeapiClient
client = DeapiClient()
# --- Text-to-speech ---
print("Generating speech...")
job = client.audio.synthesize(
text="Hello! Welcome to DeAPI, the distributed AI inference platform.",
model="Kokoro",
voice="af_sky",
lang="en-us",
format="mp3",
speed=1.0,
sample_rate=24000,
)
result = job.wait()
print(f"Audio URL: {result.result_url}")
# --- TTS with voice cloning ---
# Uncomment to run — requires a reference audio file (3-10 seconds):
#
# print("\nCloning voice...")
# job = client.audio.synthesize(
# text="This is generated using a cloned voice.",
# model="Kokoro",
# lang="en-us",
# format="wav",
# speed=1.0,
# sample_rate=24000,
# mode="voice_clone",
# ref_audio="voice_sample.wav", # 3-10 second reference clip
# ref_text="The original text spoken in the reference.",
# )
# result = job.wait()
# print(f"Cloned voice audio: {result.result_url}")
# --- TTS price calculation ---
price = client.audio.synthesize_price(
model="Kokoro",
lang="en-us",
format="mp3",
speed=1.0,
sample_rate=24000,
text="Hello! Welcome to DeAPI.",
)
print(f"\nTTS price: ${price.price}")
# You can also estimate price by character count:
price = client.audio.synthesize_price(
model="Kokoro",
lang="en-us",
format="mp3",
speed=1.0,
sample_rate=24000,
count_text=500, # 500 characters
)
print(f"Price for 500 chars: ${price.price}")
# --- Music generation ---
# Uncomment to run:
#
# print("\nComposing music...")
# job = client.audio.compose(
# caption="upbeat electronic track with synth leads and a driving bassline",
# model="MusicGen",
# duration=30, # 30 seconds
# inference_steps=50,
# guidance_scale=3.0,
# seed=42,
# format="mp3",
# lyrics="Dancing in the moonlight, feeling so alive",
# bpm=128,
# )
# result = job.wait()
# print(f"Music URL: {result.result_url}")
client.close()