Make your BeagleBone Speak
Video Tutorial:
Supplies:
-A BeagleBone running Debian and a USB cable.
-A computer with Google Chrome or Mozilla Firefox. If you have an SSH program that will work too.
-A USB to Audio converter. It needs to support ALSA (The Advanced Linux Sound Architecture).
-Headphones/Speaker
Connecting to your BeagleBone
You can use cloud9 or SSH with this tutorial. If you haven't installed the drivers for the BeagleBone, plug in your BeagleBone, which will come up as a USB device. Then open start.htm and install the drivers. Now you can open cloud9 by opening Chrome or Firefox and navigating to 192.168.7.2. On the bottom of cloud9, you will notice a terminal. Here is a video tutorial about how to get started with the BeagleBone Black.
If you prefer SSH, you can use PuTTY to connect to the BeagleBone on windows. In UNIX based systems like
OS X and Linux, you can connect by opening terminal and entering:
your-computer:~ ssh root@192.168.7.2
Setting up Sound
To output audio from your BeagleBone, you can use a USB to Audio dongle. Drivers for the advanced Linux Sound Architechture (ALSA webpage) are already installed on the Bone. You can view all recording and playing devices connected to the bone with:
bone# aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: Black [TI BeagleBone Black], device 0: HDMI nxp-hdmi-hifi-0 []
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: Set [C-Media USB Headphone Set], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0
Now to set up your USB to Audio dongle to work with the Bone create a file called ~/.asoundrc.
bone# nano ~/.asoundrc
Now Type:
pcm.!default {
type plug
slave {
pcm "hw:1,0"
}
}
ctl.!default {
type hw
card 1
}
Installing Flite
Lets start by installing flite, a text-to-speech program. Enter into terminal:
bone# apt-get install flite
Basic Flite Commands:
Now it's time to test it! To do so type:
bone# flite -t Hello!
Flite can speak from a file with:
bone# flite -f hello.txt
You can also make flite output to a file:
bone# flite -t "Shall we play a game?" -o WOPR.wav
Which you can than run with...
bone# aplay WOPR.wav
Using Voices:
Time for some variety! Flite comes with multiple voices pre-installed. To view the available voices run:
bone# flite -lv
Now to use one of these voices:
bone# flite -voice rms -t This is rms voice!
Now to use one of these voices:
bone# flite -voice rms -t This is rms voice!
Using Flite with Python:
If you are using cloud9, create a new file. If you are using terminal you can do so with nano:
bone# nano speak.py
Now enter this into the file:
#imports and stuff
from subprocess import call
import os
#executing flite speech
call(["flite", "-voice", "rms", "-t", "Shall we play a game?"])
If you used nano, type ctrl+x to exit the file. If you used cloud9, save the file as speak.py
Now it is time to test it! If you used cloud9, simply press run. If you used terminal, run:
bone# python speak.py
If you want, you can even make a question-answer program:
#imports and stuff
from subprocess import call
import os
#as long as a = 1, the program will run
a=1
#default voice
voice = "rms"
#all the ways to ask a question
qHi = ["hi","hi!","hello","hello!"]
cQuit = ["quit","exit"]
def speak(output):
print "[Smart Alek Robot Head]: " + output
call(["flite", "-voice", voice, "-t", output])
speak("Ask a question or say a command to begin!")
while a is 1:
command = raw_input()
if command.lower() in qHi:
speak("Hello!")
if command.lower() in cQuit:
speak("Good Bye!")
a = 0
Go ahead and run it! Try to add some extra questions and commands. I was messing around and created a giant program with user accounts, notifications, voice changing, and time telling! If you would like to try my program, it is on my github page. Download the code with:
bone# git clone https://github.com/AlekMabry/RobotHead.git
Now enter the directory with the cd command:
bone# cd RobotHead/Speech/
Now simply run the program:
bone# python speak.py
Using Flite with Node.js:
If you are using cloud9, create a new file. If you are using terminal you can do so with nano:
bone# nano speak.js
Now enter this into the file:
#!/usr/bin/env node
var exec = require('child_process').exec;
function speak(phrase) {
exec('flite -t "' + phrase + '"', function (error, stdout, stderr) {
console.log(stdout);
if(error) {
console.log('error: '+ error);
}
if(stderr) {
console.log('stderr: '+ stderr);
}
});
}
speak("Hello, My name is Borris. "+
"I am BeagleBone Black, " +
"A true open hardware, " +
"community-supported embedded computer for developers and hobbyists. " +
"I am powered by a 1 Giga Hertz Sitara ARM Cortex-A8 processor. " +
"I boot Linux in under 10 seconds. " +
"You can get started on development in " +
"less than 5 minutes with just a single USB cable. " +
"Bark, Bark!");
If you used nano, type ctrl+x to exit the file. If you used cloud9, save the file as speak.js
Now it is time to test it! If you used cloud9, simply press run. If you used terminal, run:
bone# node speak.js
Now you can use flite in your projects!
Copyright © 2017 Einsteinium Studios