Basic installation

There are various ways and methods through which we can control our smart home Jarvis, some of which we have explored earlier such as controlling it through. So, to start with, we need to prepare our system to be able to do speech synthesis; to do that, let's perform the following process.

First, go to the terminal and enter the following command:

sudo apt-get install alsa-utils

What this will do is install the dependency alsa-utilsThe alsa-utils package contains various utilities that are useful for controlling your sound drivers.

Once this is done, you need to edit the file. To do it, we need to open the file. Use the following command:

sudo nano /etc/modules

Once that is done, a file will open; at the bottom of that file, you need to add the following line:

snd_bcm2835

You don't need to get too much into why we are doing it. It's just there to set things up. I can give you an explanation; however, I do not wish to bore you at this exciting moment. 

Also, if you are lucky, then sometimes, you might find the line to be already present. If that is the case, then let it be there and don't touch it. 

Now, to play the sounds that we need the Jarvis to say, we need an audio player. No, not the one that you have at your home. We are talking about the software that would play it. 

To install the player, we need to run the following commands:

sudo apt-get install mplayer

All right, we are done with audio player; let's see what we have next. Now, again, we need to edit the file of the media player. We will use the same steps to open the file and edit it:

sudo nano /etc/mplayer/mplayer.conf

This will open the file. As before, simply add the following line: 

nolirc=yes

Finally, we need to give it some voice, so run the following command:

sudo apt-get install festvox-rablpc16k

This will install a 16 kHz, British, male, voice to Jarvis. We love British accents, don't we? 

Perfect. Once we have done all of the steps mentioned previously, we would be good to go. To test the voice, simply connect a USB speaker to the Raspberry Pi and run the following code:

import os
from time import sleep
os.system('echo "hello! i am raspberry pi robot"|festival --tts ')
sleep(2)
os.system('echo "how are you?"| festival --tts ')
sleep(2)
os.system('echo "I am having fun."| festival --tts ')
sleep(2)

All right then, let's see what we have actually done: 

import os

As you might have figured out, we are importing the library named os. This library provides a way of using operating-system-dependent functionality:

os.system('echo "Hello from the other side"|festival --tts ')

Here, we are using a method called system(); what this does is that it executes a shell command. You might be wondering what this is. A shell command is a command used by the user to access the functionality of a system to interact with it. So now that we want to convert our text to voice, we would be providing two arguments to this function. First, what is the text? In our case, it is Hello from the other side; the second argument that we have here is festival --tts. Now festival is a library, and tts stands for text to speech conversion. So when we pass it on to the argument, the system will know that the text passed on to the argument has to be converted from text to speech.

And that's it! Yes, that's it. That's all we have to do to make your Raspberry speak. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.216.163