Skip to content
This repository was archived by the owner on Jan 2, 2023. It is now read-only.

Commit e5b9bc6

Browse files
committed
add in v3
1 parent ef9bedf commit e5b9bc6

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

birdcache_v3.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
from pprint import pprint
2+
import json
3+
import requests
4+
5+
6+
API_KEY = "YOUR_API_KEY_HERE"
7+
VOICE_NAME = "linda"
8+
ENDPOINT_URL = "https://v1.api.audio/birdcache"
9+
10+
the_sentence = "Hi {{username|friend}}, welcome to {{city|tallinn}}. It is {{weather|rainy}} today. Have a great {{day|day}}"
11+
audience = {
12+
"username": ["linda", "anne", "salih", "matt"],
13+
"city": ["istanbul", "tallinn", "london", "barcelona"],
14+
"weather": ["rainy", "sunny", "cloudy", "windy"],
15+
"day": ["monday", "friday", "sunday"],
16+
}
17+
mastering_sound_template = "openup"
18+
19+
20+
def birdcache_v3_speech():
21+
r = requests.post(
22+
url=ENDPOINT_URL,
23+
headers={"x-api-key": API_KEY},
24+
data=json.dumps(
25+
{
26+
"voice": VOICE_NAME,
27+
"type": "speech",
28+
"text": the_sentence,
29+
"audience": audience,
30+
}
31+
),
32+
)
33+
r = r.json()
34+
35+
pprint("speech text files produced:")
36+
for req in r:
37+
print(req["text"])
38+
39+
pprint("speech urls produced:")
40+
for req in r:
41+
print(req["text"] + " - " + (req["url"] if req["ready"] else "in progress"))
42+
43+
44+
def birdcache_v3_mastering():
45+
r = requests.post(
46+
url=ENDPOINT_URL,
47+
headers={"x-api-key": API_KEY},
48+
data=json.dumps(
49+
{
50+
"voice": VOICE_NAME,
51+
"type": "mastering",
52+
"text": the_sentence,
53+
"audience": audience,
54+
"soundTemplate": mastering_sound_template,
55+
}
56+
),
57+
)
58+
r = r.json()
59+
60+
pprint("speech text files produced:")
61+
for req in r:
62+
print(req["text"])
63+
64+
pprint("speech urls produced:")
65+
for req in r:
66+
print(req["text"] + " - " + (req["url"] if req["ready"] else "in progress"))
67+
68+
69+
birdcache_v3_speech()
70+
birdcache_v3_mastering()

0 commit comments

Comments
 (0)