#!/bin/bash
# Download voice samples for Qwen3-TTS voice cloning
# Uses LibriSpeech test-clean samples (CC BY 4.0)

set -e

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

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

# LibriSpeech test-clean has good quality samples with transcripts
# We'll use samples from different speakers for variety

# Download a small subset from HuggingFace
# These are curated samples for the 6 OpenAI-compatible voice types:
# - alloy: neutral/balanced
# - echo: male, clear
# - fable: expressive/storyteller
# - onyx: deep male
# - nova: female, warm
# - shimmer: female, soft

# Using LibriVox/LibriSpeech samples (public domain audiobooks)
# Format: Speaker reads a passage, we take a clean 3-10 second clip

cat << 'EOF'
Voice samples need to be:
- 3-10 seconds of clear speech
- Single speaker, no background noise
- WAV format (16kHz or higher)
- With exact transcript

Recommended sources:
1. LibriSpeech test-clean: https://www.openslr.org/12
2. VCTK: https://datashare.ed.ac.uk/handle/10283/3443
3. LJ Speech: https://keithito.com/LJ-Speech-Dataset/

For now, using Qwen's demo sample for all voices.
To add distinct voices, place WAV files in voices/samples/ and update
config/voice_to_speaker.yaml with paths and transcripts.

Example voice_to_speaker.yaml entry:
  alloy:
    ref_audio: voices/samples/alloy.wav
    ref_text: "The exact words spoken in the audio file."
    language: English
EOF

# Download LJ Speech sample (public domain) since Qwen's Alibaba Cloud URL is blocked
echo "Downloading LJ Speech sample..."
curl -L -o "$VOICES_DIR/lj_speech.wav" \
  "https://github.com/coqui-ai/TTS/raw/main/tests/data/ljspeech/wavs/LJ001-0001.wav" 2>/dev/null || \
  echo "Failed to download LJ Speech sample"

# Check if we have the sample
if [ -f "$VOICES_DIR/lj_speech.wav" ]; then
  echo "Downloaded: $VOICES_DIR/lj_speech.wav"
  echo "Transcript: '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'"
else
  echo "Warning: Could not download voice sample"
fi

echo ""
echo "To add more voices, you can:"
echo "1. Record your own samples (3-10 seconds, clear speech)"
echo "2. Download from LibriSpeech: https://www.openslr.org/12"
echo "3. Use VCTK dataset: https://datashare.ed.ac.uk/handle/10283/3443"
echo ""
echo "Then update config/voice_to_speaker.yaml with the paths and transcripts."
