hey-hey! I used Python to make a Monkey King playing Ruyi Golden Cudgel

The summer vacation is coming soon, and many children will also have a vacation. The most familiar TV program during the summer vacation is "Journey to the West". I think everyone is familiar with this TV series. The editor's favorite is the Ruyi Golden Cudgel in the hands of Monkey King. This stick weighs 13,500 catties.

Whenever Sun Wukong lets him expand and contract freely, making it bigger and smaller, the editor always thinks that he can have such a handy weapon. It just so happens that my little nephew is coming to Beijing for summer vacation. Thinking of this, the editor decided to use Python to make a small fun program for my little nephew. As long as you say "big" or "small", you can control the size of the golden cudgel freely. What are you waiting for, come and see how it is realized with the editor.

 1

general idea

Today's program mainly uses multithreading, speech_recognition speech recognition library and opencv image processing library. Let's first look at the flowchart of program execution, as shown in the following figure:

The program is mainly divided into three parts, which are three threads, which respectively control the playback of the picture of the golden cudgel, collect the sound of the microphone, and display the picture of Monkey King. Let's take a look at the program and specific implementation of each thread separately.

 2 

control golden cudgel

How to play the picture of the golden hoop is actually not difficult to use. We first scale a picture to 29 pictures of different scales in equal proportions, store them in a designated folder, and then use thread 1 to continuously play the pictures of the golden cudgel. The program and picture storage are shown in the figure below.

In the above program, the 19 pictures that we scaled are displayed, and then we use the following program to continuously display the pictures, and the instruction is responsible for controlling whether the pictures are constantly getting bigger or smaller.

 3 

sound collection

The next step is for the collection of voice, we need to use voice to control the size of the golden cudgel, which is actually to control the variable instruction. The program is shown in the figure below:

In the above program, we use the speech_recognition library to continuously monitor the microphone, convert the extracted speech into text, and judge whether the instruction content needs to be changed according to the text information, so as to change whether the picture in thread 1 becomes larger or smaller.

Show photo of Monkey King

The function of the last thread is to display an image of Monkey King on the computer desktop to make the game more vivid. The program is as follows:

The above is the explanation of the procedures and functions of the three threads. Finally, let's show the effect of the game in a video.

If you need source code, you can enter it in the background: [Golden Cudgel]

end

近期十大热门:

The public account [Programmer GitHub] created by the original team of Cainiao Learning Python focuses on sharing interesting resources on GitHub, including high-quality learning resources such as Python, Java, and Go language front-end learning.



点这里,进菜鸟学PythonB站大本营

Guess you like

Origin blog.csdn.net/cainiao_python/article/details/107273675#comments_27666974
Hey