A computer system used to create artificial speech is called a speech synthesizer, and can be implemented in software or hardware products.
A text-to-speech (TTS) system converts normal language text into speech. How can we use speech synthesis in Python?Related courses:
Pyttsx is a cross-platform speech (Mac OSX, Windows, and Linux) library. You can set voice metadata such as age, gender, id, language and name. Thee speech engine comes with a large amount of voices.
Text to speech sample:
Create the code speech1.py
And execute it with python.
eSpeak is a compact open source software speech synthesizer for English and other languages, for Linux and Windows.
Text to speech sample:
We can install using:
Create the code speech2.py:
It is very easy to use, but like pyttsx it sounds very robotic.
The gtts module no longer works.
I found a script on Github that uses the Google speech engine. The script comes with many options and does not speak, instead it saves to an mp3. We added a command to play the mp3 automatically:
The voice is extremely natural. The only disadvantage is that you need to be connected with the Internet when running this script.
You might like:
Methods can be applied to Python strings, where a string is somet text between quotes. An example of using the string method replace, which replaces the a sub-string in a string:
Python Programming Bootcamp: Go from zero to hero
Python includes these useful methods for string manipulation:
|Method with description|
Returns first letter capitalized string.
Count the frequency of the word str. It can also be applied to words: s.count("Hello")
Find the position of the first occurence.
Find the position of the first occurence, raise exception if not found.
Returns true if string is decimal.
Returns true if string contains digits only.
Returns true if string contains numeric only.
Returns string in lowercase.
Returns the length of str.
Returns string in uppercase.
Replaces the first argument with the second argument.
|PyCharm||Jetbrains||Windows, Mac OS X, Linux/UNIX||Python IDE. Features including: code completion, code inspections, on-the-fly error highlighting and quick-fixes||€ 89 / 1st year.($ 97.90)||Download PyCharm|
|Atom (+script plugin)||GitHub||Windows, Mac OS X, Linux/UNIX||Python IDE. You need to download the script plugin after installing Atom.||Free.||Download Atom.|
|Pythonista||omz:software||Apple iOS (iPhone, iPad)||Features include: Syntax highlighting, code completion, interactive prompt, standard and iOS modules.||€ 9. ($ 9.90)||Download Pythonista.|
|Eclipse with PyDev||Aleks Totic||Windows, Mac OS X, Linux/UNIX||Features include: Syntax highlighting, code refactoring, graphical debugging and more.||Free||Download|
|Eric Python IDE||Detlev Offenbach||Windows, Linux/UNIX||Features include: Syntax highlighting, autocompletion, class browser and more.||Free||Download|
|Wing IDE||Wingware||Windows, Mac OS X, Linux/UNIX||Features: Syntax highlighting, auto completion, refactoring, unit testing and version control.||$45 to $245 per user / license.||Download|
|Komodo IDE||Komodo||Windows, Mac OS X, Linux/UNIX||Features: Syntax highlighting, documentation browser, run code in-line, quick bookmarks and more.||€ 40 to € 223. ($99 to $295).||Download|
|Repl.it||Amjad Masad, Haya Odeh, Faris Masad and Max Shawabkeh.||Web||Python interpreter||Free||Run Online|
|Ideone||Ideone||Web||Python interpreter||Free||Run Online|
|Codepad||Steven Hazel||Web||Python interpreter||Free||Run Online|
Using it is as simple as:
The program below will answer spoken questions.
To create a graphical interface (GUI) in Python you need to make use of a library or module. There are at least three widely used modules for creating GUIs with Python:
Tk provides basic widgets such as a button, menu, text and label. It is very limited compared to QT4 and WxPython but it is also the oldest module. It runs on most versions of Mac OS, Linux and Windows.
QT4 and QT5 are developed by the Qt company. Graphical applications made with QT4 or QT5 run on Windows, Linux/X11 and Mac OS X. It has tons of widgets including tabs, buttons, item views, table views, progressbars, input fields, calendar views and many more. Compared to Tk it has a lot more widgets available.
WxPython is a module that creates a native GUI look regardless of the operating system used. On Windows it will look as windows application while on Mac OS it will look as a Mac application. This can be a clear advantage compared to QT4 or Tk, depending on your purpose. WxWidgets has many widgets available such as buttons, menu, text but also more advanced widgets as a htmlview or tree control.