Skip to main content

Pytońska treść do mowy – Polish Text to Speech library for Python

Project description

PyTDM

ie. Pytońska treść do mowy which is Polish for Python Text to Speech. Package for turning text written in Polish into speech.

Both for standard Python3 and for iOS.

ok but why

This lil library was designed in order to assure that people programming for Pollacks have some sort of an offline-working text to speech python software. For English speaking people there already is the pyttsx3 library which provides such functionalities. If you want your programme to talk you simply run few commands

import pyttsx3
engine = 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.

installation

it is avalaible on PyPI! you can just run:

pip install pytdm

and you can use it just like that!

how it's made

It's based on the pyttsx3 package I've just mentioned. The thing is that contrary to what many English speaking people think (looking at u americans) Polish actually is pronounceable for someone knowing English.

What PyTDM does is

  • first it translates* the given polish string/text into english
  • then it gets pronounced with the pyttsx3

The asterisk above next to the word "translates" is there for a reason – it's not exactly translation. More like transcription or transliteration. We shall get back to that later

usage

For simple basic stuff you should do it as follows:

import pytdm
pytdm.mów("dzień dobry, dobranoc")

or the second way:

from pytdm import mowa
mowa.mów("dzień dobry, dobranoc")

and then you can happily listen to the sweet sound of the polish language spoken by the pyttsx3 synthesiser voice. Isn't that great?

little disclaimer

the functions have Polish names like mów or tłumacz with those funny strange letter but if you want you can use them without the diacritics eg. write mow or tlumacz. They will work just fine.

In general if have any problems first you can type eg. help(pytdm.mow) and read the info provided there.

examples

An example for how well does the software work with approxima... translation of polish words is to be seen in the demo.py file (avalaible on my 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 see barka.py. Both demo files are in the demos github directory) – the anthem of the Third Polish Republic.

There is a video showing how the demo.py file works (recorded in low quality by me and posted on youtube) here.

dependencies

all you need are built-in packages like re and apart from that the pyttsx3 package (v>=2.7). It is avalaible on pypi so you can just do the classic:

pip install pyttsx3

what OS?

The only problem is it's different for every OS.

  • For all I know it works really well on macOS – I use this OS myself therefore I can easily test that there and adjust it respectively.

For other OS I have only some feedback from other people:

  • Windows is stoopid (per usual) and reads 'ch' as /k/ and not /t͡ʃ/. Apart from that and maybe some other mistakes it is fine.
  • it's not bad on Linux but it has problems with eg. consonant clusters like szcz. When it tries to pronounce them as shtch it 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 is w e i r d

In conclusion: it works ok for all of them but some sounds are realised differently on different OSs.

mobile versions – iOS

for iOS see the pythonista directory on github. Everything there is the iOS version of PyTDM.

Function names are weird?

As a cautious reader might have noticed the main speaking function is mów (fyi it means say just like in the pyttsx3). One could ask wthell? or more properly co do diabła? but that is exactly how the package was intended to be: the functions have polish names. Deal with it.

behind the scenes

Now for some calrification about how the so called translation process actually works.

For every word passed to the mów function it is first tanslated by another polish-named func tłumacz (ie. translate) and it calls 2 more functions first:

  • repolonizuj ie. repolonise – it deals with all the weird polish ortographic stuff like the diagraphs, some consonants being devoiced etc. Futuryści inspired

  • anglicyzuj ie. anglicise – it takes the repolonised text and tries to find the closest approximations for all the sounds that are to be found. It's doingit's best.

only then mów gives the anglicised repolonised text to the engine.say as shown above.

So when you do something like mów('czuję, że będzie dziś dość średni dzień') it first calls tłumacz which calls repolonizuj that returns this simplified polish text: 'czuje, że bendźe dźiś dość średni dźen' and it is passed to the anglicyzuj which gives the final result to be said by pyttsx3:

'choo yeah, zshehh behnjehh jeesh dawshtch shrehdnee jehn'

it sure is amazing.

TO DO
  • saving mp3s (to do before v0.1.0)
  • polish the Polish
    • implement pronouncing numbers above 199
    • better handling of numbers mixed-in with words
    • no hardcoded words is the goal
    • better handling of syllables, diphtongs and other strange edgecases eg. je, ej, aj, świe etc
  • a good idea would be to provide alternative rules of translation for different operating systems in the future
  • some proper documentation for functions and the translation process
  • optional gTTS mode
  • extend this list

feel free to fork the github repo and provide some videos:)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytdm-0.0.9.tar.gz (7.4 kB view hashes)

Uploaded Source

Built Distribution

pytdm-0.0.9-py3-none-any.whl (8.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page