How to voice type and print the text on LCD using Raspberry Pi

Jarvan   2017/12/11   How to voice type and print the text on LCD using Raspberry Pi已关闭评论

Voice typing feature is quite common to mobile phones; it is considered faster and user-friendly to those who find it difficult to type to input the question about which they need information. If typing fast is required or your handicap, this feature works the best for you.
In this article, we will input voice via an Android App and the output will be displayed on LCD using Raspberry Pi. This requires a 16x 2 LCD with Raspberry Pi which is equipped with Bluetooth to receive inputs from the mobile phone.
Start with Connecting 16×2 LCD with Raspberry Pi:
Setting Bluetooth is preceded by interfacing 16x 2 LCD with Raspberry Pi. Bluetooth setup, first we will interface 16×2 LCD as Raspberry Pi accessory. External Adafruit Library is used for making this interface happen. Adafruit Library can be installed using this command:
git clone
cd ./Adafruit_Python_CharLCD
sudo python install
This is followed by importing the library in the python program using the command:
import Adafruit_CharLCD as LCD
Now, LCD pins are connected with Raspberry Pi with the help of circuit diagram like this:

Circuit diagram that LCD pins are connected with Raspberry Pi Here is the list of functions provided in Adafruit Library for controlling the LCD.

  • lcd.set_cursor(col, row) = Move the cursor to any position at column and row.
  • lcd.clear() = To clear the LCD.
  • lcd.blink(True) = To blink the cursor (True or False)
  • lcd.move_right() = To move the cursor to Right by one position.
  • lcd.move_left() = To move the cursor to Left by one position.
  • lcd.message(message) = To print the text on LCD.

Now we will connect our Raspberry Pi with Android Smartphone using Bluetooth.
Bluetooth Communication requires few packages
First, with the help of a dongle, the Bluetooth communication is set up in Raspberry Pi. This is required in case the Raspberry Pi is not provided with in-built Bluetooth. Raspbian is updated first of all using below commands:
sudo apt-get update and sudo apt-get upgrade
This is followed by installation of a few packages which are related to Bluetooth, and Raspberry Pi is then reboot.
sudo apt-get install bluetooth blueman bluez
sudo reboot
We also install Python Library to exchange data by RFCOMM by using Python language.
Finally, we need python Library for Bluetooth communication so that we can send and receive data through RFCOMM using Python language:
sudo apt-get install python-bluetooth
Additionally, the GPIO support libraries are also installed for Raspberry Pi:
sudo apt-get install python-rpi.gpio
Voice Typing on LCD – start trying now
You can pair a variety of devices such as mobile phones and others with Raspberry Pi using the suitable command. Once the pairing of mobile phone is done, an Android App such as BlueTerm App is installed. This app supports RFCOMM/SPP protocol. The Android App is made to communicate with Raspberry Pi with the help of a Bluetooth Serial Adapter. There are a few other Bluetooth Terminal Apps also available that are compatible with RFCOMM socket.
To voice type on LCD, the Python Program stated below is used. While running this program, you can connect the Raspberry Pi display from the BlueTerm App simultaneously. The soundness of connection can be verified by the appearance of connected Raspberry Pi message appearing at the top right corner of BlueTerm App. Finally, you are ready for voice-typing.
Voice Typing on LCDBlueTerm

Python code is provided below. (Source of the code: )
If you want messages in bigger fonts, you can use a bigger LCD display in this project.
This is the Python Code useful for trying Voice Typing
import bluetooth
import RPi.GPIO as GPIO   #calling for header file which helps in using GPIOs of PI
import Adafruit_CharLCD as LCD
# Raspberry Pi pin setup
lcd_rs = 18
lcd_en = 23
lcd_d4 = 24
lcd_d5 = 16
lcd_d6 = 20
lcd_d7 = 21
lcd_backlight = 2
# Define LCD column and row size for 16×2 LCD.
lcd_columns = 16
lcd_rows = 2
lcd = LCD.Adafruit_CharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows, lcd_backlight)
server_socket=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
port = 1
client_socket,address = server_socket.accept()
print “Accepted connection from “,address
while 1:
 data = client_socket.recv(1024)
 print “Received: %s” % data
 if (data != “”):
  print (len(data))
  if (len(data) > 16):  #breaking long strings into 2 parts
   i = len(data)-16
   a,b = data[:16], data[16:]  #first string will be of 16 char
   print i
   print a
   print b
 if (data == “clear”):
 if (data == “q”):
  print (“Quit”)
Voice typing using Google Keyboard is a great achievement. This feature can easily be added with the help of Android Apps and display for Raspberry Pi. The user does require basic knowledge of Python language to accomplish this project. Availability of library of tools makes the project easier and faster to complete.
Thus, Raspberry Pi has proved its worth in bringing more innovations to the existing devices. This mini-computer of credit card size, due to its unmatched flexibility, has changed the way computers and mobile phones were used. The best technology is one that is friendly to privilege and handicapped alike. Voice typing has added to the user-friendliness of the computer and mobile phones and made them accessible to visually impaired users too. The number of Raspberry Pi GPIO pins can be altered as per requirement if you choose to extend this project. So, try it yourself and add to your knowledge base.