-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_speech_samples.py
64 lines (51 loc) · 2.67 KB
/
generate_speech_samples.py
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
import os
import requests
from tqdm import tqdm
MALE_VOICE = "Andrew"
FEMALE_VOICE = "Ava"
TEXT_TO_SPEECH_URL = "http://localhost:5379"
TEXT_TO_SPEECH_ENDPOINT = f"{TEXT_TO_SPEECH_URL}/text_to_speech"
SPEECH_SAMPLE_DIR = "shared/input"
def generate_speech_samples():
speeches = [
"The quick brown fox jumps over the lazy dog.",
"Where do bright violets bloom in relation to ancient oaks?",
# "Complex systems evolve from simple rules.",
# "Thunderstorms could delay the early morning flight.",
"A murmuration of starlings filled the dusky sky.",
# "She sells seashells by the seashore.",
# "The mysterious manuscript contained unfamiliar symbols.",
# "Artificial intelligence transforms industries globally.",
"What type of melody did the jazz saxophonist play?",
# "Climate change affects global weather patterns.",
"Quantum computing revolutionizes data processing, offering solutions to previously unsolvable problems.",
# "Digital encryption secures online transactions, right?",
# "Ancient civilizations crafted remarkable artifacts.",
# "The culinary artist designed a five-course meal.",
# "How do renewable energy sources impact carbon emissions?",
# "Theoretical physics explores multidimensional spaces.",
# "Quantum computing revolutionizes data processing.",
"The ancient library contained manuscripts that chronicled the lost civilization's history and knowledge.",
# "Bioluminescent creatures light up the ocean depths.",
# "The geneticist decoded the DNA sequence efficiently.",
]
male_voice_lowercase = MALE_VOICE.lower()
male_output_dir = os.path.join(SPEECH_SAMPLE_DIR, male_voice_lowercase)
female_voice_lowercase = FEMALE_VOICE.lower()
female_output_dir = os.path.join(SPEECH_SAMPLE_DIR, female_voice_lowercase)
os.makedirs(male_output_dir, exist_ok=True)
os.makedirs(female_output_dir, exist_ok=True)
for index, speech in tqdm(enumerate(speeches)):
body = {"voice": MALE_VOICE, "inputText": speech}
response = requests.post(TEXT_TO_SPEECH_ENDPOINT, json=body)
file_path = os.path.join(male_output_dir, f"{index}.wav")
with open(file_path, "wb") as f:
f.write(response.content)
for index, speech in tqdm(enumerate(speeches)):
body = {"voice": FEMALE_VOICE, "inputText": speech}
response = requests.post(TEXT_TO_SPEECH_ENDPOINT, json=body)
file_path = os.path.join(female_output_dir, f"{index}.wav")
with open(file_path, "wb") as f:
f.write(response.content)
if __name__ == "__main__":
generate_speech_samples()