Skip to content

A TTS that fits in your CPU (and pocket)

Python

Add Colab example (#67)

Václav Volhejn6f9dd250c24e
diff --git a/README.md b/README.md
index 6c3824d..135cb4d 100644
--- a/README.md
+++ b/README.md
@@ -59,6 +59,8 @@ for each voice.
* [azelma](https://huggingface.co/kyutai/tts-voices/blob/main/vctk/p303_023.wav)
The `--voice` argument can also take a plain wav file as input for voice cloning.
+You can use your own or check out our [voice repository](https://huggingface.co/kyutai/tts-voices).
+
Feel free to check out the [generate documentation](https://github.com/kyutai-labs/pocket-tts/tree/main/docs/generate.md) for more details and examples.
For trying multiple voices and prompts quickly, prefer using the `serve` command.
@@ -76,6 +78,8 @@ You can check out the [serve documentation](https://github.com/kyutai-labs/pocke
## Using it as a Python library
+You can try out the Python library on Colab [here](https://colab.research.google.com/github/kyutai-labs/pocket-tts/blob/main/docs/pocket-tts-example.ipynb).
+
Install the package with
```bash
pip install pocket-tts
@@ -90,7 +94,10 @@ import scipy.io.wavfile
tts_model = TTSModel.load_model()
voice_state = tts_model.get_state_for_audio_prompt(
- "hf://kyutai/tts-voices/alba-mackenna/casual.wav"
+ "alba" # One of the pre-made voices, see above
+ # You can also use any voice file you have locally or from Hugging Face:
+ # "./some_audio.wav"
+ # or "hf://kyutai/tts-voices/expresso/ex01-ex02_default_001_channel2_198s.wav"
)
audio = tts_model.generate_audio(voice_state, "Hello world, this is a test.")
# Audio is a 1D torch tensor containing PCM data.
diff --git a/docs/pocket-tts-example.ipynb b/docs/pocket-tts-example.ipynb
new file mode 100644
index 0000000..2914070
--- /dev/null
+++ b/docs/pocket-tts-example.ipynb
@@ -0,0 +1,80 @@
+{
+ "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
+}