Script etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
Script etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

10 Eylül 2015 Perşembe

How to use Vox for basic system function,remote VNC Raspberry Pi login and others ( Vox part 2 script)




 This post show How to use Vox for controlling system basic function using voice recognition .It is a continuity from my previous post    .At this moment, The program consist of 3 main script.There will be  a more function added to this program in the future .

Script

1.vox (main script)
2.vrec (recording script. will use more for future development)
3.vsort ( return text integrate with local system script )


Script details

1.Vox script(main script)



1.1.Variable declaration and changing directory working directory to ~/vox-master .

URL="http://www.google.com/speech-api/v1/recognize?lang=en-us&client=chromium&maxresults=10" 


 cd ~/vox-master

If you use different language than english, you need to  change "en-us" in the above script..Check here for language reference. Notice the "&maxresults=10" line . What this line do is, it request for maximum 10 results from Google server.


1.2. Calling the recording program.

./vrec

Currently, the program can only record for 3 seconds  .You can remove this line and just  use          " rec -r 16000 -b 16 voice.flac trim 0 3 " instead .The recorded file will be save as "voice.flac"

1.3 "voice.flac" will then be send over to Google voice search engine and it will feedback a text message to our system . The retrieve result from Google is then pipe into a file call "result" .I use "result" information  to custom  my "vsort"file .

wget -q -U "Ninetailfox" --post-file voice.flac --header "Content-Type: audio/x-flac; rate=16000" -O - "$URL" >result

The detail information of the above command is much more easier to understand with snapshot from Wireshark . Click here to download vox wireshark file .

Vox Wireshark snapshot



1.4 Sorting out the return result and send it over to "vsort" script. After vsort file being execute, The program will wait for 5 second delay before executing .


RETURN="$(cat result | cut -d\" -f12 )"
echo "you said :$RETURN"
./vsort "$RETURN"
sleep 5

2 Vrec script .
At this moment, Vrec only consist of one line .I'll be using this file more in the future development.


3.Vsort script


What this script does is it associate the word that has been retrieve from Google server and use it to execute a command  that is associated with your system. You need to make sure what kind of word is use and what command you want  to execute . You need to edit this file to make it work with your system.



In the existing script ,

case "$1" in
 'ping server') 
 cd /home/shark_attack/Programming/bash
 ./pi -ping 
 ;;

'ping server' is the word I choose and I want it to execute my "./pi" script  in  "/home/shark_attack/Programming/bash" . Click here to check my previous post on my pi script .

I will update more function on vox in the future . At the moment, I'm testing some other stuff and playing around with some code. That's it for now.Please leave comment on the box below .




Devamı »

How to create simple interactive folder directory bash script


    When I started using Linux, I always have the problem of navigating into my working folder using the terminal.The case sensitive nature of Linux make it more frustrating and often time get me demotivate and lost in my own system!!.I still remember it took me 3 minute to find the right folder and  just type "cd " and "ls"  along the way . I don't have strong understanding on Linux architecture and how file was arrange back then.

   In this post, I'm going to share  a simple script that we can run directly from the terminal to our respective working folder. This is a simple script that use  if,else,elif function .

Below is the breakdown of this script and how to use it .

1 . The script start off like how a normal bash file look like.Since this is an easy script Next I'm declaring the variable that going to be use in the script. It is better to write all at once for the directory for future maintenance.

#!/bin/bash
#Title : Lazy bum directory link
#Author : shark Attack
#REV:1.0

fold_prog='/home/shark_attack/Programming'
fold_proj='/home/shark_attack/Videos/PROJECT'
fold_mus='/home/shark_attack/Music'
fold_doc='/home/shark_attack/Documents'
fold_hack='/home/shark_attack/hack

2.This part of the script will print  on terminal requesting input from user

echo "Please type folder selection that you want to go"
echo  "1.programming"
echo  "2.project"
echo  "3.music"
echo  "4.documents"
echo  "5.hack"

3. input from the user wil be save in variable call "gugu"

read gugu

4.I used "gugu" as a loop control in this script .Basic idea of this script is when the word type in the terminal is similar with the selection above, the system will navigate it to respective folder.system will then list or open a graphical user interface depending on what user want to do .

if  [ "$gugu" == "project" ]; then
    cd "$fold_proj"     #this will change the current folder directory to desired location
        ls -a                    #listing your directory
    #nautilus "$PWD" 
   
   
elif [ "$gugu" == "programming" ]; then
    cd "$fold_prog"
        ls
       # nautilus "$PWD"
   

elif [ "$gugu" == "documents" ]; then
    cd "$fold_doc"
        ls
        nautilus "$PWD"       #nautilus will open a GUI from your terminal
   
elif [ "$gugu" == "music" ]; then
    cd "$fold_mus"
        ls
      

elif [ "$gugu" == "hack" ]; then
    cd "$fold_hack"
        ls


5. exit loop
else                    \
    echo "folder is not in selection.please try run the command again .."
fi


6. save the script in the location  that was include in your system path. you can type 'echo $PATH' on your terminal . Please refer to my previous post on this .

7. Open the terminal and change the file type

shark_attack@Positive-Space:~$ chmod 754 /home/shark_attack/Programming/bash/desktop


8. Run the command. You can run the command straight from your terminal. Note that there is a different when running as "filename" or ". filename" with and without  . (dot) . . (dot)  is a longer version of "source"

  When a script is run using "source" it runs within the existing shell, any variables created or modified by the script will remain available after the script completes. In contrast if the script is run just as "source.sh" , then a separate subshell (with a completely separate set of variables) would be spawned to run the script.please refer here for more details

9. Run the command from terminal and adjust the script to  what is suitable for your usage
shark_attack@Positive-Space:~$ . desktop

or

shark_attack@Positive-Space:~$ source desktop 

That's it for now.Please find the script here for download and subscribe my page and youtube channel for more tips.



Devamı »

How to use Voice for basic system control function,Raspberry pi remote VNC server login etc (Vox install and use)




   A few days ago I played around with Google voice search and wonder if  Google has this good program that can detect voice and return their search result, I can use this function to make use on my system . Instead of  writing big chunk program with dictionary stuff to do some basic voice recognition function,I can make use Google server voice recognition service to return the text and execute it on my system. Once I start to work around the script, I realize there is heaps of function I can integrate with this script. This can be a good program by itself.

  In this post , I'm going to share how you can use Google voice recognition to do simple task with your system . The idea behind this program is  using your recorded voice,send it to Google server and it will  translate the voice to text . The translated text will be use as a control structure to run basic command for your system .

What do you need for this project?

1. Internet connection
2. Built in or external mic
3. Any Linux Distro (Bash shell)
5. A little bit of bash scripting knowledge

Steps

1. Download the source code zip file. Extract it on your "home" folder . Please click here

Downloading Vox


2.Run the "setup" file
shark_attack@Positive-Space:~$ cd vox-master
shark_attack@Positive-Space:~/vox-master$ sudo ./setup   
#installing Vox dependencies and run it                

3.Set your keyboard shortcut .Open your keyboard setting . Since I'm running on Ubuntu 12.04 , below is snapshot how to do this. If you are running on different Linux Distro, you can try to look around in your system .

3.1. Search for Keyboard setting
Search for Keyboard setting

3.2 Click "Shortuct>Custom Shortcut" and click the '+' sign . Give it a name .You can use your own name if you want to :)

add new shortcut

3.3 In the command box . add below command in the shortcut box

gnome-terminal -e /usr/local/bin/vox

edit the command part

3.4 Click on the right side and give it a shortcut that you want . In my case, I use "CTRL -M"
 
choose your shortcut

4. Edit "vsort" file to use it with your  system setting.The voice recognition is not 100% accurate because of different dictation between people and how Google server feedback the result to our system.For that reason ,I save 10 utterance  that being detected by Google in the "result" file . You can use the result uttterence word by editing in  the "vsort" file .I will share the detail script drill down information in the next post .Stay tune .

5.Next test and play around with it. You can run it from the terminal or use the shortcut key you  have set .
shark_attack@Positive-Space:~$ vox

The program should work with basic file searching using your own voice.This program is still under testing phase and I will update more function to vox.Anyone interested with this project  or have cool idea what to include in are welcome to contribute.Please visit my Github page.



Read Previous :How to convert video file type with robot voice feedback using bash script on Linux
Read Next :How to use Vox for basic system control,remote VNC Raspberry Pi login and others (Vox part 2)
Devamı »

How to do progress indicator using bash



  Sometimes when our machine is doing job for longer time period, we need some methods to make sure the end user being keep updated. One such example I can think off is when  we are  running our system backup script.The reason why we need such application is to make sure the end user feel content and not thinking that the script they are running are  hung or inactive.It is important for the script to do their job until finish without being interrupted .

Few example that I can think of for the progress indicator are as below

Dots
Rotating Line
Progress Counter counting to 100%

It must be highlighted that all this application are running in a loop(for,while,until)  and it should be use as a function in your script.Below are example of progress indicator script that you can try to play around

Dot

#!/bin/bash

 INT=1                                #declaring the variable


while true
do
     echo -n "." 
     sleep $INT 
done





 Rotating Line

#!/bin/bash

CHA=( "-" "\\" "|" "/" )
INT=1             
CNT=0              

while true                             #While function as controlling loop
do

    loc=$(($CNT % 4))            #using the modulo expression for arithmetic fn 

    echo -en "\b${CHA[$loc]}"  #check this link for bash arrays info.
    CNT=$(($CNT + 1))            #Increasing the CouNTer
    sleep $INT

done



 Increasing Progress indicator

#!/bin/bash

LIST="1 2 3 4 5 6 7 8 9 10"             #Note that there is a different when we
INT=1                                          #use (),"",'' .Maybe Ill explain in diff. post 
CNT=0               

for NIM in ${LIST}                         #For function  as controlling loop
do
   
    len=$(echo ${LIST} | wc -w)             #"wc"command is used print new line
    echo -en "\b\b\b$(($NIM*100/$len))%"
    sleep $INT
   

done



That's it for now. click here to download the script.

Devamı »

How to convert video file type with robot voice feedback using bash script on Linux


 
  When I record my screen video, I used  desktop recorder software call "RecordMyDesktop" .You can get it by downloading from Ubuntu repositories. The recorder will record in .OGV file type. Video editor like Openshot (version 1.4.3), Kdenlive (version 4.8.5) ,Pitivi and others have problem in editing this  kind of file type.Sometime while using  the video editor to edit  .OGV file, you will get skipping frame,frame not moving or grey screen .

 To resolve this issue, I used "avconv" to convert my video to other file type . "avconv" is  fast and reliable tools  that can be use to grab audio/video source ,convert file and do many other cool stuff. There are certain settings that  I used to make sure the converted video is in good quality when using "avconv" . I will share some tricks on using "avconv" in other post.

   In this post, I will share how you can create a bash script to convert your video file,what the script does is, it will convert the file and will ask  user what name will it give to the new file with robot feedback voice . The script will only convert a single file at a time.To make it run on your machine, you need to save the script inside the folder which is included in your working PATH .Please refer here for more information.

Script drill down
---------------------

1.My Normal script header


#!/bin/bash
#Title : Video converter with robot feedback voice
#Author : N3rv3wr3ck
#Date : 17/1/2014
#Rev : 1.0


2. "Avconv" setting for my video conversion.I convert the file to MP4

avconv -i $1 -s hd1080 -c:v libx264 -crf 23 -c:a aac -strict -2 $1.mp4  # file type that you want to convert to


3. "espeak"is function that I use to convert text to speech.Make sure you put the word in ("") .On terminal it will echo "Please rename your file" .Once you type the file name,it will be store in variable "new"

espeak "Please rename your file"                                       # robot voice for file renaming
echo "Please rename your file " # show on screen
read new # store in variable "new"


4.This part of the script will rename the existing file in the directory. Since i'm using this script for .ogv file converted to  .Mp4 ,the converted file by default will have  naming convention something like "filename.ogv.mp4" . for loop control will look for file with ".ogv.mp4"and will rename the file using the name stored in variable "new" . The new file name will change it's naming convention to  "filename.mp4"

for file in *ogv.mp4;do                                         # The converter file will have ".ogv.mp4" 
file name mv "$file" "$new.mp4"                        # Rename the file using above variable 
done

Test it!!!

Please download the  full script here .



Devamı »

How to write VNC server (Raspberry Pi) startup and VNC client script



   In this post, I'm going to share  how to write a  VNC server start up script and client script. Before you continue with this tutorial, please make sure that your VNC server and client is working.You can check how do I do it in my previous post here.

   What will be accomplish by running this script on your VNC server (Raspberry Pi) is your Pi will automatically run at boot time.You can straight away  log in to your Pi from your system (client) once it is booted  up.Client side script is optional.I do it because I'm too lazy to remember the setting and need more space in my brain :-).

   I  used "case " statement for control structure on both server and client side. I use text editor on the client side and nano editor on server side to edit the script. You can download the full script at the end of this tutorial. Below are the steps I took to do this script .

1.Client

    I save this script in a folder that I normally put my script in .Visit my previous post on how do I do it . I name this script as "pi" .


Pi script piece by piece
------------------------
1.1) The script start off like normal script header

#!/bin/bash
#Title : Client VNC viewer login
#Author :Nerverwreck
#Website :http://www.geckogeeky.blogspot.com
#Date :December 2013
#Rev :0.1


1.2)It continue to the main content of the script .This script will only have 3 case to be select from . Once the user choose to select the case, it will automatically execute the following bash command.To execute this script,you need to type on terminal " pi [-selection ] ".The "$1" sign will take the input directly from the teminal.

If the user enter command that is not in the case, the "*" sign will execute its command by stating how to use the script.

case "$1" in
    -ping)
    echo "Ping to Pi VNC Server"
    ping 10.42.0.68                             # 10.42.0.68 is my Pi IP replace with your server IP
    ;;

    -ssh)   
    echo "SSH to Pi VNC Server"
    ssh 10.42.0.68 -l pi
    ;;

    -vnc)
    echo "Remote login to Pi "
    vncviewer 10.42.0.68:1 -geometry 1280x800  # use geometry to define your display
    ;;

    *)
    echo "`basename $0`:usage:[-ping][-ssh][-vnc]"
    exit 1
    ;;
esac
exit 0




2.Server

   On server part, you need to store the script in "/etc/init.d"  .This folder consist of file that will be execute during the boot time . I name this script as "autovnc"

pi@raspberrypi ~ $ cd /etc/init.d



Autovnc script piece by piece
---------------------------------
2.1) start off as a normal script header


#!/bin/bash
#/etc/init.d/autovnc
#Author :N3rv3wreck
#Website :htttp://geckogeeky.blogspot.com
#Date :December 2013
#Rev 0.1

2.2) For Debian base Linux distro, we must include in this header as a part of boot up script. If you miss this part on the script, It will pop up 'LSB missing 'warning when you want to configure it to run at boot up. For more information, you can visit here .


### BEGIN INIT INFO
# Provides:          Auto VNC server startup at boot
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start VNC server daemon at boot time
# Description:       Enable service provided by daemon.
### END INIT INFO

2.3)Changing the folder . to where you install the VNC server program . in my script i wrote as

VNCUSER='pi'
eval cd ~$VNCUSER

eval command will takes a string as its argument, and evaluates it as if you'd typed that string on a command line.

    You can use other method in doing the same job as above. The idea of both line above is finding the location of  ".vnc" file. I installed the program in my home folder .In this case, I set my Pi username  as "pi" .You will have the same location as me if you follow my tutorial . You can use below command as a substitution of above two line.

cd /home/pi

2.4) Main content of the script. Basically the script idea is similar to what we have on client side. To execute the file  we need to run as "./autovnc [selection] " . In autovnc, there is "start" and "stop"  selection. By running "start" command, it will start the server and enabling it at display :1 with the screen size 1280x600 .

   The server will be kill if we choose  the  "stop"  case.

case "$1" in
        start)
        echo "Waddap..Im starting the VNC Servo!"
         su $VNCUSER -c  '/usr/bin/vncserver :1 -geometry 1280x800'
        ;;

        stop)
        echo "Hey..Im gonna stop the VNC Servo Yo!"
         /usr/bin/vncserver -kill :1
        ;;

        *)
        echo "`basename $0`:usage:[start][stop]"
        exit 1
        ;;
esac
exit 0

If you use " cd/home/pi" in changing the folder, you can substitute
su $VNCUSER -c  '/usr/bin/vncserver :1 -geometry 1280x800'
with
su pi  -c '/usr/bin/vncserver :1 -geometry 1280x800'   


3.Testing the script
 After finish configuring, you can try and run the command  by using"./autovnc  start" or "./autovnc stop" command.

Testing VNC server script 


4.Update the script to be include during the boot time .
 pi@raspberrypi /etc/init.d $ sudo update-rc.d autovnc defaults
 
success configuring init file


reboot the server.

pi@raspberrypi /etc/init.d $ sudo reboot

5. You can now then try to log in to your  pi from you client.

shark_attack@Positive-Space:~$ pi -vnc

VNC to your server

 What do you think about this tutorial?To download the full script,please click here  . Please subscribe this page and leave comment in the box below

  Visit my other post on How to use voice to login your remote server and do other basic system control stuff. Click here .

.

Devamı »