ArmadilloLabs

Sharing Knowledge about ARM, Linux and Development Platforms as Beaglebone Black.

29 May 2014

Using a Text to Speech (TTS)

Our Beaglebone Black is smaller, powerful and has a lot of things to say! In our LAST entry we configured Bluetooth and microphone so now is time to give it the needed speech!! :-)


The Speech synthesis is a great and complex world. Nowadays we can hear synthetic voices and maybe we wouldn't say 100% sure if it is human or synthesized. Unfortunately for us, open source seekers, there are not many options out there for TTS on Linux. For sure we are looking for high quality offline open source voices! If we discard some requirements a lot of options appear!

We are going to focus on open source/free to use text to speech applications. For an expanded list check in HERE.

- eSpeak: 50 languages, Offline, Robotic, Different Voices, Easy to use.
- Festival: 3 languages by default, Offline, Robotic, Different Voices, Uncomfortable but powerful.
- Mary: 8 languages and growing, Offline, Almost Natural, Different Voices.
- SVOX Pico: 5 languages, Offline, Not as bad as Robotic, 'Tricky' open source adapted from Android.
- Google TTS: 50 languages Aprox., Online, Some languages almost Natural and others Robotic.

Let´s start to test them. As usual we will begin running a system upgrade:
 pacman -Syyu
After that we will start installing eSpeak TTS:
 pacman -S espeak
To list all supported languages type this:
 espeak --voices
And this for a list of different voices for a language:
 espeak --voices=en
Finally let´s say something!
 espeak -ven "Hello, world!"
Now we are going to use Google Translate TTS services! We will install a player able to stream audio called mpg123. Remember that in this case TTS won´t work unless you have an Internet connection.
 pacman -S mpg123
And in this case is just simple as running as this:
 mpg123 -q "http://translate.google.com/translate_tts?tl=en&q=Hello, world!"
If you try to read more than 100 bytes you won´t be able to do it unless you try THIS.

These two solutions above for me are the best right now but if you want to try that SVOX Pico (Android) TTS you will have to download and compile the package from the AUR repository. Let´s take a minutes to explain how to do that. We will begin installing the full developers package for ArchLinux:
 pacman -S base-devel
Once the installation is finished let´s create a build directory, download tarball package and extract it:
 mkdir builds
 cd ~/builds
 curl -O https://aur.archlinux.org/packages/sv/svox-pico-git/svox-pico-git.tar.gz
 tar -xvzf svox-pico-git.tar.gz
 cd svox-pico-git
Now we will compile it! Relax because it will take a while:
 makepkg -Acs --asroot
After it finishes is time to install it, so that check the proper name inside compilation folder:
 ls -l
 pacman -U svox-pico-git-android.4.4.2_r2.34.g47af76b-1-armv7h.pkg.tar.xz
And finally let´s try how it works!
 pico2wave --lang=en-US --wave=/tmp/test.wav "Hello, world!";paplay /tmp/test.wav
As you see it is a matter of "How is my project and what I want for it?". For sure are paid solutions that are really awesome about audio quality although normally are heavy! A great solution for a mid-term is MaryTTS, sounds nice and is able to simulate feelings! Unfortunately has no many languages for now... :-(

So come on start to think about open possibilities that a Beaglebone with a TTS brings to you and remember: The only limit is the one you set yourself!! Thanks for reading me. :-)
No comments

26 May 2014

Connecting a Bluetooth Speaker and a Microphone

Has been arduous, difficult, frustrating and tricky but finally and after two weeks we made it!! Our Beaglebone Black with Archlinux is able to reproduce sounds recorded from an USB microphone on a Bluetooth speaker aaaand is not just that, it is able to "auto-connect" after power up too... We made this possible with Bluez 5, Alsa, Pulseaudio 5 and a lot of try and error. So come on, be my guest and start reading the whole process.


We will start as always updating our system and then checking if our Bluetooth dongle and our USB Microphone are detected and loaded by Linux, you shouldn´t have any problems if you use the ones we recommended in HERE.
 pacman -Syyu
 lsusb
 lsmod
Afer this we are going to install Bluez (Bluetooth protocol stack), Alsa (Audio devices handling) and Pulseaudio (Audio rerouting) latest versions and some utils. Pulseaudio should not be necessary but Bluez 5 is not supported by Alsa so if we want to use a Bluetooth Speaker we need to install it or jump down to the legacy methods with Bluez 4. Even more, if you want to use a Bluetooth Headset you won´t be able to do it with this latest Bluez 5, it is not supported yet!! Take a look in HERE for more information. Seems that Bluez 5 is not as good as it should be but we are here to install latest versions and for sure it will be improved by their developers. Let´s install then:
 pacman -S bluez bluez-utils bluez-libs alsa-utils pulseaudio-alsa
Now we will start Bluetooth service and will enable it at boot time.
 systemctl start bluetooth
 systemctl enable bluetooth
We are ready to start, scan and pair our bluetooth speaker! I´m using a Creative D200, others should behave similar...! (or not...). We will start pulseadio service on first place and then we are going to use the 'bluetoothctl' utility that is going to help us on make the pair process simple.
 pulseaudio --start -v 
 bluetoothctl
  power on
  agent on
  default-agent
  scan on (put your device on discovery mode before doing this!)
  pair 00:02:3C:26:FC:A6 (change this to your own MAC founded after scan command)
  0000 (your PIN code in here!)
  trust 00:02:3C:26:FC:A6
  scan off
  exit
If you find any problem (probably on first launch you won´t find any device) please reboot! At this point you should be paired with your bluetooth speaker but if you reboot your link will be lost and will have to connect manually again. To do that you have two different options. Pair your device again through 'bluetoothctl' utility or pair it 'manually'. Let´s check how to do it 'manually', as we made it before, we will launch pulseaudio service on first place:
 pulseaudio --start -v
Now we will check on the Sinks list which is our 'bluez.path', should be something like this: "/org/bluez/hci0/dev_00_02_3C_26_FC_A6"
 pactl list sinks
And finally we will power bluetooth up and will connect to it through Dbus system daemon:
 hciconfig hci0 up
 dbus-send --system --type=method_call --print-reply --dest=org.bluez /org/bluez/hci0/dev_00_02_3C_26_FC_A6 org.bluez.Device1.Connect
Ok, we are connected now but this is not fun enough! We want to make it automatically on boot time right? Let´s do it then... :-)

On first place we need to create a Pulseaudio Service file:
 nano /usr/lib/systemd/system/pulseaudio.service
And now write this on it:
 [Unit]
 Description=PulseAudio Sound System
 After=dbus.target sound.target

 [Service]
 ExecStart=/usr/bin/pulseaudio --system --disallow-exit -v

 [Install]
 WantedBy=multi-user.target
After Pulseaudio service we will create the Bluetooth service when we will powered it up and pair it:
 nano /usr/lib/systemd/system/bluespk.service
Write this on it:
 [Unit]
 Description=Connect Bluetooth Speaker
 After=dbus.target bluetooth.target

 [Service]
 ExecStart=/usr/lib/systemd/scripts/bluespk.sh
 Restart=always
 RestartSec=30

 [Install]
 WantedBy=multi-user.target
As you see the tricky stuff will be written on a bash shell so let´s create it!:
 nano /usr/lib/systemd/scripts/bluespk.sh
Type this:
 #!/bin/bash
 hciconfig hci0 up
 dbus-send --system --type=method_call --print-reply --dest=org.bluez /org/bluez/hci0/dev_00_02_3C_26_FC_A6 org.bluez.Device1.Connect
We need to give execution properties to our new fancy files:
 chmod +x /usr/lib/systemd/scripts/bluespk.sh
 chmod +x /usr/lib/systemd/system/bluespk.service
 chmod +x /usr/lib/systemd/system/pulseaudio.service
And now enable and start our services:
 systemctl enable pulseaudio.service
 systemctl start pulseaudio.service
 systemctl enable bluespk.service
 systemctl start bluespk.service
Due to Pulseaudio is not intended to be executed on boot time, we have to make it run on 'system' mode instead of running it on 'start' mode when we run it manually. Because of this 'system mode' we have to create and modify more files! Come on, we are reaching our goal... On first place we will change DBus policy:
 nano /etc/dbus-1/system.d/pulseaudio.conf
Write this:
 <!DOCTYPE busconfig PUBLIC  
  "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"  
  "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">  
 <busconfig>  
     <policy user="pulse">  
         <allow own="org.pulseaudio.Server"/>  
         <allow send_destination="org.pulseaudio.Server"/>  
         <allow receive_sender="org.pulseaudio.Server"/>  
         <allow send_destination="org.bluez"/>  
         <allow send_interface="org.bluez.Manager"/>  
     </policy>  
 </busconfig>  
Now open up Pulseaudio daemon configuration to modify it:
 nano /etc/pulse/daemon.conf
Uncomment these lines: 
 allow-module-loading = yes
 load-default-script-file = yes
 default-script-file = /etc/pulse/default.pa
And now we will create the 'pulse' user and group, and add it to the audio group:
 useradd pulse
 groupadd pulse-access
 usermod -a -G audio pulse
We will add as much users as we want to the pulse group, in our case just the 'root' user:
 usermod -a -G pulse-access root
And finally we are going to define a Home to pulse user.
 usermod --home /var/run/pulse pulse
 mkdir -p /var/run/pulse
 chown -R pulse: /var/run/pulse
That´s all, we made it, reboot and check the magic! If everything went OK your bluetooth speaker should be autoconnected to your Beaglebone Black! Take a look on these links for more information: 1, 2, 3, 4. We made it possible thanks to them! If something is failing try to find it out with this command:
 journalctl -b
We are now in position to record and play some audio. We will check Audio levels first, we can do this with 'alsamixer' GUI easily or manually with 'amixer'. Let´s check our current Mixer levels:
 amixer contents
If you are using our recommended devices you will have a similar Mixer configuration, so in order to set up our Playkbak volume to 100% and our recording volume to 40% (maximum for our Microphone in order to not distort) these are the commands:
 amixer cset numid=2,iface=MIXER,name='Capture Switch' on
 amixer cset numid=1,iface=MIXER,name='Capture Volume' 26281
 amixer cset numid=4,iface=MIXER,name='Master Playback Switch' on
 amixer cset numid=3,iface=MIXER,name='Master Playback Volume' 65536,65536
In order to force which will be our recording device we need to check his name with:
 pactl list
or through Alsa detected devices:
 arecord -L
In our case we will extract the information given by pactl sources device string. Now, clear your voice and begin to record some funny stuff during 5 seconds with a Signed 16 bit Little Endian sampling rate at 48000Hz:
 arecord -d 5 -f S16_LE -r 48000 -c 1 -D hw:1 -t wav test.wav
And finally let´s Play it on our sink device (get this string from 'pactl' command under sink name)!
 paplay -d bluez_sink.00_02_3C_26_FC_A6 --format=s16le --channels=1 --rate=48000 --file-format=wav test.wav
If you ear some noise, try setting up a lower recording volume. If this doesn´t help consider to use a better power supply or even a external-powered USB Hub. 

That´s all! A little step for the Mankind but a great one for us! And remember: Keep calm and Beaglebone! :)  
No comments

11 May 2014

Setting up a WiFi connection

I have been fighting during the last two days with my Beaglebone Black and ArchLinux and Debian in order to configure the WiFi connection with an extremely cheap, unsupported and non compilable driver USB WiFi 802.11n Stick. I failed, it beat me, too many hours reading, testing and finally... I decided to try another USB WiFi stick and it worked at the first try!!! XD So... we will talk today about how to configure our Beaglebone Black WiFi and no to die trying!


The first thing we will need is to connect our BBB through Ethernet and install a Linux shell in our PC to access through SSH. I think this way to work is easy than a direct connection with a keyboard. There are many terminals over there, if you are in Windows i would recommend you  to Install Cgywin: LINK

By default Arch/Debian had SSH enabled so nothing is requested to be installed, we will need to know which one is the IP of our BBB (for example you can check it on your Router active connections), launch Cgywin and write this command (change it to your IP accordingly!):
 ssh -p 22 root@192.168.1.106
If everything is OK and is the first time you request access, the fingerprint should be accepted, after that the BBB 'root' password will be asked, by default 'root' too (Arch&Debian). Congrats you have SSH access to BBB!

We will setting up our WiFi connection on Arch and Debien, they are using slightly different commands so come on, let´s start the thing!

It is always recommended to keep your system updated, so let´s do it on first place:
Arch:
 pacman -Syyu
Debian:
 apt-get update
 apt-get upgrade

Additionally on Arch, if you didn´t it before, update your BBB Bootloader:
 pacman -S uboot-beaglebone

After that we will enable NTP (Network Time Protocol) as Service and will change TimeZone:
Arch:
 systemctl enable ntpd
 timedatectl set-timezone Europe/Madrid
Debian:
 apt-get install ntp
 echo "Europe/Madrid" > /etc/timezone
 dpkg-reconfigure -f noninteractive tzdata

We will install 'wpa_supplicant' to negotiate the authentication on your network.
Arch:
 pacman -S wpa_supplicant
Debian:
 apt-get install wireless-tools wpasupplicant

In our next step we are going to find out which is our WiFi interface (typ: wlan0) supposing was not any driver problem and your device is automatically detected by the Linux Kernel! After that we will edit the device interface file were configuration about connection will be inserted.
Arch:
 ip addr
 cp /etc/netctl/examples/wireless-wpa /etc/netctl/wlan0
 nano /etc/netctl/wlan0
Debian:
 ip a
 nano /etc/network/interfaces

Change information according with your connection info (this sample is for a WPA2)
Arch:
 Description='My WiFi Device'
 Interface=wlan0
 Connection=wireless
 Security=wpa
 ESSID=YourWiFiNameHere
 IP=dhcp
 Key=YourPasswordHere
Debian:
 auto wlan0
 iface wlan0 inet dhcp
 wpa-ssid "YourWiFiNameHere"
 wpa-psk  "YourPasswordHere"

And finally we will set our wlan up, we will connect to it and put it like a service that will be auto-executed after our BBB reset.
Arch:
 ip link set wlan0 up
 netctl start wlan0
 netctl enable wlan0
Debian:
 ifup wlan0

That´s all! You should now be connected to your WiFi! Check the assigned IP Addr and try to connect through a SSH to finally detach your Ethernet cable! I took the information from this two sites: Arch and Debian so take a look  in there to amply your knowledge.

Thanks for reading me and remember that a journey of a thousand miles begins with a single step... enjoy stepping! :-)
No comments

07 May 2014

Installing Arch Linux

Our purpose for today is to install Arch Linux on a MicroSD card that we will plug onto our Beaglebone Black. It is not a difficult process and it is almost detailed on Arch Linux ARM webpage: LINK


We have selected this Linux distro because it is light and minimalist, has only and just necessary stuff (we will have to install manually some things that are preinstalled on other distros and probably this will cause us some headache but no pain no gain!).

The process will be as easy as format the MicroSD, download the Beaglebone bootloader, the Arch Linux filesystem and write them on the MicroSD. We will perform these steps on Linux so unless you have your preferred distro I will recommend you download and launch a Live USB with Xubuntu.


Xubuntu is an Ubuntu brother thought for medium age computers and from my point of view it works like a charm! Download it from here: Get Xubuntu!

If you are running Windows you should download a tool called "Universall USB Installer" from PendriveLinux guys that will simplify for you the Live USB Xubuntu creation. Get UUI! Install it, follow the steps, reboot your computer, change the BIOS for booting from an USB device and welcome to Xubuntu!

Ok, so you are now under Xubuntu, you took your time to configure WiFi, your Language, TimeZone, Keyboard, etc. Let's get started!

Open a Terminal and List partition tables so write:
 sudo fdisk -l
Search carefully (extract it and insert it twice to be sure!) for your MicroSD card, in my case: "sdb". Start fdisk to partition it:
 sudo fdisk /dev/sdb
1. Type o to clear any partition the card
2. Type p to list partitions (should be empty!)
3. Type n to add a partition, p for primary, 1 for the first partition, enter for the default first sector, +64M for the last sector. Type t to change the partition type, e for W95 FAT16 (LBA). Type a to set the bootable flag and 1 to apply it on first partition. Now type to add another partition, p for primary, for the second partition, enter for the default first sector, enter for the default last sector. Finally type w to write partition table.
4. Create the FAT16 filesystem:
 sudo mkfs.vfat -F 16 /dev/sdb1
5. Create the EXT4 filesystem:
 sudo mkfs.ext4 /dev/sdb2
6. Extract the bootloader into the first partition:
 sudo wget http://archlinuxarm.org/os/omap/BeagleBone-bootloader.tar.gz
 sudo mkdir boot 
 sudo mount /dev/sdb1 boot  
 sudo tar -xvf BeagleBone-bootloader.tar.gz -C boot
 sudo umount boot
7. Extract the root filesystem into the second partition:
 sudo wget http://archlinuxarm.org/os/ArchLinuxARM-am33x-latest.tar.gz
 sudo mkdir root 
 sudo mount /dev/sdb2 root  
 sudo tar -xvf ArchLinuxARM-am33x-latest.tar.gz -C root
 sudo umount root
8. That's all! Insert the MicroSD into the Beaglebone Black and power it while holding down the boot switch (the one nearest the HDMI connector), this will boot the board from MicroSD instead of eMMC. As User/Pass type root/root and enjoy!

Thanks for reading me and remember, if you can think it you can build it! :)
No comments

04 May 2014

Getting Started with Beaglebone Black!

This post is a basic response to: I´ve received my beaglebone black, opened the box, connected it through HDMI to the TV. What´s next?... Well you were faster! Let´s take a minute to see these two out of the box videos/getting started videos:

 

As you can see specs are awesome and it is easy as hell to link it to a computer and made a simple 'Hello World' blinking Leds. So what do we have on our hands? Check this!


That ARM SoC is more than enough to move any Linux Distro or Android, to see your movies on the TV and for the reason we are here... to develop The Next Big Thing to change this world for good! :-)

We will enter on detail on future publications for now it is OK just to have a picture about BBB. Here you have some useful links for more information:

In order to have a full 'Inspector Gadget' bag I´m going to recommend you a list of things I consider mandatory to have:

- AC 100-240V / DC 5V 2A Plug USB Power Supply. LINK
- USB 5V 2A / 5,5mm Cable. LINK
- Beaglebone Case. LINK
- MicroHDMI to HDMI Cable. LINK
- 4 port USB Switch. LINK
- USB Wireless-N adaptor. LINK
- USB Microphone. LINK
- USB Bluetooth. LINK
- Bluetooth Speaker. LINK
- Micro SD HC Card 4GB
- Logitech K400 (Keyboard + Touchpad)

If you just bought your BBB probably you have received the latest B Hardware revision coming with a Linux Angstrom distribution. I´m not going to evaluate it but I´m going to tell you that they are migrating to Linux Debian distro so let´s take a few minutes to upgrade our BBB!


The first thing you will need is to download and uncompress latest Debian BBB eMMC flasher: Latest Images. Download and install Image Writer for Windows. Connect the Micro SD Card to your computer and write it with that Image you downloaded through ImageWriter!

Extract and Insert the card on your Turned OFF BBB. Now Hold On the Boot button and apply Power. The flashing eMMC process will begin and LEDs will be flashing until it finishes that you will see it because Led will maintain solid! After that everything is done. Remove power, extract your SD card and follow the Getting Started guide to be sure you got familiar with your board hardware, software and possibilities. 

On our next entry we will install an ultra light Linux distro called Archlinux on a Micro SD card and then we will start to write some tips&tricks! Thanks for reading me and let your ideas take flight! 
No comments