You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
872 B

import requests
from urllib.parse import quote
import subprocess
import os
import sys
import re
letter_year = sys.argv[1]
fn = f"./{letter_year}/bh-annual-letter-{letter_year}.txt"
output_dir = f"./{letter_year}/"
speaker_id="p230"
subprocess.run(['mkdir', '-p', output_dir])
with open(fn) as f:
lines = f.readlines()
all_text = ''.join(lines)
sentences = re.split(r"\w\w+\.[\s\n]", all_text)
count = len(sentences)
for (i, sentence) in enumerate(sentences):
text_prompt = quote(sentence)
# If hosted on IPv6 use http://[::1]:5002
# If hosted on IPv4 use http://localhost:5002
query_string = f"http://\[::1\]:5002/api/tts?text={text_prompt}&style_wav=&language_id="
print(f"Query string {query_string}")
subprocess.run(['curl', query_string, '-o', f"./{output_dir}/output-{str(i).zfill(3)}.wav"])