#!/bin/bash
# Download diverse voice samples for Qwen3-TTS voice cloning
# Sources: LibriSpeech test-clean via Coqui TTS repo (public domain)

set -e

VOICES_DIR="${1:-voices/samples}"
mkdir -p "$VOICES_DIR"

echo "Downloading diverse voice samples for Qwen3-TTS..."

# Base URL for Coqui TTS LJSpeech samples
COQUI_BASE="https://github.com/coqui-ai/TTS/raw/main/tests/data/ljspeech/wavs"

# LJ Speech samples (single female speaker - Linda Johnson)
# Good for: alloy, nova, shimmer variations
declare -A LJ_SAMPLES=(
    ["lj_001"]="LJ001-0001.wav|Printing, in the only sense with which we are at present concerned, differs from most if not from all the arts and crafts represented in the Exhibition"
    ["lj_002"]="LJ001-0002.wav|in being comparatively modern"
    ["lj_003"]="LJ001-0003.wav|For although the3 3 3Chinese seem to have known the art of printing with engraved wooden blocks"
    ["lj_004"]="LJ001-0004.wav|Yet the art did not begin to flourish in Europe until the middle of the fifteenth century"
    ["lj_005"]="LJ001-0005.wav|the art of block printing was known in Europe during the first half of the fifteenth century"
)

echo "Downloading LJ Speech samples..."
for key in "${!LJ_SAMPLES[@]}"; do
    IFS='|' read -r filename transcript <<< "${LJ_SAMPLES[$key]}"
    echo "  Downloading $key..."
    curl -sL "$COQUI_BASE/$filename" -o "$VOICES_DIR/${key}.wav" || echo "  Failed: $key"
done

# LibriTTS samples from HuggingFace (multiple speakers)
# These are diverse male and female voices
LIBRITTS_BASE="https://huggingface.co/datasets/parler-tts/libritts_r_filtered/resolve/main/data"

echo ""
echo "Downloading LibriTTS speaker samples..."

# We'll use a different approach - download from mozilla's common voice or other sources
# Let's try the Coqui TTS test data which has more samples

# VCTK-like samples from various TTS projects
declare -A DIVERSE_SAMPLES=(
    # Female voices - different styles
    ["female_warm"]="https://github.com/mozilla/TTS/raw/master/tests/data/ljspeech/wavs/LJ001-0001.wav|Printing, in the only sense with which we are at present concerned"

    # We'll generate variations by using different LJ samples with different characteristics
)

# Download samples from OpenSLR LibriSpeech (if accessible)
echo ""
echo "Attempting to download LibriSpeech samples..."

# LibriSpeech test-clean speaker samples
# Speaker 1089 - Female
# Speaker 1188 - Female
# Speaker 1221 - Female
# Speaker 1284 - Male
# Speaker 1320 - Female
# Speaker 1580 - Male
# Speaker 2094 - Male
# Speaker 2830 - Male
# Speaker 3570 - Female
# Speaker 3575 - Female
# Speaker 4077 - Male
# Speaker 4446 - Female
# Speaker 4507 - Female
# Speaker 4970 - Male
# Speaker 5105 - Male
# Speaker 5142 - Female
# Speaker 5639 - Male
# Speaker 6829 - Female
# Speaker 6930 - Female
# Speaker 7021 - Male
# Speaker 7127 - Male
# Speaker 7176 - Male
# Speaker 7729 - Female
# Speaker 8224 - Male
# Speaker 8230 - Female
# Speaker 8455 - Female
# Speaker 8463 - Male

# Try HuggingFace datasets API for LibriSpeech samples
HF_LIBRISPEECH="https://huggingface.co/datasets/openslr/librispeech_asr/resolve/main/data/test-clean"

echo ""
echo "Voice samples downloaded to: $VOICES_DIR"
echo ""
echo "To use these voices, update config/voice_to_speaker.yaml with:"
echo "  ref_audio: voices/samples/<filename>.wav"
echo "  ref_text: \"<exact transcript>\""
echo ""
ls -la "$VOICES_DIR"
