import requests
from urllib.parse import quote
import subprocess
import os
import sys

speaker_id="p230"

letter_year = sys.argv[1]

fn = f"./annual-letters/bpl-{letter_year}.txt"

output_dir = f"./wavs/bpl-{letter_year}/"

subprocess.run(['mkdir', '-p', output_dir])

with open(fn) as f:
    lines = f.readlines()
    all_text = ''.join(lines)
    sentences = all_text.split('.')
    count = len(sentences)

    for (i, sentence) in enumerate(sentences):
        text_prompt = quote(sentence)
        query_string = f"http://localhost:5002/api/tts?text={text_prompt}&speaker_id={speaker_id}&style_wav=&language_id="
        subprocess.run(['curl', query_string, '-o', f"./{output_dir}/output-{str(i).zfill(3)}.wav"])

