piper-phonemize icon indicating copy to clipboard operation
piper-phonemize copied to clipboard

[Linux] Add Python 3.12 support

Open TheEpic-dev opened this issue 1 year ago • 17 comments

Hey! I was trying to pip install piper-tts, but it fails to resolve piper-phonemize. I see on PyPI that there is a Python 3.12 build for Mac OS, but not for Linux. As Python 3.12 is now the default on Arch Linux and Ubuntu 24.04 LTS, would it be possible to update or rebuild the package with support for 3.12?

Thanks, Pat

TheEpic-dev avatar May 03 '24 16:05 TheEpic-dev

In the meantime, you can download the source from tag v1.1.0, and in it, edit the dockerfile to build a wheel for Python 3.12 (i.e., add to or replace the pip wheel calls to target cp312 rather than 311, 310...). The manylinux_2_28_x86_64 Docker image ships with CPython 3.12 so this is the only required change. Then you build per the readme file.

Then you install the whl you just built alongside with piper-tts. In pipx, you'd have to use something like --pip-args="$HOME/Temporary/piper-phonemize-1.1.0/dist/piper_phonemize-1.1.0-cp312-cp312-manylinux_2_28_x86_64.whl" (with an absolute path because pipx changes its working directory).

If you trust me—which you shouldn't since I could very well have added a system("rm -rf /home") or worse in there for kicks and giggles—here's my build: https://temp.zetanor.com/g417y32tss0q8l43bg4e6q/piper_phonemize-1.1.0-cp312-cp312-manylinux_2_28_x86_64.whl

zetanor avatar May 05 '24 15:05 zetanor

In the meantime

Thanks. I decided it wasn't a high priority for me after all. I did want to test it locally real quick, but as I am already using Docker for a bunch of projects, I can easily run in an Ubuntu container with python 3.10.

TheEpic-dev avatar May 05 '24 23:05 TheEpic-dev

Would it be possible to upload the source bundle to pypi? That would allow pip to build the wheel locally (assuming the needed packages are installed) rather than just having to wait for built wheels be be pushed to pypi

jhollowe avatar Jul 06 '24 18:07 jhollowe

agreed

smallbraineng avatar Jul 08 '24 20:07 smallbraineng

Checking in on this -

It's September, how's it going?

sbussard avatar Sep 03 '24 22:09 sbussard

Does anyone interested working with me on that?

  1. Add option to build on Windows
  2. Add option to build on macOS
  3. Add BUILDING.md with docs about build it on linux/macos/windows
  4. Add CI on Github actions to build and publish pre built wheels for Windows/macOS.

Then we can create a PR here, and in the meantime a fork which will publish wheels.

thewh1teagle avatar Sep 11 '24 23:09 thewh1teagle

Any progress? Upgraded to the Ubuntu LTS release and my home lost its voice. :/

brandyn avatar Dec 09 '24 16:12 brandyn

I created pypy project search on my github

thewh1teagle avatar Dec 09 '24 17:12 thewh1teagle

Maybe you can use the follow command to install the piper-phonemizer:

pip install piper_phonemize -f https://k2-fsa.github.io/icefall/piper_phonemize.html

qt06 avatar Dec 11 '24 03:12 qt06

I was able to get piper-tts installed on the latest Ubuntu LTS under python3.12 by (what I now realize is essentially @zetanor 's suggested method above) downloading an older version of the project from github and changing one line of the Dockerfile to compile a python 3.12 version. Here are the exact commands I issued in order (since it builds with docker, this should be fairly independent of your particular environ?). I did these as a regular user, not root. You will need to have docker-buildx installed and your user must be in the docker group:

  1. git clone https://github.com/rhasspy/piper-phonemize.git
    
  2. cd piper-phonemize
    
  3. git checkout 20554f24f807146fcf183f4a22ac10e9f24c9f45     # Last checkin with 1.1.0 tag?
    
  4. vi Dockerfile                                             # Add (it's obvious where): /opt/python/cp312-cp312/bin/pip wheel . && \
    
  5. docker buildx build . -t piper-phonemize --output 'type=local,dest=dist'
    
  6. cd dist
    
  7. pip install piper_phonemize-1.1.0-cp312-cp312-manylinux_2_28_x86_64.whl
    
  8. pip install piper-tts
    

brandyn avatar Dec 13 '24 02:12 brandyn

You can use this Dockerfile to build piper-phonemize for Python 3.12

  1. Replace the Dockerfile in the repo with the one below
  2. Run docker buildx build . -t piper-phonemize --output 'type=local,dest=dist'
  3. The *.whl file will be in the dist/
# For Python 3.9
#FROM debian:bullseye AS build

# For Python 3.11
# FROM debian:bookworm AS build

# For Python 3.12
FROM debian:trixie AS build
ARG TARGETARCH
ARG TARGETVARIANT

ENV LANG=C.UTF-8
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
    apt-get install --yes --no-install-recommends \
        build-essential cmake ca-certificates curl pkg-config git python3 python3-dev python3-pip

WORKDIR /build

COPY ./ ./
RUN cmake -Bbuild -DCMAKE_INSTALL_PREFIX=install
RUN cmake --build build --config Release
RUN cmake --install build

# Do a test run
RUN ./build/piper_phonemize --help

# Build .tar.gz to keep symlinks
WORKDIR /dist
RUN mkdir -p piper_phonemize && \
    cp -dR /build/install/* ./piper_phonemize/ && \
    tar -czf "piper-phonemize_${TARGETARCH}${TARGETVARIANT}.tar.gz" piper_phonemize/

# Build Python wheel
ENV CPLUS_INCLUDE_PATH=/build/install/include
ENV LIBRARY_PATH=/build/install/lib

WORKDIR /build
RUN python3 -m pip install --upgrade pip setuptools wheel pybind11 --break-system-packages
RUN python3 setup.py sdist bdist_wheel
RUN cp dist/*.whl /dist/

# -----------------------------------------------------------------------------

FROM scratch

COPY --from=build /dist/piper-phonemize_*.tar.gz ./
COPY --from=build /dist/*.whl ./

raivisdejus avatar Jan 11 '25 16:01 raivisdejus

I am new to this kind of stuff, including working in Linux, How do I build the file being described in this post:

https://github.com/rhasspy/piper-phonemize/issues/33#issuecomment-2540407032

?

Thank you in advance

Baalduron avatar Apr 04 '25 04:04 Baalduron

@Baalduron See instructions above https://github.com/rhasspy/piper-phonemize/issues/33#issuecomment-2585318698

You will need Docker installed, see https://www.docker.com/get-started/ or Google how to install it. On Ubuntu sudo apt install docker-ce should install it.

Then clone this repo or download the code as zip and extract.

Then replace contents of Dockerfile in the repo code with the content from post above

Then Run docker buildx build . -t piper-phonemize --output 'type=local,dest=dist' from the folder containing repo code and the Dockerfile file.

The wheel file will be in dist folder

raivisdejus avatar Apr 04 '25 05:04 raivisdejus

@raivisdejus thanks for your work,when i changed the dockerfile and run the docker build comand,every thing seemed ok.but the .wheel file is too small,about 171K,is that right? Image i installed the wheel dependentlt,and test it in a script,but an error throwed as follow:

Image could you have a look at this? look for your reply.

masterwang22327 avatar May 22 '25 05:05 masterwang22327

First it seems that latest Debian Trixie is using Python 3.13 now, so to get 3.12 replace ~FROM debian:trixie AS build~ with FROM python:3.12.10-bookworm AS build

Second to fix the issue with libonnxruntime you would need to run pip install onnxruntime==1.14.1, but this will fail on python 3.12 and also python 3.11 as this version of onnxruntime only supports python 3.10

So IMO your best option is to use conda to create a virtual enviroment with python 3.10 https://www.anaconda.com/blog/getting-started-with-conda-environments

raivisdejus avatar May 23 '25 15:05 raivisdejus

@raivisdejus here is my dockerfile mydockerfile.txt and follow is my build log build.log the whl file is still 182K,not as the same size as the repo released version.could you help chek where is wrong?for my personal guess,maybe the espeak-ng folder is not right in dockerfile pipline?and is not the fault of onnxruntime.look for your reply.thanks.

Image

masterwang22327 avatar May 26 '25 05:05 masterwang22327