Javatpoint Logo
Javatpoint Logo

Python Pronouncing Module

It is never easy to find rhyming words of the given word, and this becomes even more difficult when we are writing a poem or some rhyming paragraph. Many of us may have heard of CMU pronouncing dictionary and how helpful it is for producing rhyming words. For those of us who don't know what CMU dictionary is, it is an open-source pronouncing dictionary that anyone can use for finding rhyming words, and the Speech Group created it at Carnegie Mellon University. Since it is an open-source dictionary, anyone can use it for free, and it was basically designed for use in speech recognition research. If we don't have any idea of rhyming words of a given word and are looking for them, we can use this CMU dictionary, which is absolutely free. This dictionary provides us with all the rhyming words available of any word from the English language. We just have to visit their website and type the given word in the search box; the result will be displayed with all the rhyming words of the given word in the search box. Thus, it becomes very easy for us to find the rhyming words of any given word, and we don't have to spend too much time thinking about all the rhyming words.

Many programming languages also offer packages that can be used, like CMU pronouncing dictionary to find the rhyming words of any given word of English language. Talking specifically about Python, it has the pronouncing package, which is a very simple interface for the CMU pronouncing dictionary, and we can use this package in a Python program to find rhyming words of any word given in the program. Therefore, we will learn about this pronouncing module of Python in this tutorial. We will learn about its installation and how we can use this module to find rhyming words of any given word in the program.

Introduction to Pronouncing Module of Python

Pronouncing module or library is a simple interface of CMU pronouncing dictionary in Python which anyone can use for finding rhyming words and performing other operations that one can perform using the CMU pronouncing dictionary. There are already many packages available in Python that can be used to find rhyming words, but the best part of this module is that it doesn't require any external dependencies while performing operations, and it is very easy to use. The pronouncing module of Python was created so that one can use the CMU pronouncing dictionary's interface from a Python program without having to install the NLTK or grand behemoth. Using the functions of this module is very easy, and one can easily use this module in any Python program to find out rhyming words of the given word in the program. This module saves lots of time which we can waste while manually thinking or looking for the rhyming words of a given word. We just have to use the functions of this module in a Python program, and all the rhyming words related to the given word will be displayed in the output.

Pronouncing Module in Python: Installation

The pronouncing module of Python is not an in-built module of Python which means that it doesn't come pre-installed in our system when we installed the Python source in our machine. This module requires to be installed externally, and that's why we have to perform an installation process for installing this module in our system. Like using this module, installing it is also very easy because we don't have any external dependencies for this module. We can install pronouncing module of Python using multiple installation processes but installing it using the pip installer method is the simplest and easiest one. Therefore, in this part, we are going to install this module using the pip installer method, and to use this installation method, we have to write down the following pip command in the command prompt shell of our system:

After writing the installation command as mentioned above, we just have to press the 'enter' key, and the installation of the pronouncing module will begin. When the installation process of this module starts, we will have to wait for some time because completion of this module's installation will take a while.

Python Pronouncing Module

As we can see, the pronouncing module of Python is now successfully installed in our system, and 'successfully installed' is displayed on the command prompt shell's screen. Now, we can import the pronouncing module in any Python program to use its functions and find out the rhyming words of a given word in the program using these functions.

Pronouncing Module in Python: Implementation

Now, we will learn how this module functions and how we can use the functions of this module to find rhyming words of a given word. We will understand the implementation of this module by importing and using these functions in the example programs. We will use the functions of this module in the example program and find out the rhyming words of the word given in that example program. We will use this module's rhymes() function to carry out this operation. Following is the syntax of using the rhymes() function of the pronouncing module:

As we can see, the rhymes() function takes the given word (whose rhymed words will be displayed as a result) as an argument.

Look at the following example program to understand the implementation of this pronouncing module:

Example 1: Look at the following Python program where we find rhyming words using the pronouncing module:

Output:

The rhyming words of the word Shine are: 
['affine', 'align', 'aline', 'assign', 'barentine',  .. 'vine', 'whine', 'whine', 'wine', 'wyne', 'zine']

Python Pronouncing Module

As we can see, the rhyming words of the word 'Shine' are printed in the output, and that's how we can use this module to print the rhyming words of any given word.

Explanation: First, we have imported the pronouncing module as prn in the program to use this module's rhymes() function. After that, we used the rhymes() function and used the 'Shine' word in it so that all rhyming words related to the 'shine' word will be fetched. We have stored the result of this operation in the rhymResult variable so that we can use this variable to print the result. Lastly, we used the print statement with the rhymResult variable to print rhyming words related to 'Shine' in the output as a result of the operation performed in the function.

Taking a word input from the user and finding its rhyming words:

In the following program, we will perform the same operation as we have performed in the first example program, but here, we will take the given word as input from the user. Look at the following example program to understand this implementation:

Output:

Please enter a word to find its rhyming words: Meta
The rhyming words of the word given by you are: 
['akita', 'alita', 'alvita', 'amelita', 'amezquita', ....., ita', 'tita', 'tomita', 'unita', 'velveeta', 'venita', 'vernita', 'vinita', 'yamashita', 'zita']

Python Pronouncing Module





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA