{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "technological-hybrid",
   "metadata": {},
   "source": [
    "## Data prep"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "challenging-rotation",
   "metadata": {},
   "outputs": [],
   "source": [
    "# python examples/speech_synthesis/preprocessing/get_common_voice_audio_manifest.py \\\n",
    "#         --data-root /data-ssd-2/georg/data/commonvoice/cv-corpus-7.0-2021-07-21 \\\n",
    "#         --output-manifest-root /data-ssd-2/georg/data/fairseq/commonvoice/manifest \\\n",
    "#         --lang en \\\n",
    "#         --convert-to-wav"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "adolescent-hunter",
   "metadata": {},
   "outputs": [],
   "source": [
    "# for SPLIT in dev test train; do\n",
    "#     python examples/speech_synthesis/preprocessing/denoise_and_vad_audio.py \\\n",
    "#       --audio-manifest /data-ssd-2/georg/data/fairseq/commonvoice/manifest/${SPLIT}.audio.tsv \\\n",
    "#       --output-dir /data-ssd-2/georg/data/fairseq/commonvoice/processed_data \\\n",
    "#       --denoise --vad --vad-agg-level 2\n",
    "# done"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "entitled-presentation",
   "metadata": {},
   "source": [
    "## Option 1) no CER filtering"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "military-output",
   "metadata": {},
   "outputs": [],
   "source": [
    "for SPLIT in dev test train; do\n",
    "    python -m examples.speech_synthesis.preprocessing.get_feature_manifest \\\n",
    "        --audio-manifest-root /data-ssd-2/georg/data/fairseq/commonvoice/manifest \\\n",
    "        --output-root /data-ssd-2/georg/data/fairseq/commonvoice/feature_manifest \\\n",
    "        --ipa-vocab \\\n",
    "        --lang en \\\n",
    "        --snr-threshold 15\n",
    "done"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "urban-activation",
   "metadata": {},
   "source": [
    "## Option 2) CER filtering (TODO)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "residential-delicious",
   "metadata": {},
   "outputs": [],
   "source": [
    "for SPLIT in dev test train; do\n",
    "    python examples/speech_synthesis/evaluation/get_eval_manifest.py \\\n",
    "        --generation-root ${SAVE_DIR}/generate-${CHECKPOINT_NAME}-${SPLIT} \\\n",
    "        --audio-manifest /data-ssd-2/georg/data/fairseq/commonvoice/manifest/${SPLIT}.audio.tsv \\\n",
    "        --output-path /data-ssd-2/georg/data/fairseq/commonvoice/eval_output/eval.tsv \\\n",
    "        --vocoder griffin_lim \\\n",
    "        --sample-rate 22050 \\\n",
    "        --audio-format flac \\\n",
    "        --use-resynthesized-target \\\n",
    "        --eval-target\n",
    "done"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "arctic-wound",
   "metadata": {},
   "outputs": [],
   "source": [
    "for SPLIT in dev test train; do\n",
    "    python examples/speech_synthesis/evaluation/eval_asr.py \\\n",
    "        --audio-header syn \\\n",
    "        --text-header text \\\n",
    "        --err-unit char --split ${SPLIT} \\\n",
    "        --w2v-ckpt ${WAV2VEC2_CHECKPOINT_PATH} \\\n",
    "        --w2v-dict-dir ${WAV2VEC2_DICT_DIR} \\\n",
    "        --raw-manifest /data-ssd-2/georg/data/fairseq/commonvoice/eval_output/eval_16khz.tsv \\\n",
    "        --asr-dir /data-ssd-2/georg/data/fairseq/commonvoice/eval_output/asr \\\n",
    "        --err-unit char\n",
    "done"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "comfortable-particular",
   "metadata": {},
   "outputs": [],
   "source": [
    "for SPLIT in dev test train; do\n",
    "    python -m examples.speech_synthesis.preprocessing.get_feature_manifest \\\n",
    "        --audio-manifest-root /data-ssd-2/georg/data/fairseq/commonvoice/manifest \\\n",
    "        --output-root /data-ssd-2/georg/data/fairseq/commonvoice/feature_manifest \\\n",
    "        --ipa-vocab \\\n",
    "        --lang en \\\n",
    "        --snr-threshold 15 \\\n",
    "        --cer-threshold 0.1 \\\n",
    "        --cer-tsv-path /data-ssd-2/georg/data/fairseq/commonvoice/eval_output/uer_cer.${SPLIT}.tsv\n",
    "done"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "binding-amazon",
   "metadata": {},
   "source": [
    "## Inference"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "exclusive-touch",
   "metadata": {},
   "outputs": [],
   "source": [
    "SPLIT=test python examples/speech_synthesis/generate_waveform.py \\\n",
    "    /data-ssd-2/georg/data/fairseq/commonvoice/feature_manifest \\\n",
    "    --config-yaml config.yaml \\\n",
    "    --gen-subset ${SPLIT} \\\n",
    "    --task text_to_speech \\\n",
    "    --path /data-ssd-2/georg/models/cv4_en200_transformer_phn/checkpoint_avg_last_5.pt \\\n",
    "    --max-tokens 50000 \\\n",
    "    --spec-bwd-max-iter 32 \\\n",
    "    --dump-waveforms"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "afraid-squad",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "color-ordinance",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "destroyed-taiwan",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "chief-situation",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "mysterious-stress",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "integral-pattern",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cardiovascular-shannon",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
