mahtab Firouzinegin nourmohammadEhsan Aerabi
Published

The Guide Robot

Understand anything about anything with guide robot!

IntermediateShowcase (no instructions)Over 1 day1,756
The Guide Robot

Things used in this project

Story

Read more

Schematics

dc motor driver

motors and gyrybox

speaker and raspberry pi

Code

text to speech 1

Python
this is code of the first audio. it means that for example the robot stops in front of first board and we want to introduce that. so we write it's introduction before, and now we want to convert it into a voice.
from num2words import num2words
from subprocess import call


cmd_beg= 'espeak '
cmd_end= ' | aplay /home/pi/Desktop/Text.wav  2>/dev/null' # To play back the s$
cmd_out= '--stdout > /home/pi/Desktop/Text.wav ' # To store the voice file

text = "The Mona lisa painting is painted by leonardo davinchi."
print(text)

#Replacing ' ' with '_' to identify words in the text entered
text = text.replace(' ', '_')

#Calls the Espeak TTS Engine to read aloud a Text
call([cmd_beg+cmd_out+text+cmd_end], shell=True)

telegram bot

Python
this is the code of telegram bot that we use for controlling the robot to play the audios. this audios have been changed from text to voice.
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
import logging
import wave
import pyaudio
import time

logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)$
                    level=logging.INFO)

logger = logging.getLogger(__name__)

def start(bot, update):
        update.message.reply_text('select your wav file:\n insert /first for fi$

def first(bot, update):
        chunk = 1024
        f = wave.open(r"/home/pi/Desktop/Text.wav","rb")
        p = pyaudio.PyAudio()
        stream = p.open(format = p.get_format_from_width(f.getsampwidth()),
                channels = f.getnchannels(),
                rate = f.getframerate(),
                output = True)
        data = f.readframes(chunk)

        while data:
                stream.write(data)
                data = f.readframes(chunk)

        stream.stop_stream()
        stream.close()

        p.terminate()
        update.message.reply_text('The ROBOT explained about MONALISA painting.')
        
def second(bot, update):
        chunk = 1024
        f = wave.open(r"/home/pi/Desktop/Text1.wav","rb")
        p = pyaudio.PyAudio()
        stream = p.open(format = p.get_format_from_width(f.getsampwidth()),
                channels = f.getnchannels(),
                rate = f.getframerate(),
                output = True)
        data = f.readframes(chunk)

        while data:
                stream.write(data)
                data = f.readframes(chunk)

        stream.stop_stream()
        stream.close()
        p.terminate()
        update.message.reply_text('The ROBOT explained about THE WEEPING WOMAN painting.')
        
def third(bot, update):
        chunk = 1024
        f = wave.open(r"/home/pi/Desktop/Text2.wav","rb")
        p = pyaudio.PyAudio()
        stream = p.open(format = p.get_format_from_width(f.getsampwidth()),
                channels = f.getnchannels(),
                rate = f.getframerate(),
                output = True)
        data = f.readframes(chunk)

        while data:
                stream.write(data)
                data = f.readframes(chunk)

        stream.stop_stream()
        stream.close()
        p.terminate()
        update.message.reply_text('The ROBOT explained about THE SCREAM painting.')

def echo(bot, update):
        update.message.reply_text(update.message.text)


def error(bot, update, error):
        logger.warning('Update "%s" caused error "%s"', update, error)


def main():
        updater = Updater("470332284:AAEEJIXN5FRtxeVg5hMpDKMasIc1aVZOfEQ")
        dp = updater.dispatcher
        dp.add_handler(CommandHandler("start", start))
        dp.add_handler(CommandHandler("first", first))
        dp.add_handler(CommandHandler("second", second))
        dp.add_handler(CommandHandler("third", third))
        dp.add_handler(MessageHandler(Filters.text, echo))
        dp.add_error_handler(error)
        updater.start_polling()
        updater.idle()


if __name__ == '__main__':
        main()

text to speech 2

Python
the second introduction.
from num2words import num2words
from subprocess import call


cmd_beg= 'espeak '
cmd_end= ' | aplay /home/pi/Desktop/Text1.wav  2>/dev/null' # To play back the $
cmd_out= '--stdout > /home/pi/Desktop/Text1.wav ' # To store the voice file

text = "The Weeping Woman, is an oil on canvas painted by Pablo Picasso in Fran$
print(text)

#Replacing ' ' with '_' to identify words in the text entered
text = text.replace(' ', '_')

#Calls the Espeak TTS Engine to read aloud a Text
call([cmd_beg+cmd_out+text+cmd_end], shell=True)

Credits

mahtab Firouzi

mahtab Firouzi

1 project • 0 followers
student of information technology engineering at Hamedan university of technology
negin nourmohammad

negin nourmohammad

0 projects • 0 followers
Ehsan Aerabi

Ehsan Aerabi

18 projects • 60 followers
Researcher on IoT and Embedded Systems

Comments