['Welcome, I am python developer and roboticist based in Indonesia. This blog is mainly focused on programming topics and robotic topics']



Blog Posts



Some simple tts functions in python



  • 1. using espeak ------  this one is a bit crappy
  • 2. using google api, this one is the best, the sound is so natural compared to other implementations


    def tts_offline_espeak_speak(self, words, speed, lang):
            #try:
            #print(inspect.stack()[0][3])
            if (len(str(lang)) < 1) or lang == 0:
                lang = config_tts.tts_lang
            if (len(str(speed)) < 1) or speed == 0:
                speed = config_tts.tts_speed
            if speed == "slow":
                spd_q = "90"
            elif speed == "medium":
                spd_q = "110"
            elif speed == "fast":
                spd_q = "170"
            else:
                spd_q = "100"
            cmd_espeak = "espeak -v" + lang + "+f5 -s " + spd_q + ' "' + words + '"'
            #print "[" + cmd_espeak + "]"
            pipe = os.popen(cmd_espeak).read()
            print pipe
            '''
            except:
            self._log_txt("err", inspect.stack()[0][3])
            print ("[-] exception :" + inspect.stack()[0][3])
            pass
            '''
  
    def tts_online_gtts_speak(self, words, speed, lang):
            #try:
            #print(inspect.stack()[0][3])
            if (len(str(lang)) < 1) or lang == 0:
                lang = config_tts.tts_lang
            if (len(str(speed)) < 1) or speed == 0:
                speed = config_tts.tts_speed
            is_slow = True
            if len(speed) > 1:
                if (speed == "fast"):
                    is_slow = False
            else:        
                if config_tts.tts_speed == "fast":
                    is_slow = False
            if len(lang) > 1:
                tts = gTTS(text= words, lang=lang, slow=is_slow).save(config_tts.tts_tmp_path + "tmp.mp3")
            else:
                tts = gTTS(text= words, lang=config_tts.tts_lang, slow=is_slow).save(config_tts.tts_tmp_path + "tmp.mp3")
            #cmd = "play " + config_tts.tts_tmp_path + "tmp.mp3"
            os.system("killall -9 gnome-mplayer;killall -9 mplayer")
            cmd = "gnome-mplayer --volume " + config_tts.tts_volume + " -q "  + config_tts.tts_tmp_path + "tmp.mp3"
            pipe = os.popen(cmd).read()
            print pipe
        
            '''
            except:
            self._log_txt("err", inspect.stack()[0][3])
            print ("[-] exception :" + inspect.stack()[0][3])
            pass
            '''
       


Python3 Database Class for Viewing Data

python3 database class that I used several times for viewing data


#!/usr/bin/env python3
import sys, os
import pymysql
import config
import inspect

class RingDb:
    def bukadb(self):
        try:
            print("[+] connecting to  database")
            config.conn = pymysql.connect(host=config.host,user=config.username,password=config.password,db=config.database,charset='utf8mb4',cursorclass=pymysql.cursors.DictCursor)
            print("[+] connected to database")
        except:
            print ("[-] exception at callfunc :" + inspect.stack()[0][3])
            pass

    def getrows(self,table_name,colname=None,valname=None):
        try:
            if config.conn != None:
                cur = config.conn.cursor()
                if ( (colname != None) and (valname != None) ):
                    sql = "SELECT * FROM `" + table_name + "` where `"+colname+"` like '"+valname+"'"
                else:
                    sql = "SELECT * FROM `" + table_name + "`"
                print("[sql] " + sql)
                cur.execute(sql)
                dictpage = cur.fetchall()
                return dictpage
        except:
            
            print ("[-] exception at callfunc :" + inspect.stack()[0][3])
            pass

   
    def ret_total(self, table_name, kategori=None):
        try:
            total = 0
            cur = config.conn.cursor()
            if ( (kategori == None) or (kategori == "all") or (len(kategori) < 1) ):
                cur.execute("select count(*) from " + table_name)
            else:
                cur.execute("SELECT COUNT(*) from " + table_name + " where `descr`='"+kategori+"'")
            total = cur.fetchone()
        except:
            
            print ("[-] exception at callfunc :" + inspect.stack()[0][3])
            pass
        return total

    

C Socket Programming in Linux

In this video, I developed a dns server using c in linux around Nov 2013


A Robot Without Encoder

This robot movement was not so smooth,  since I haven't add some encoders for it's wheel.


A Ludicrous Robot

This video demonstrate when I shocked my tiny robot several times. Detail instruction to develop this robot can be found at https://sw0rdm4n.wordpress.com/category/wheeled-robot/ (my old blog)


Vision of A Robot

This video shows android interface that I developed for my robot. This simple interface was used to control my robot camera and movements. Check this out


A Robot Answering my Questions

Do you like robot ?   This video demonstrate a robot answering my questions about security exploitation technics.

Technology:

  • python (speech recognition, speech to text, wolfram alpha as knowledge agent)
  • electronic circuit : h-bridge, tlc5949 to control multiple servo using arduino

php function for translating boarding pass data

If you have a flight boarding pass, you can try to get your data using pdf417 barcode scanner then pass it as reference into $data_barcode variable. Your boarding pass data will be translated into human readable output.

This function was inspired by flighthistorian (https://www.flighthistorian.com/boarding-pass), hopefully you like it.

 

<?php
function _parse_full_emanifest_data_print_detail($data_barcode) {
    /*
    this php function was inspired by flighthistorian.com
    */
    $ar_print = array();
    $data_titles = array();

    $format_code = substr($data_barcode,0,1);
    array_push($ar_print, $format_code);
    array_push($data_titles, "Format Code");

    $number_of_legs = substr($data_barcode,1,1);
    array_push($ar_print, $number_of_legs);
    array_push($data_titles, "Num of Legs");

    $passenger_name = substr($data_barcode,2,20);
    array_push($ar_print, $passenger_name);
    array_push($data_titles, "Passenger Name");

    $electronic_ticket_indicator = substr($data_barcode, 22, 1);
    array_push($ar_print, $electronic_ticket_indicator);
    array_push($data_titles, "Electronic Ticket Indicator");

    $pnr = substr($data_barcode,23,7);
    array_push($ar_print, $pnr);
    array_push($data_titles, "PNR");

    $from_city = substr($data_barcode,30,3);
    array_push($ar_print, $from_city);
    array_push($data_titles, "From");

    $to_city = substr($data_barcode,33,3);
    array_push($ar_print, $to_city);
    array_push($data_titles, "Dest");

    $operating_carrier_designator = substr($data_barcode,36,3);
    array_push($ar_print, $operating_carrier_designator);
    array_push($data_titles, "Operating Carrier");

    $flight_num = substr($data_barcode, 39, 5);
    array_push($ar_print, $flight_num);
    array_push($data_titles, "Flight Num");

    $date_of_flight = substr($data_barcode, 44, 3);
    array_push($ar_print, $date_of_flight);
    array_push($data_titles, "Date of Flight");

    $compartment_code = substr($data_barcode, 47, 1);
    array_push($ar_print, $compartment_code);
    array_push($data_titles, "Compartment Code");

    $seat_num = substr($data_barcode, 48, 4);
    array_push($ar_print, $seat_num);
    array_push($data_titles, "Seat Num");

    $checkin_sequence = substr($data_barcode, 52, 5);
    array_push($ar_print, $checkin_sequence);
    array_push($data_titles, "Checkin Seq");

    $passenger_status = substr($data_barcode,57,1);
    array_push($ar_print, $passenger_status);
    array_push($data_titles, "Passenger Status");

    $field_size_of_following_variable_size = substr($data_barcode, 58, 2);

    $pax_status = $jenis;
    array_push($ar_print, $jenis);
    array_push($data_titles, "Pax Status");

    $tgl = $this->generate_time("tanggal");
    $bulan = $this->generate_time("bulan");
    $tahun = $this->generate_time("tahun");
    $nama_hari = $this->generate_nama_hari();
    $full_tgl = $this->generate_cur_date() . " " . $this->generate_cur_time();
    array_push($ar_print, $full_tgl);
    array_push($data_titles, "Full Date");

    $tgl_mysql = $tahun . "-" . $bulan . "-" . $tgl;

    $r_from = $this->get_ar_tval_cond("master_cities_domestik", "iata_code", $from_city);
    $r_to = $this->get_ar_tval_cond("master_cities_domestik", "iata_code", $to_city);
    if ( (!empty($r_from)) ||  (!empty($r_to)) )
        $dom_or_int = "domestik";
    else {
        $dom_or_int = "internasional";
    }
    array_push($ar_print, $dom_or_int);
    array_push($data_titles, "Domestic/International");

    $cur_date_mysql = $this->generate_cur_date_mysql();

    if ( (strstr($data_barcode, " MR ")) || (strstr($data_barcode, " MSTR "))) {
        $gender = "male";
    }
    else if ( (strstr($data_barcode, " MS ")) || (strstr($data_barcode, " MISS ")) || (strstr($data_barcode, " MRS "))) {
        $gender = "female";
    }
    else {
        /* maybe this one ? */
        if ($format_code == "M")
            $gender = "male";
        else
            $gender = "female";
    }

    array_push($ar_print, $gender);
    array_push($data_titles, "Gender");

    if ( (strstr($data_barcode, "MR")) || (strstr($data_barcode, "MSTR")) || (strstr($data_barcode, "MRS")) || (strstr($data_barcode, "MS")) || (strstr($data_barcode, "MISS")) )
        $adult_infant = "adult";
    else
        $adult_infant = "infant";

    array_push($ar_print, $adult_infant);
    array_push($data_titles, "Adult/Infant");

    /* extract first name and last name */
    $ar_nama = explode("/",$passenger_name);
    $fname = $ar_nama[1];
    array_push($ar_print, $fname);
    array_push($data_titles, "Fname");

    $lname = $ar_nama[0];
    array_push($ar_print, $lname);
    array_push($data_titles, "Lname");
    $i = 0;
    foreach($ar_print as $should_print_data) {
        $data_title = $data_titles[$i];
        print "<div id=row><b>$data_title</b><br>$should_print_data</div><hr>";
        $i++;
    }
}

?>