{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "OiFxAw6MoHnp"
   },
   "outputs": [],
   "source": [
    "# Locally, we recommend using `uv` over `pip`\n",
    "!pip install pocket-tts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "FfBHOrFcU0gI"
   },
   "outputs": [],
   "source": [
    "import scipy.io.wavfile\n",
    "from IPython.display import Audio\n",
    "\n",
    "from pocket_tts import TTSModel\n",
    "\n",
    "# The pre-defined voices are alba, marius, javert, jean, fantine, cosette, eponine, and azelma.\n",
    "# You can also clone any voice you'd like by passing a file path!\n",
    "# For voice cloning, please go to https://huggingface.co/kyutai/pocket-tts\n",
    "# and accept the terms, then make sure you're logged in locally with `uvx hf auth login`.\n",
    "voice = \"alba\"\n",
    "\n",
    "tts_model = TTSModel.load_model()\n",
    "voice_state = tts_model.get_state_for_audio_prompt(voice)\n",
    "\n",
    "# Audio is a 1D torch tensor containing PCM data\n",
    "audio = tts_model.generate_audio(voice_state, \"Hello world, this is a test.\")\n",
    "\n",
    "# You can also find the output in the files tab on the left\n",
    "scipy.io.wavfile.write(\"output.wav\", tts_model.sample_rate, audio.numpy())\n",
    "\n",
    "Audio(audio.numpy(), rate=tts_model.sample_rate)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "gbnHfLwbo5W8"
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "colab": {
   "provenance": []
  },
  "kernelspec": {
   "display_name": "pocket-tts",
   "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.10.16"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
