In this lesson, we will learn how to transfer Python text to voice.
15.1 Components used in this course
15.2 Wiring diagram (Circuit diagram)
You need to connect 3.5mm earphones (provided by yourself) to the audio port on the driver board of the Raspberry Pi, as shown below:
15.3 How to initiate Python text-to-voice function
1. Open the terminal software MobaXterm:
2. Log in to your Raspberry Pi (the way to log in to Raspberry Pi has been introduced in Lesson 1):
3. Enter the Course Code folder, this folder stores the sample code program to control the robot, enter the following command:
cd adeept_alter/02CourseCode/01ComponentCode
4. Enter the command to display the contents of the current directory:
ls
5. The 14Speech_Text folder stores the sample code of this course. Enter the command to enter this folder:
cd 14Speech_Text
6. Enter the command to display the contents of the current directory:
ls
7. Before running this program, we need to make some settings. You need to install the voice environment first, and enter the following commands in the command window:
sudo apt-get install espeak
8.After the download is complete, you need to install the text-to-voice dependency library. Enter the following command:
sudo pip3 install pyttsx3
9. Run the program ttv.py and enter the following command:
sudo python3 ttv.py
10. After running the program, if the program has the following prompt error:
The reason is that the sound card of the Raspberry Pi is blocked. You need to turn it on again and enter the following command:
sudo nano /etc/modprobe.d/snd-blacklist.conf
After entering, add # before the blacklist snd_bcm2835, press ctrl+x to exit, press y, and then press Enter to save the changes.
After saving and exiting, you need to restart the Raspberry Pi, and then run sudo python3 ttv.py again.
11. When you want to terminate the running program, you can press the shortcut key Ctrl+C on the keyboard.
【Attention】:
If you use the built-in Small speaker to play the sound, you may not hear the sound.You can replace it with a headset to play it.