The simplest English word simulator using Python and Balabolka

There are a large number of different methods of studying foreign languages โ€‹โ€‹in general and English in particular. But whatever the method, learning words is still necessary.

For these purposes, there are so many different simulators with a choice of words to learn. However, their capabilities are sometimes not enough.

On one of these simulators, I have already learned enough words. And faced with one problem. The simulator offers a Russian word, in response you need to write this word in English, the announcer (actually a speech synthesizer) then voices the English version. I write all the words perfectly, however, when I see the English text, I only remember that I taught this word, but I do not remember what it means. That is, I realized that I lack the recognition of words.

Another drawback of the selected simulator is that empty positions are offered for input, into which letters must be entered, and I always have a hint how many letters should be in a word, and this is not sports.

Based on these considerations, I realized that I want to make my simulator for repeating the words I studied. This simulator should be English-Russian in the direction of translation and with voice acting of the English text in order to train listening.

The procedure for solving the problem was as follows:

  • I prepared a csv file from two columns: 'word' and 'translate', which included all the words I needed.
  • I downloaded the console version of Balabolka, a well-known free program tts (text-to-speach), designed to voice any text from a file or from the clipboard.
  • I wrote working code in the Jupiter Notebook under the Windows 10 operating system.

I did not immediately come to use Balabolka. At first I wanted to use the pyttsx3 library, but a lot of errors crashed when initializing the pyttsx3.init () package, and there was no sound when starting pyttsx3.init ('dummy'). I did not succeed in breaking through mutual misunderstanding with this package, so I had to look for other options, and I succeeded with Balabolka.

The code I got is this:

import subprocess, clipboard
import pandas as pd

Standard start. If pandas knows everything, then the subprocess and clipboard libraries were unfamiliar to me. The subprocess package accesses the console version of Balabolka, simulating the command line. The clipboard package allows you to copy text to the clipboard, from where it will be read by a speech synthesizer.

words = pd.read_csv ('C:/.../Python_Scripts/words.csv', delimiter=';')
words.head()

I read the prepared csv file with words and translation.

words.shape

And I always control the values โ€‹โ€‹of the variables, what is written in them and how.

words1 = words.sample(frac=1)
words1.head()

I mix the words in the file like cards, so as not to remember the sequence of words.

words10 = words1.iloc[0:100]

Sometimes there is not enough time to go through the entire word file and here you can limit the number of repeated words.

for i in range (len (words10)):
    path = r'C:\...\balcon\balcon.exe'
    flag = ' -n Slt -s -3 -c'
    clipboard.copy (words10['word'].iloc[i])
    subprocess.Popen(path + flag, creationflags=0, close_fds = True)
    print ("\033[1m {}\033[0m" .format(words10['word'].iloc[i]))
    tr = input ()
    print ("\033[1m {}\033[0m" .format(words10['translate'].iloc[i]))
    res = words10['translate'].iloc[i] == tr
    if res == True:
        print("\033[1m\033[36m {}\033[0m" .format(''))
    else:
        print("\033[1m\033[31m {}\033[0m" .format(''))
    i = +1

The text of the program itself.

In the path variable, I call the console version of Balabolka, the balcon.exe file.

The console has its own call parameters written to the flag variable.

Specifically, here I use:

  • free voice -n Slt (it was downloaded from the developer of voice synthesizers Olga Yakovleva, I picked up the English voice with the pronunciation clarity I needed and, in fact, the voice can be any other)
  • pronunciation speed -s -3 (this option means slowing down the pronunciation speed -3 from the standard)
  • reading from the clipboard -c (Balabolka can read text both from a file and from the clipboard; I chose the clipboard, because creating thousands of files with words is a terrible undertaking).

The result of the program looks like this:

Jupiter Notebook Window

Initially, a long โ€œsausageโ€ of output without highlighting the text looked completely unreadable (first the word in English, then the answer I entered, then the output of the correct translation, then the result of comparing the original version and the entered one, totaling four lines per word). This made it very difficult to analyze errors. I had to use ANSI codes so that later I could quickly find those words where I made a mistake.

This simplest simulator does not pretend to be original. A large number of more advanced programs have been created, but to solve my own local problem, this result suits me. I can control it from beginning to end. The script can be modified, remove the spelling of the English word, leave only a voice and train listening. You can also change the direction of the translation and train the spelling of English words, which was not enough for me in the original simulator, and with which this whole story began.

I would be glad if this simple script helps people who do not have strong programming skills to create their own simulator or to implement something else based on this code.

All Articles