Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix python install and upgrade versions to allow 3.11 installation #374

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,18 @@ if(NOT DEFINED SPDLOG_DIR)
add_dependencies(test_piper spdlog_external)
endif()

# ---- piper-phonemize ---

# ---- piper-phonemize ---
set(PIPER_PHONEMIZE_REPO $ENV{PIPER_PHONEMIZE_REPO})
if(NOT DEFINED PIPER_PHONEMIZE_REPO)
set(ESPEAK_NG_REPO "https://github.com/jmfrank63/piper-phonemize.git")
endif()
if(NOT DEFINED PIPER_PHONEMIZE_DIR)
set(PIPER_PHONEMIZE_DIR "${CMAKE_CURRENT_BINARY_DIR}/pi")
ExternalProject_Add(
piper_phonemize_external
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/p"
URL "https://github.com/rhasspy/piper-phonemize/archive/refs/heads/master.zip"
URL "${PIPER_PHONEMIZE_REPO}/archive/refs/heads/master.zip"
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${PIPER_PHONEMIZE_DIR}
)
add_dependencies(piper piper_phonemize_external)
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
all:
cmake -Bbuild -DCMAKE_INSTALL_PREFIX=install
cmake --build build --config Release
cd build && ctest --config Release
@if [ "$(OS)" != "Windows_NT" ]; then \
cd build && ctest --config Release; \
fi
cmake --install build

docker:
Expand Down
184 changes: 100 additions & 84 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,85 +1,97 @@
![Piper logo](etc/logo.png)
# ![Piper logo](etc/logo.png)

A fast, local neural text to speech system that sounds great and is optimized for the Raspberry Pi 4.
Piper is used in a [variety of projects](#people-using-piper).
A fast, local neural text to speech system that sounds great and is optimized for the Raspberry
Pi 4. Piper is used in a [variety of projects](#people-using-piper).

``` sh
```sh
echo 'Welcome to the world of speech synthesis!' | \
./piper --model en_US-lessac-medium.onnx --output_file welcome.wav
piper --model en_US-lessac-medium --output_file welcome.wav
```

[Listen to voice samples](https://rhasspy.github.io/piper-samples) and check out a [video tutorial by Thorsten Müller](https://youtu.be/rjq5eZoWWSo)
[Listen to voice samples](https://rhasspy.github.io/piper-samples) and check out a
[video tutorial by Thorsten Müller](https://youtu.be/rjq5eZoWWSo)

[![Sponsored by Nabu Casa](etc/nabu_casa_sponsored.png)](https://nabucasa.com)

Voices are trained with [VITS](https://github.com/jaywalnut310/vits/) and exported to the [onnxruntime](https://onnxruntime.ai/).
Voices are trained with [VITS](https://github.com/jaywalnut310/vits/) and exported to the
[onnxruntime](https://onnxruntime.ai/).

## Voices

Our goal is to support Home Assistant and the [Year of Voice](https://www.home-assistant.io/blog/2022/12/20/year-of-voice/).

[Download voices](https://huggingface.co/rhasspy/piper-voices/tree/v1.0.0) for the supported languages:

* Arabic (ar_JO)
* Catalan (ca_ES)
* Czech (cs_CZ)
* Danish (da_DK)
* German (de_DE)
* Greek (el_GR)
* English (en_GB, en_US)
* Spanish (es_ES, es_MX)
* Finnish (fi_FI)
* French (fr_FR)
* Hungarian (hu_HU)
* Icelandic (is_IS)
* Italian (it_IT)
* Georgian (ka_GE)
* Kazakh (kk_KZ)
* Luxembourgish (lb_LU)
* Nepali (ne_NP)
* Dutch (nl_BE, nl_NL)
* Norwegian (no_NO)
* Polish (pl_PL)
* Portuguese (pt_BR, pt_PT)
* Romanian (ro_RO)
* Russian (ru_RU)
* Serbian (sr_RS)
* Swedish (sv_SE)
* Swahili (sw_CD)
* Turkish (tr_TR)
* Ukrainian (uk_UA)
* Vietnamese (vi_VN)
* Chinese (zh_CN)
Our goal is to support Home Assistant and the
[Year of Voice](https://www.home-assistant.io/blog/2022/12/20/year-of-voice/).

[Download voices](https://huggingface.co/rhasspy/piper-voices/tree/v1.0.0) for the supported
languages:

- Arabic (ar_JO)
- Catalan (ca_ES)
- Czech (cs_CZ)
- Danish (da_DK)
- German (de_DE)
- Greek (el_GR)
- English (en_GB, en_US)
- Spanish (es_ES, es_MX)
- Finnish (fi_FI)
- French (fr_FR)
- Hungarian (hu_HU)
- Icelandic (is_IS)
- Italian (it_IT)
- Georgian (ka_GE)
- Kazakh (kk_KZ)
- Luxembourgish (lb_LU)
- Nepali (ne_NP)
- Dutch (nl_BE, nl_NL)
- Norwegian (no_NO)
- Polish (pl_PL)
- Portuguese (pt_BR, pt_PT)
- Romanian (ro_RO)
- Russian (ru_RU)
- Serbian (sr_RS)
- Swedish (sv_SE)
- Swahili (sw_CD)
- Turkish (tr_TR)
- Ukrainian (uk_UA)
- Vietnamese (vi_VN)
- Chinese (zh_CN)

You will need two files per voice:

1. A `.onnx` model file, such as [`en_US-lessac-medium.onnx`](https://huggingface.co/rhasspy/piper-voices/resolve/v1.0.0/en/en_US/lessac/medium/en_US-lessac-medium.onnx)
2. A `.onnx.json` config file, such as [`en_US-lessac-medium.onnx.json`](https://huggingface.co/rhasspy/piper-voices/resolve/v1.0.0/en/en_US/lessac/medium/en_US-lessac-medium.onnx.json)

The `MODEL_CARD` file for each voice contains important licensing information. Piper is intended for text to speech research, and does not impose any additional restrictions on voice models. Some voices may have restrictive licenses, however, so please review them carefully!
1. A `.onnx` model file, such as
[`en_US-lessac-medium.onnx`](https://huggingface.co/rhasspy/piper-voices/resolve/v1.0.0/en/en_US/lessac/medium/en_US-lessac-medium.onnx)
2. A `.onnx.json` config file, such as
[`en_US-lessac-medium.onnx.json`](https://huggingface.co/rhasspy/piper-voices/resolve/v1.0.0/en/en_US/lessac/medium/en_US-lessac-medium.onnx.json)

The `MODEL_CARD` file for each voice contains important licensing information. Piper is intended for
text to speech research, and does not impose any additional restrictions on voice models. Some
voices may have restrictive licenses, however, so please review them carefully!

## Installation

You can [run Piper with Python](#running-in-python) or download a binary release:

* [amd64](https://github.com/rhasspy/piper/releases/download/v1.2.0/piper_amd64.tar.gz) (64-bit desktop Linux)
* [arm64](https://github.com/rhasspy/piper/releases/download/v1.2.0/piper_arm64.tar.gz) (64-bit Raspberry Pi 4)
* [armv7](https://github.com/rhasspy/piper/releases/download/v1.2.0/piper_armv7.tar.gz) (32-bit Raspberry Pi 3/4)

If you want to build from source, see the [Makefile](Makefile) and [C++ source](src/cpp).
You must download and extract [piper-phonemize](https://github.com/rhasspy/piper-phonemize) to `lib/Linux-$(uname -m)/piper_phonemize` before building.
For example, `lib/Linux-x86_64/piper_phonemize/lib/libpiper_phonemize.so` should exist for AMD/Intel machines (as well as everything else from `libpiper_phonemize-amd64.tar.gz`).
- [amd64](https://github.com/rhasspy/piper/releases/download/v1.2.0/piper_amd64.tar.gz) (64-bit
desktop Linux)
- [arm64](https://github.com/rhasspy/piper/releases/download/v1.2.0/piper_arm64.tar.gz) (64-bit
Raspberry Pi 4)
- [armv7](https://github.com/rhasspy/piper/releases/download/v1.2.0/piper_armv7.tar.gz) (32-bit
Raspberry Pi 3/4)

If you want to build from source, see the [Makefile](Makefile) and [C++ source](src/cpp). You must
download and extract [piper-phonemize](https://github.com/rhasspy/piper-phonemize) to
`lib/Linux-$(uname -m)/piper_phonemize` before building. For example,
`lib/Linux-x86_64/piper_phonemize/lib/libpiper_phonemize.so` should exist for AMD/Intel machines (as
well as everything else from `libpiper_phonemize-amd64.tar.gz`).

## Usage

1. [Download a voice](#voices) and extract the `.onnx` and `.onnx.json` files
2. Run the `piper` binary with text on standard input, `--model /path/to/your-voice.onnx`, and `--output_file output.wav`
2. Run the `piper` binary with text on standard input, `--model /path/to/your-voice.onnx`, and
`--output_file output.wav`

For example:

``` sh
```sh
echo 'Welcome to the world of speech synthesis!' | \
./piper --model en_US-lessac-medium.onnx --output_file welcome.wav
```
Expand All @@ -92,86 +104,90 @@ See `piper --help` for more options.

Piper can stream raw audio to stdout as its produced:

``` sh
```sh
echo 'This sentence is spoken first. This sentence is synthesized while the first sentence is spoken.' | \
./piper --model en_US-lessac-medium.onnx --output-raw | \
aplay -r 22050 -f S16_LE -t raw -
```

This is **raw** audio and not a WAV file, so make sure your audio player is set to play 16-bit mono PCM samples at the correct sample rate for the voice.
This is **raw** audio and not a WAV file, so make sure your audio player is set to play 16-bit mono
PCM samples at the correct sample rate for the voice.

### JSON Input

The `piper` executable can accept JSON input when using the `--json-input` flag. Each line of input must be a JSON object with `text` field. For example:
The `piper` executable can accept JSON input when using the `--json-input` flag. Each line of input
must be a JSON object with `text` field. For example:

``` json
```json
{ "text": "First sentence to speak." }
{ "text": "Second sentence to speak." }
```

Optional fields include:

* `speaker` - string
* Name of the speaker to use from `speaker_id_map` in config (multi-speaker voices only)
* `speaker_id` - number
* Id of speaker to use from 0 to number of speakers - 1 (multi-speaker voices only, overrides "speaker")
* `output_file` - string
* Path to output WAV file

- `speaker` - string
- Name of the speaker to use from `speaker_id_map` in config (multi-speaker voices only)
- `speaker_id` - number
- Id of speaker to use from 0 to number of speakers - 1 (multi-speaker voices only, overrides
"speaker")
- `output_file` - string
- Path to output WAV file

The following example writes two sentences with different speakers to different files:

``` json
```json
{ "text": "First speaker.", "speaker_id": 0, "output_file": "/tmp/speaker_0.wav" }
{ "text": "Second speaker.", "speaker_id": 1, "output_file": "/tmp/speaker_1.wav" }
```


## People using Piper

Piper has been used in the following projects/papers:

* [Home Assistant](https://github.com/home-assistant/addons/blob/master/piper/README.md)
* [Rhasspy 3](https://github.com/rhasspy/rhasspy3/)
* [NVDA - NonVisual Desktop Access](https://www.nvaccess.org/post/in-process-8th-may-2023/#voices)
* [Image Captioning for the Visually Impaired and Blind: A Recipe for Low-Resource Languages](https://www.techrxiv.org/articles/preprint/Image_Captioning_for_the_Visually_Impaired_and_Blind_A_Recipe_for_Low-Resource_Languages/22133894)
* [Open Voice Operating System](https://github.com/OpenVoiceOS/ovos-tts-plugin-piper)
* [JetsonGPT](https://github.com/shahizat/jetsonGPT)
* [LocalAI](https://github.com/go-skynet/LocalAI)
* [Lernstick EDU / EXAM: reading clipboard content aloud with language detection](https://lernstick.ch/)
- [Home Assistant](https://github.com/home-assistant/addons/blob/master/piper/README.md)
- [Rhasspy 3](https://github.com/rhasspy/rhasspy3/)
- [NVDA - NonVisual Desktop Access](https://www.nvaccess.org/post/in-process-8th-may-2023/#voices)
- [Image Captioning for the Visually Impaired and Blind: A Recipe for Low-Resource Languages](https://www.techrxiv.org/articles/preprint/Image_Captioning_for_the_Visually_Impaired_and_Blind_A_Recipe_for_Low-Resource_Languages/22133894)
- [Open Voice Operating System](https://github.com/OpenVoiceOS/ovos-tts-plugin-piper)
- [JetsonGPT](https://github.com/shahizat/jetsonGPT)
- [LocalAI](https://github.com/go-skynet/LocalAI)
- [Lernstick EDU / EXAM: reading clipboard content aloud with language detection](https://lernstick.ch/)

## Training

See the [training guide](TRAINING.md) and the [source code](src/python).

Pretrained checkpoints are available on [Hugging Face](https://huggingface.co/datasets/rhasspy/piper-checkpoints/tree/main)

Pretrained checkpoints are available on
[Hugging Face](https://huggingface.co/datasets/rhasspy/piper-checkpoints/tree/main)

## Running in Python

See [src/python_run](src/python_run)

Install with `pip`:

``` sh
```sh
pip install piper-tts
```

and then run:

``` sh
```sh
echo 'Welcome to the world of speech synthesis!' | piper \
--model en_US-lessac-medium \
--output_file welcome.wav
```

This will automatically download [voice files](https://huggingface.co/rhasspy/piper-voices/tree/v1.0.0) the first time they're used. Use `--data-dir` and `--download-dir` to adjust where voices are found/downloaded.
This will automatically download
[voice files](https://huggingface.co/rhasspy/piper-voices/tree/v1.0.0) the first time they're used.
Use `--data-dir` and `--download-dir` to adjust where voices are found/downloaded.

If you'd like to use a GPU, install the `onnxruntime-gpu` package:


``` sh
```sh
.venv/bin/pip3 install onnxruntime-gpu
```

and then run `piper` with the `--cuda` argument. You will need to have a functioning CUDA environment, such as what's available in [NVIDIA's PyTorch containers](https://catalog.ngc.nvidia.com/orgs/nvidia/containers/pytorch).

and then run `piper` with the `--cuda` argument. You will need to have a functioning CUDA
environment, such as what's available in
[NVIDIA's PyTorch containers](https://catalog.ngc.nvidia.com/orgs/nvidia/containers/pytorch).
2 changes: 1 addition & 1 deletion src/python/piper_train/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0
1.1.0
6 changes: 3 additions & 3 deletions src/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cython>=0.29.0,<1
piper-phonemize~=1.1.0
piper-phonemize~=1.2.0
librosa>=0.9.2,<1
numpy>=1.19.0
onnxruntime>=1.11.0
pytorch-lightning~=1.7.0
torch>=1.11.0,<2
pytorch-lightning~=2.1.0
torch>=2.0.0
2 changes: 2 additions & 0 deletions src/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
],
keywords="rhasspy tts speech voice",
)
2 changes: 1 addition & 1 deletion src/python_run/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
piper-phonemize~=1.1.0
piper-phonemize~=1.2.0
onnxruntime>=1.11.0,<2
1 change: 1 addition & 0 deletions src/python_run/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
],
keywords="rhasspy piper tts",
)