Package: pytdm
PyTDMie.Pytońska treść do mowywhich is Polish forPython Text to
Speech. Package for turning text written in Polish into speech.Both for standard Python3 and for iOS.ok but whyThis lil library was designed in order to assure that people
programming for Pollacks have some sort of an offline-workingtext to
speechpython software.
For English speaking people there already is
thepyttsx3library which
provides such functionalities.
If you want your program totalkyou simply run few commandsimportpyttsx3engine=pyttsx3.init()engine.say("now we're talkin'")engine.runAndWait()and it's literally that easy! But for Polish there was no such thing. Until now.installationit is avalaible onPyPI!
you can just run:pipinstallpytdmand you can use it just like that!iOSfor the iOS version see
thepythonista directory on github,
do not usepipthere – just put this file in thePython Modules/site-packages-3directory and restart the app. The module will
be added to the path and then you can simply import it.how it's madeIt's based on thepyttsx3package I've mentioned. The thing is
that contrary to what many English speaking people think (looking at u
americans) Polish actuallyispronounceable for someone knowing
English (or French – see below).WhatPyTDMdoes isfirst ittranslates*the given polish string/text into englishthen it gets pronounced with thepyttsx3The asterisk above next to the word "translates" is there for a reason
– it's not exactly translation. More like transcription or
transliteration. Anglicises or francises depending on the language one
has choosen.
We shall get back to that laterusageFor simple basic stuff you should do it as follows:importpytdmpytdm.mów("dzień dobry, dobranoc")or the second way:frompytdmimportmowamowa.mów("dzień dobry, dobranoc")and then you can happily listen to the sweet sound of the polish
language spoken by thepyttsx3synthesiser voice. Isn't that great?You don't have to start the engine as one does withpyttsx3hence it
takes some time for python to import the package (thepytdmmodulw performs thepyttsx3.init()command itself when imported).saving filesWith version0.1.0came the functionality of saving spoken text in
files! It is similar to simply making the computer say stuff:pytdm.zapisz("dzień dobry świecie!","example.mp3")and your file will be saved in your cwd under the name"example.mp3".It isn't working 100% correctly though.For some
reasonpyttsx3seems to break when trying to save a second file in
the same session. Or rather the file does indeed get saved but the command
doesn't stop executing itself. I suppose the issue is atpyttsx3part.little disclaimerthe functions have Polish names likemówortłumaczwith those
funny strange letter but if you want you can use them without the
diacritics eg. writemowortlumacz. They will work just fine.In general if you have any problems first you can type
eg.help(pytdm.mow)and read the info provided there.examplesAn example for how well does the software work with
approxima...translationof polish words is to be seen in thedemo.pyfile (avalaible
onmy github). You just can run
it and then see how well it handles the most sacred polish song
(actually the second sacred-est. For the most sacred one seebarka.py) – the anthem of the Third Polish Republic.There is a video showing how thedemo.pyfile works (recorded in low
quality by me and posted on
youtube)here.Also with version0.1.0the french mode has been introduced
therefore there's another demo filedemo_fr.py. A video of it being
run ishere.All demo files are in thedemosgithub directory.dependenciesall you need are built-in packages likereand apart from that thepyttsx3package (version>=2.7). It
isavalaible on pypiso you can
just do the classic:pip install pyttsx3what OS?The only problem is it's different for every OS.For all I know it works really well onmacOS– I use this OS
myself therefore I can easily test it there and adjust it
respectively. The built-in synthesisers are some ofreallyhigh quality
ones and it comes with many languages avalaible which are easily
managable for the user.For other OS I have only some feedback from other people:Windowsis stoopid(per usual)and reads 'ch' as /k/ and not
/t͡ʃ/. Apart from that andmaybesome other mistakes it is
fine. Usingpytdmwith other languages is problematic though -
windows' built-in synthesiser comes without necessary language
marking flags for thepyttsx3to detect hence trying to change the
language may often fail.the English one it's not bad onLinux(of course it depends on what synthesiser
do you use and on which distribution of linux) but it has problems
with eg. consonant
clusters likeszcz. When it tries to pronounce them asshtchit
spells (es aitch tee cee aitch...) the cluster instead of just
just saying /ʃt͡ʃ/ as other versions tend to do. Also it sounds
robotic which isw e i r d. I do not know how does it work with
the language set to french.In conclusion:it works ok for all of them but some sounds are
realised differently on different OSs.mobile versions – iOSforiOSsee thepythonistadirectory on github.
Everything there is the iOS version ofPyTDM.Function names are weird?As a cautious reader might have already noticed the main speaking function ismów(fyi it meanssayjust like in thepyttsx3). One could askwthell?or more properlyco do diabła?but that is exactly how
the package was intended to be: the functions have polish
names.Deal with it.Or use the same name without the diacritics
if you really need to.behind the scenesNow for some calrification about how the so calledtranslationprocess actually works.For every word passed to themówfunction it is firsttanslatedby
another polish-named functłumacz(ie.translate) and it calls 2
more functions first:repolonizujie.repolonise– it deals with all the weird
polish ortographic stuff like the diagraphs, some consonants being
devoiced
etc.Futuryściinspiredanglicyzujie.anglicise– it takes therepolonisedtext
and tries to find the closest approximations for all the sounds that
are to be found. It's doing its best.only thenmówgives the anglicised repolonised text to theengine.sayas shown above.So when you do something likemów('czuję, że będzie dziś dość średni dzień')it first callstłumaczwhich callsrepolonizujthat returns this simplified polish text:'czuje, że bendźe dźiś dość średni dźen'and it is passed to theanglicyzujwhich gives the final result to
be said bypyttsx3:'choo yeah, zshehh behnjehh jeesh dawshtch shrehdnee jehn'it sure is amazing.FrenchAs you may have known thepyttsx3library offers any speech
synthesiser avalaible to the system. Therefore it may happen one does
also have the french one and now it is possible to use it withpytdmtoo.It is a relatively new feature so you shouldn't expect it to be
flawless. As for now pronouncing numbers is not even implemented
here. Also it hasn't been tested anywhere apart from macOS yet.The good thing is it is actually easier to transcribe Polish into
French than into English. Why? Well despite what many people think
about the French language it is actually pretty logical and much more
regular than English. Its reading rules are not that messy and there
are not as many strange edge cases.How to use the french mode?You must have thepytdmversion0.1.0or higher installed.just add thelang="fr"argument or simplyfrwhen calling
functions likemówortłumacz. To set it back to english setlang="en".>>>importpytdm>>>pytdm.tłumacz("czuję, że będzie dziś dość średni dzień","fr")'tchouyé, jé baindjé djich dochtch chrédgni djègn'>>>pytdm.mów("czuję, że będzie dziś dość średni dzień","fr")czuję,żebędziedziśdośćśrednidzieńAnd there is the functionfrancyzujthat works the same asanglicyzujmentioned before but for French.TO DOpolish the Polishimplement pronouncing numbers above 199better handling of numbers mixed-in with wordsno hardcoded words is the goalbetter handling of syllables, diphtongs and other strange
edgecases eg.je, ej, aj, świeetcmake french mode as good as the standard english one. right now
there is no pronounciation for numbers implemented in the french modea good idea would be to provide alternative rules oftranslationfor different operating systems in the futureadd numbers to the french variantsome proper documentation for functions and thetranslationprocess. Regexp isfamouslycomplicated as hell so an entire file
explaining each of all those patterns etc is not a bad
idea.optionalgTTSmodeextend this listfeel free to fork the github repo and provide some videos:)