In many places, we can come into contact with TTS (Text-to-speech) technology, which converts text into natural-sounding speech and brings people a good interactive experience.
Let’s try to make your project speak.
Step 1: Build the circuit.
After building the circuit according to the above diagram, then plug the audio cable into the Raspberry Pi’s 3.5mm audio jack.
Step 2: Install
sudo apt-get install espeak -y
Step 3: Get into the folder of the code.
Step 4: Run.
Raspberry pi will greet you kindly after the code runs, and it will say goodbye to you when the code stops.
If your speaker have no sound, it may be because the Raspberry Pi has selected the wrong audio output (The default is HDMI), you need to Change Audio Output to Headphones.
If you feel that the volume of the speakers is too low, you can Adjust Volume.
You can Modify/Reset/Copy/Run/Stop the code below. But before that, you need to go to source code path like
raphael-kit/python. After modifying the code, you can run it directly to see the effect. After confirming that there are no problems, you can use the Copy button to copy the modified code, then open the source code in Terminal via
nano cammand and paste it.
from tts import TTS tts = TTS(engine="espeak") tts.lang('en-US') def main(): tts.say('Hello, nice to meet you!') def destroy(): tts.say('See you later') if __name__ == '__main__': try: main() except KeyboardInterrupt: destroy()
from tts import TTS tts = TTS(engine="espeak")
Import the TTS class and instantiate an object.
Set the language.
Currently the switchable language only supports English.
tts.say("Hello, nice to meet you!")
Fill in the text to be said as a parameter, after executing
tts.say(), Raspberry Pi will say the text you wrote.