Running a local Piper TTS server with Python on Linux

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
good day and welcome to this step-by-step cooking recipe tutorial on how you set up a locally running server process for Piper TTS so Piper text to speech and use this server process to synthesize wave file audio on the command line by using curl or in a simple python script and as this HTTP endpoint server is a really new feature I did not know until I talked with Mike Hensen so the creator of Piper TTS put a link in the description box below to this interview this is really an early step in development and might change in the future and if you are interested in Piper TTS in general I will put a link in the description box also to a video playlist I've made with some tutorials about Piper before starting with the actual topic do not forget to give this video a thumbs up and subscribe to my channel if you have not done so already thank you and now let's go let's start by cloning if you have git tools installed or downloading the source code of Piper TTS so hop on to GitHub com rasby Piper so Piper TTS is a part of the rasby project and uh let's click this button and copy the git clone URL and now let's switch to the command line for this demonstration I will use my 10 year old MacBook Pro with yuntu 22 uh latest LTS version installed so let's see our yuntu version so 22.4 and let's create a new and empty folder because I'm so creative let's call it Piper switch into that and as we we use a python virtual environment because we clone the sources we work on python code base and we will create by the end a python script to use that Piper TTS locally running server process uh I start by creating a python virtual environment I've installed Python 3 in version 3.10 so let's run Python 3 minus m v en and the name of the folder structure so do we enf then it will be a hidden file in directory structure so if I run just list it's empty but running list with showing hidden files we can obviously see that there are a VN directory let's activate this one by running VN bin activate and as you can see by this wi and prefix we are now inside our python virtual environment let's see p list and the first thing I personally like to do always is to update some default python packages so let's run pip install the PIP the package management system itself setup tools and the wheel package with minor no with minus upper case U for upgrade let's see pip list again and now let's clone our code base of pipa TTS so we copied that clone repo URL to to our clipboard so let's run git clone and no I copied it to clipboard but it's gone so let's copy it again alternatively you can download a zip file and uh extracted on your local hard disk once this is done we have another subfolder for Piper let's go inside here and uh now as we work on the python source code level let's go in the SRC so the source directory and in the python uncore run and here you can see we have some um python requirements files for some packages and we have a read me HTTP MD so a markdown file so let's take a look to this read me HTTP MD file in our GitHub repository so switch to the source python run directory and let's open the readme file and as you can see you can install the requirements by running uh resolving um the dependencies in requirements HTTP text and then start the HTTP server process but before doing so we have to install the python package for Piper TTS itself so let's go back to our command line inside our source python run directory and let's run pip install minus E Dot this will download some python dependencies once done let's run pip list again and now we can see we have a piper TTS package in the version 1.2.0 so now let's go back to the read me documentation and let's satisfy the requirements for this HTTP server and as you can see now let's take a look to our requirements HTTP this is pretty simple it's just this flask package in the version higher than three and lower than four or to be more precise higher or equal three and lower version four so let's satisfy this dependency pip install minus r requirements uncore HTTP txt and now when we run pip list again we should have a package of flask in the required version range and you can see flask is installed in version 3.0.2 so now now we have installed now we cloned the source code of Piper TTS we installed the dependencies the package and satisfied our dependency for the HTTP server process but before we can run an actual server process we have to download the model files for specific language or a model uh to use pip up by itself so let's go back to the browser and go to the piper report repository scroll a little bit down on the read me and click this download voices link which will which will bring you to hugging face choose your language I go with us English and choose this voice in a high quality then let's click the onx model file itself and copy the URL to the download load link so let's copy link and go back to our command line prompt let's move a few areas up and let's create a new folder models and let's use this command to download the model file download finished let's rename it to a more intuitive name so let's just make it copy paste looking way better now we have to download the configuration Json file for this specific model so let's go back to hugging phase and click this Json file raw copy the URL let's go back to our command line running command to download again where's the matching Json file and now we have the onx DI actual model for Piper TDS and we have the matching Json file the configuration file in this models directory so let's copy this path copy and now we have satisfied or installed Piper TTS by running the PIP command so on the python level we have downloaded a model an x file and it's mapping Jon file and we have satisfied the flask dependency for the simple HTTP locally running server process so I would say now it's time to go back to the read me and see what's next and now we can run the web server by running the python command with the module Piper HTP server and a model name so let's give this one a try minus minus model copy okay let's make it this one with the o x file not the Json file and let's try and run so now as you can see we have started an HTTP server process that is running on your Local Host um system or on your Lan or in your local network IP address and do not Wonder this is not a web UI so there's no fancy web user interface you can just give the try um you can see we get an internal server error and let's go back to the command line we will see that there's the value the arrow value no text provided so there's no user interface no graphic user interface you can access in the browser it's just a backend API and after my interview with Mike Hansen he told me that he's definitely more the backend person than a front-end developer and I can really feel this so no user interface but a back end so the server process is up and running let's keep this tab open and now let's go to the client side and try if we can access this running server process on the command line so for this let's open a new terminal uh let's now I'm on the same machine as the running server process but this should work over your local network as well so just to be sure yes it's the same machine and now let's go back to the piper documentation and see how we can access the server process by running the get command or the get method probably more get method so using the curl command let's just take it as it is in the documentation let's go back to our YouTube Piper directory as you can see I'm not in the piper virtual environment so this is a plain new session and let's copy or paste the command so what's happening here curl is being executed with a text parameter this is a test output will be saved as test Point wave and the connection is Local Host 5,000 so let's run this and let's see what we got and here we are we have this test vaff file so let's just simply see if this works and as you can see it's a wave file audio we will listen to the output files when we use the python script based method and this is now so um let's go back to the browser I've created a special special a simple script which will access um the server process and download the wave file as you can see it's really a super simple script just requires the requests python package you define the text to be spoken you define your server pass the HTTP URL a file name and uh that's then the output is just saved so let's take the script and let's paste this script in my preferred development environment which is Visual Studio code by now so as you can see I'm in my visual studio code and I'm connected using SSH to my yuntu 22.4 uh laptop and uh we are inside this directory structure so we have this virtual python environment our models file and the piper so the cloned repository code uh let's create a new simple file here let's call it test py I'm so creative I do not want it in this I would like to have it outside so test py and let's just paste the snipet here and uh if things go right let's open a command line prompt terminal new terminal here so I'm in my YouTube Piper directory with the well-known structure and this test py so let's run Python 3 test py and if things go right there should magically appear an output bu file with the spoken phrase We defined here so let's run it and no this is because I did not satisfy there's just one dependency to you had just one job so sorry for that but uh this should be easy to fix so let's run pip install requests okay and let's run it again taada here we are so as you can see on the left side now there's this output ra and let's that's okay let's listen to it this is a text to be spoken using the locally running Piper TTS server process and that's it super simple so this is really really totally easy to set up a locally running pipa TTS server process and use this either by using a command line tool like curl just by accessing the get method or using this simple python script I hope you like this video you found it helpful if so please give this video a thumb up let me know in the comment box below and do not forget to subscribe to my channel if you like my work thank you and have a nice day if you like we might see us next time bye
Info
Channel: Thorsten-Voice
Views: 2,064
Rating: undefined out of 5
Keywords: TTS, Text to Speech, Voice Tech, Tutorial, ML, Machine Learning, AI, Smart Home, KI, Voice Assistant, Python, Tech, Open Source, Künstliche Stimme, Sprachassistent, Home Assistant, Raspberry, text to speech ai, text to speech deutsch, text to speech ai free, text to speech python, open source ai, open source software, voice assistant ai, machine learning tutorial, machine learning projects, piper tts python, piper, piper text to speech, local running ai
Id: pLR5AsbCMHs
Channel Id: undefined
Length: 17min 34sec (1054 seconds)
Published: Tue Feb 13 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.