Search

Just Another Tech Blog

A mind is like a parachute. It doesn't work if it is not open.

How to Bypass Adblock Detection on Websites that Bombard You With Ads


Easy One-click Solution to Bypass Ad Block Detection

The easiest way you can bypass ad block detection on a website is by disabling JavaScript using the Site Info option on the browser. Just click on the Site Info icon as shown in the screen shot and disable the JavaScript option.

java-script

Bypass Adblock Using Tamper Monkey Script

If there are more than one website you wish to bypass, than installing anti-adblock killer makes more sense. The UserScript helps you keep your ad-blocker active when you visit a website even when it asks you to disable it. As this is a script, you will have to install Greasemonkey on Firefox or Tampermonkey for Opera or Chrome. Once these add-ons are installed, you will have to download this JS file and add it to the Tampermonkey extension.

Selection_015

Now you do not need to disable the adblocker on any site, instead the JS script will prevent that site’s anti-adblocker script and let you browse the site smoothly.

Happy browsing!!

Source: http://www.guidingtech.com/60376/bypass-ad-block-detection-sites/

How To Add Robot Framework Syntax in Sublime Text and VIM editor


By default, files for the Robot Framework do not show any syntax on Sublime Text or VIM, with some tweaks we can add Robot Framework syntax.

For Sublime Text 2:

Open Sublime Text 2 and click Preferences -> Browse Packages to open the packages directory. Then create a directory named Robot Framework containing the contents of the following repository:

https://github.com/seeamkhan/sublime-robot-plugin

Note: The contents of the repository should be directly under the Robot Framework directory.

Now close the Sublime Text 2 editor if it’s already been opened and then open a file with Robot Framework syntax, the syntax should be now visible like below:

Selection_012

For VIM Text Editor:

Clone the git repository in any place:

git clone https://github.com/seeamkhan/robotframework-vim

Go to the content directory:

cd robotframework-vim

Make sure the directory ~/.vim/ already exist for the current user, if not then create the directory:

mkdir ~/.vim

Now copy all the contents to ~/.vim/ location:

cp -R * ~/.vim/

Now open any files with Robot Framework syntax in the VIM editor, the syntax should be visible like below:

Selection_014

Prepare CentOS 6.x or 7.x Server for Selenium


We need to install the following things in the server to run the Python test scripts after WordPress auto update:

  1. Need to be installed Python 2.6.x or 2.7.x
  2. Install WP CLI, see detail: http://wp-cli.org/
  3. Install pip:For RHEL 6.x and CentOS 6.x (x86_64)
    rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

    For RHEL 6.x and CentOS 6.x (i386)

    rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm

    Now install pip with yum command:

    yum install -y python-pip

    If you can not install pip be following the above steps then try the below steps:

    curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
    python get-pip.py
    
  4. Install Selenium:
    pip install selenium
    
  5. Install python-detenv:
    pip install python-dotenv
    
  6. Install python requests library:

    pip install requests
  7. Download Phantomjsfrom:http://phantomjs.org/download.html
  8. Copy Phantomjs to /usr/local/share/:
    cp -f phantomjs /usr/local/share/phantomjs

    Note: Keep the phantomjs nonexecutable while the wp-auto-update will run the script will make it executable and make it nonexecutable once it’s done.

  9. Make symlinks of Phantomjs:
    ln -s /usr/local/share/phantomjs /usr/local/bin/phantomjs
    ln -s /usr/local/share/phantomjs /usr/bin/phantomjs
    
  10. Install additional dependency for Phantomjs:
    yum install freetype
    yum install fontconfig

How to setup network after RHEL/CentOS 7 minimal installation


After installing RHEL/CentOS 7 minimal, You may not able to connect network in that machine. This will happen because Ethernet interfaces are not enabled by default.
This guide explain you to setup network on RHEL/CentOS 7.

Setup network on CentOS 7 minimal

First, type “nmcli d” command in your terminal for quick list ethernet card installed on your machine:

"nmcli d" command output

Type “nmtui” command in your terminal to open Network manager. After opening Network manager chose “Edit connection” and press Enter (Use TAB button for choosing options).

CentOS_7 Network manager screen

Now choose you network interfaces and click “Edit

Edit your network interfaces

DHCP configuration

Choose “Automatic” in IPv4 CONFIGURATION and check Automatically connect check box and press OK and quit from Network manager.

Set ip adress using DHCP

Reset network services:

service network restart

Now your server will get IP Address from DHCP .

CentOS 7 check ip address

 Source: https://lintut.com/how-to-setup-network-after-rhelcentos-7-minimal-installation/

XPath in Selenium WebDriver: Complete Tutorial


In Selenium automation, if the elements are not found by the general locators like id, class, name, etc. then XPath is used to find an element on the web page .

In this tutorial, we will learn about the xpath and different XPath expression to find the complex or dynamic elements, whose attributes changes dynamically on refresh or any operations.

What is XPath

XPath is defined as XML path. It is a syntax or language for finding any element on the web page using XML path expression. XPath is used to find the location of any element on a webpage using HTML DOM structure. The basic format of XPath is explained below with screen shot.

XPath in Selenium WebDriver: Complete Tutorial

Syntax for XPath:

XPath contains the path of the element situated at the web page. Standard syntax for creating XPath is.

Xpath=//tagname[@attribute='value']
  • // : Select current node.
  • Tagname: Tagname of the particular node.
  • @: Select attribute.
  • Attribute: Attribute name of the node.
  • Value: Value of the attribute.

To find the element on web pages accurately there are different types of locators:

XPath Locators Find different elements on web page
ID To find the element by ID of the element
Classname To find the element by Classname of the element
Name To find the element by name of the element
Link text To find the element by text of the link
XPath XPath required for finding the dynamic element and traverse between various elements of the web page
CSS path CSS path also locates elements having no name, class or ID.

Types of X-path

There are two types of XPath:

1) Absolute XPath .

2) Relative XPath .

Absolute XPath :

It is the direct way to find the element, but the disadvantage of the absolute XPath is that if there are any changes made in the path of the element then that XPath gets failed.

The key characteristic of XPath is that it begins with the single forward slash(/) ,which means you can select the element from the root node.

Below is the example of an absolute xpath expression of the element shown in the below screen.

Absolute xpath:

html/body/div[1]/section/div[1]/div/div/div/div[1]/div/div/div/div/div[3]/div[1]/div/h4[1]/b

XPath in Selenium WebDriver: Complete Tutorial

Relative xpath:

For Relative Xpath the path starts from the middle of the HTML DOM structure. It starts with the double forward slash (//), which means it can search the element anywhere at the webpage.

You can starts from the middle of the HTML DOM structure and no need to write long xpath.

Below is the example of a relative XPath expression of the same element shown in the below screen. This is the common format used to find element through a relative XPath.

Relative xpath: //*[@class='featured-box']//*[text()='Testing']

XPath in Selenium WebDriver: Complete Tutorial

What are XPath axes.

XPath axes search different nodes in XML document from current context node. XPath Axes are the methods used to find dynamic elements, which otherwise not possible by normal XPath method having no ID , Classname, Name, etc.

Axes methods are used to find those elements, which dynamically change on refresh or any other operations. There are few axes methods commonly used in Selenium Webdriver like child, parent, ancestor, sibling, preceding, self, etc.

Using XPath Handling complex & Dynamic elements in Selenium

1) Basic XPath:

XPath expression select nodes or list of nodes on the basis of attributes like ID , Name, Classname, etc. from the XML document as illustrated below.

Xpath=//input[@name='uid']

Here is a link to access the page http://demo.guru99.com/v1/

XPath in Selenium WebDriver: Complete Tutorial

Some more basic xpath expressions:

Xpath=//input[@type='text']				
Xpath=	//label[@id='message23']
Xpath=	//input[@value='RESET']
Xpath=//*[@class='barone']
Xpath=//a[@href='http://demo.guru99.com/']
Xpath= //img[@src='//cdn.guru99.com/images/home/java.png']

2) Contains() : Contains() is a method used in XPath expression. It is used when the value of any attribute changes dynamically, for example, login information.

The contain feature has an ability to find the element with partial text as shown in below example.

In this example, we tried to identify the element by just using partial text value of the attribute. In the below XPath expression partial value ‘sub’ is used in place of submit button. It can be observed that the element is found successfully.

Complete value of ‘Type’ is ‘submit’ but using only partial value ‘sub’.

Xpath=//*[contains(@type,'sub')]

Complete value of ‘name’ is ‘btnLogin’ but using only partial value ‘btn’.

Xpath=.//*[contains(@name,'btn')]

In the above expression, we have taken the ‘name’ as an attribute and ‘btn’ as an partial value as shown in the below screenshot. This will find 2 elements (LOGIN & RESET) as their ‘name’ attribute begins with ‘btn’.

XPath in Selenium WebDriver: Complete Tutorial

Similarly, in the below expression, we have taken the ‘id’ as an attribute and ‘message’ as a partial value. This will find 2 elements (‘User-ID must not be blank’ & ‘Password must not be blank’) as its ‘name’ attribute begins with ‘message’.

Xpath=//*[contains(@id,'message')]

XPath in Selenium WebDriver: Complete Tutorial

In the below expression, we have taken the “text” of the link as an attribute and ‘here’ as a partial value as shown in the below screenshot. This will find the link (‘here’) as it displays the text ‘here’.

Xpath=//*[contains(text(),'here')]
Xpath=//*[contains(@href,'guru99.com')]

XPath in Selenium WebDriver: Complete Tutorial

3) Using OR & AND:

In OR expression, two conditions are used, whether 1st condition OR 2nd condition should be true. It is also applicable if any one condition is true or maybe both. Means any one condition should be true to find the element.

In the below XPath expression, it identifies the elements whose single or both conditions are true.

Xpath=//*[@type='submit' OR @name='btnReset']

Highlighting both elements as “LOGIN ” element having attribute ‘type’ and “RESET” element having attribute ‘name’.

XPath in Selenium WebDriver: Complete Tutorial

In AND expression, two conditions are used, both conditions should be true to find the element. It fails to find element if any one condition is false.

Xpath=//input[@type='submit' AND @name='btnLogin']

In below expression, highlighting ‘LOGIN’ element as it having both attribute ‘type’ and ‘name’.

XPath in Selenium WebDriver: Complete Tutorial

4) Start-with function: Start-with function finds the element whose attribute value changes on refresh or any operation on the webpage. In this expression, match the starting text of the attribute is used to find the element whose attribute changes dynamically. You can also find the element whose attribute value is static (not changes).

For example -: Suppose the ID of particular element changes dynamically like:

Id=” message12″

Id=” message345″

Id=” message8769″

and so on.. but the initial text is same. In this case, we use Start-with expression.

In the below expression, there are two elements with an id starting “message”(i.e., ‘User-ID must not be blank’ & ‘Password must not be blank’). In below example, XPath finds those element whose ‘ID’ starting with ‘message’.

Xpath=//label[starts-with(@id,'message')]

XPath in Selenium WebDriver: Complete Tutorial

5) Text(): In this expression, with text function, we find the element with exact text match as shown below. In our case, we find the element with text “UserID”.

Xpath=//td[text()='UserID']

XPath in Selenium WebDriver: Complete Tutorial

6) XPath axes methods: These XPath axes methods are used to find the complex or dynamic elements. Below we will see some of these methods.

For illustrating these XPath axes method, we will use the Guru99 bank demo site.

a) Following: Selects all elements in the document of the current node( ) [ UserID input box is the current node] as shown in the below screen.

Xpath=//*[@type='text']//following::input

XPath in Selenium WebDriver: Complete Tutorial

There are 3 “input” nodes matching by using “following” axis- password, login and reset button. If you want to focus on any particular element then you can use the below XPath method:

Xpath=//*[@type='text']//following::input[1]

You can change the XPath according to the requirement by putting [1],[2]…………and so on.

With the input as ‘1’, the below screen shot finds the particular node that is ‘Password’ input box element.

XPath in Selenium WebDriver: Complete Tutorial

b) Ancestor: The ancestor axis selects all ancestors element (grandparent, parent, etc.) of the current node as shown in the below screen.

In the below expression, we are finding ancestors element of the current node(“ENTERPRISE TESTING” node).

Xpath=//*[text()='Enterprise Testing']//ancestor::div

XPath in Selenium WebDriver: Complete Tutorial

There are 13 “div” nodes matching by using “ancestor” axis. If you want to focus on any particular element then you can use the below XPath, where you change the number 1, 2 as per your requirement:

Xpath=//*[text()='Enterprise Testing']//ancestor::div[1]

You can change the XPath according to the requirement by putting [1], [2]…………and so on.

c) Child : Selects all children elements of the current node (Java) as shown in the below screen.

Xpath=//*[@id='java_technologies']/child::li

XPath in Selenium WebDriver: Complete Tutorial

There are 71 “li” nodes matching by using “child” axis. If you want to focus on any particular element then you can use the below xpath:

Xpath=//*[@id='java_technologies']/child::li[1]

You can change the xpath according to the requirement by putting [1],[2]…………and so on.

d) Preceding: Select all nodes that come before the current node as shown in the below screen.

In the below expression, it identifies all the input elements before “LOGIN” button that is Userid and password input element.

Xpath=//*[@type='submit']//preceding::input

XPath in Selenium WebDriver: Complete Tutorial

There are 2 “input” nodes matching by using “preceding” axis. If you want to focus on any particular element then you can use the below XPath:

Xpath=//*[@type='submit']//preceding::input[1]

You can change the xpath according to the requirement by putting [1],[2]…………and so on.

e) Following-sibling: Select the following siblings of the context node. Siblings are at the same level of the current node as shown in the below screen. It will find the element after the current node.

 xpath=//*[@type='submit']//following-sibling::input

XPath in Selenium WebDriver: Complete Tutorial

One input nodes matching by using “following-sibling” axis.

f) Parent: Selects the parent of the current node as shown in the below screen.

Xpath=//*[@id='rt-feature']//parent::div

XPath in Selenium WebDriver: Complete Tutorial

There are 65 “div” nodes matching by using “parent” axis. If you want to focus on any particular element then you can use the below XPath:

Xpath=//*[@id='rt-feature']//parent::div[1]

You can change the XPath according to the requirement by putting [1],[2]…………and so on.

g) Self: Selects the current node or ‘self’ means it indicates the node itself as shown in the below screen.

XPath in Selenium WebDriver: Complete Tutorial

One node matching by using “self ” axis. It always finds only one node as it represents self-element.

Xpath =//*[@type='password']//self::input

h) Descendant: Selects the descendants of the current node as shown in the below screen.

In the below expression, it identifies all the element descendants to current element ( ‘Main body surround’ frame element) which means down under the node (child node , grandchild node, etc.).

Xpath=//*[@id='rt-feature']//descendant::a

XPath in Selenium WebDriver: Complete Tutorial

There are 12 “link” nodes matching by using “descendant” axis. If you want to focus on any particular element then you can use the below XPath:

Xpath=//*[@id='rt-feature']//descendant::a[1]

You can change the XPath according to the requirement by putting [1],[2]…………and so on.

Summary:

XPath is required to find an element on the web page as to do an operation on that particular element.

  • There are two types of XPath:
    • Absolute XPath
    • Relative XPath
  • XPath Axes are the methods used to find dynamic elements, which otherwise not possible to find by normal XPath method
  • XPath expression select nodes or list of nodes on the basis of attributes like ID , Name, Classname, etc. from the XML document .
Source: http://www.guru99.com/xpath-selenium.html

Installing CMU-Sphinx on Ubuntu


Some Background

I recently installed Ubuntu 14.04 on my Lenovo Yoga, and it’s time to reinstall SPHINX.

When I installed SPHINX for the first time in September 2015, it was not a fun experience. I originally followed the instructions on CMU’s website, but I couldn’t seem to get it right. I tried a number of different approaches, using different blogs as guides, but I got nowhere. I first tried downloading Pocketsphinx, Sphinxtrain, Sphinxbase and Sphinx4 from CMU’s downloads page, but that didn’t work. I also tried installing the version hosted on SourceForge, but no luck there either. I finally decided to try cloning and installing the version on GitHub, and that seemed to do the trick. However, at the end of this post I show how to install CMUCLMTK from SourceForge, because they don’t have it on GitHub.

So, I’m going to go through installation process again here.

First, in case it’s relevant for others I’m going to show a little info about my current setup.

josh@yoga:~$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 14.04.3 LTS
Release:	14.04
Codename:	trusty

You can see the exact kernel on my version of Ubuntu below:

josh@yoga:~$ uname -a
Linux yoga 3.19.0-43-generic #49~14.04.1-Ubuntu SMP Thu Dec 31 15:44:49 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

Installing Dependencies

To install on Ubuntu (or any other unix-like system), we first need to install a few dependencies. Here’s the list:

Name Homepage Description
gcc GNU Compiler Collection GCC development is a part of the GNU Project, aiming to improve the compiler used in the GNU system including the GNU/Linux variant.
automake Automake Tool for generating GNU Standards-compliant Makefiles.
autoconf Autoconf Autoconf is an extensible package of M4 macros that produce shell scripts to automatically configure software source code packages.
libtool GNU Libtool GNU libtool is a generic library support script. Libtool hides the complexity of using shared libraries behind a consistent, portable interface.
bison GNU Bison Bison is a general-purpose parser generator that converts an annotated context-free grammar into a deterministic LR or generalized LR (GLR) parser employing LALR(1) parser tables.
swig SWIG SWIG is a software development tool that connects programs written in C and C++ with a variety of high-level programming languages.
python-dev Python Development Package Header files, a static library and development tools for building Python modules, extending the Python interpreter or embedding Python in applications.
libpulse-dev PulseAudio Development Package Headers and libraries for developing applications that access a PulseAudio sound server via PulseAudio’s native interface.

Here’s the command to get everything at once:

sudo apt-get install gcc automake autoconf libtool bison swig python-dev libpulse-dev

Installing CMU-SPHINX

Installing sphinxbase

Whether you’re using pocketsphinx or sphinx4, you’re going to need to install sphinxbase first.

The README for the sphinxbase repository says:

This package contains the basic libraries shared by the CMU Sphinx trainer and all the Sphinx decoders (Sphinx-II, Sphinx-III, and PocketSphinx), as well as some common utilities for manipulating acoustic feature and audio files.

To get sphinxbase running, we need to clone the repository from GitHub and then run a few commands to configure and install it in the right spot.

I usually make a folder on my desktop to store the source code, and then when it’s all been installed you can just throw away all those extra files.

So, first we need to get to the Desktop, make a new directory and cd into it.

josh@yoga:~$ cd Desktop/
josh@yoga:~/Desktop$ mkdir sphinx-source
josh@yoga:~/Desktop$ cd sphinx-source/
josh@yoga:~/Desktop/sphinx-source$ 

Now we can clone the source from GitHub, and you should get something like this:

josh@yoga:~/Desktop/sphinx-source$ git clone https://github.com/cmusphinx/sphinxbase.git
Cloning into 'sphinxbase'...
remote: Counting objects: 10302, done.
remote: Total 10302 (delta 0), reused 0 (delta 0), pack-reused 10302
Receiving objects: 100% (10302/10302), 8.95 MiB | 1.46 MiB/s, done.
Resolving deltas: 100% (8092/8092), done.
Checking connectivity... done.

Now can see that our once empty dir sphinx-source now has a new directory, sphinxbase:

josh@yoga:~/Desktop/sphinx-source$ la
sphinxbase

Let’s look at what’s inside this new dir, sphinxbase:

josh@yoga:~/Desktop/sphinx-source$ la sphinxbase/
AUTHORS       doc      indent.sh  Makefile.am  README.md         src   win32
autogen.sh    .git     LICENSE    NEWS         sphinxbase.pc.in  swig
configure.ac  include  m4         README       sphinxbase.sln    test

Now we need to run the autogen.sh shell script you can see in the sphinxbase directory. This will generate our Makefiles and other important scripts for compiling and installing. We’re going to get a long output here, so I only show some of it here:

josh@yoga:~/Desktop/sphinx-source$ cd sphinxbase/
josh@yoga:~/Desktop/sphinx-source/sphinxbase$ ./autogen.sh
**Warning**: I am going to run `configure' with no arguments.
If you wish to pass any to it, please specify them on the
`./autogen.sh' command line.

processing .
Running libtoolize...
libtoolize: putting auxiliary files in `.'.
libtoolize: copying file `./ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIR, `m4'.
libtoolize: copying file `m4/libtool.m4'
libtoolize: copying file `m4/ltoptions.m4'
libtoolize: copying file `m4/ltsugar.m4'
libtoolize: copying file `m4/ltversion.m4'
libtoolize: copying file `m4/lt~obsolete.m4'
Running aclocal  ...
Running autoheader...
Running automake --foreign --copy  ...
configure.ac:12: installing './compile'
                        .
                        .
                        .
config.status: creating test/regression/testfuncs.sh
config.status: creating test/regression/Makefile
config.status: creating swig/Makefile
config.status: creating swig/python/Makefile
config.status: creating include/config.h
config.status: creating include/sphinx_config.h
config.status: executing depfiles commands
config.status: executing libtool commands
Now type `make' to compile the package.

Before we charge right ahead to compilation with the make command, lets take a look at what new files were generated from running autogen.sh.

josh@yoga:~/Desktop/sphinx-source/sphinxbase$ la
aclocal.m4      config.log     doc         LICENSE      missing        sphinxbase.pc.in  win32
AUTHORS         config.status  .git        ltmain.sh    NEWS           sphinxbase.sln    ylwrap
autogen.sh      config.sub     include     m4           py-compile     src
autom4te.cache  configure      indent.sh   Makefile     README         swig
compile         configure.ac   install-sh  Makefile.am  README.md      test
config.guess    depcomp        libtool     Makefile.in  sphinxbase.pc  test-driver

You can see that we now have the scripts needed for compiling, configuring, and installing sphinxbase. Now we can run make to do our installation. As nicely summarized on Wikipedia, Make is a utility that automatically builds executable programs and libraries from source code by reading files called Makefiles which specify how to derive the target program.”

When you run the make command without any arguments (still in the local version of the cloned sphinxbase repository), you will get a long output that ends something like this:

josh@yoga:~/Desktop/sphinx-source/sphinxbase$ make
                        .
                        .
                        .
libtool: link: (cd ".libs" && rm -f "_sphinxbase.so.0" && ln -s "_sphinxbase.so.0.0.0" "_sphinxbase.so.0")
libtool: link: (cd ".libs" && rm -f "_sphinxbase.so" && ln -s "_sphinxbase.so.0.0.0" "_sphinxbase.so")
libtool: link: ar cru .libs/_sphinxbase.a  _sphinxbase_la-sphinxbase_wrap.o
libtool: link: ranlib .libs/_sphinxbase.a
libtool: link: ( cd ".libs" && rm -f "_sphinxbase.la" && ln -s "../_sphinxbase.la" "_sphinxbase.la" )
make[2]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxbase/swig/python'
make[2]: Entering directory `/home/josh/Desktop/sphinx-source/sphinxbase/swig'
make[2]: Nothing to be done for `all-am'.
make[2]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxbase/swig'
make[1]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxbase/swig'
make[1]: Entering directory `/home/josh/Desktop/sphinx-source/sphinxbase'
make[1]: Nothing to be done for `all-am'.
make[1]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxbase'

The next step is the last step. Run the command sudo make install. Root permission is important, because otherwise you will get some error without any Permision Denied warning.

You will see a good amount of output with some sections that look like this:

josh@yoga:~/Desktop/sphinx-source/sphinxbase$ sudo make install
                        .
                        .
                        .
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
                        .
                        .
                        .
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/lib/python2.7/dist-packages/sphinxbase

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
                        .
                        .
                        .
make[3]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxbase/swig'
make[2]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxbase/swig'
make[1]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxbase/swig'
make[1]: Entering directory `/home/josh/Desktop/sphinx-source/sphinxbase'
make[2]: Entering directory `/home/josh/Desktop/sphinx-source/sphinxbase'
make[2]: Nothing to be done for `install-exec-am'.
 /bin/mkdir -p '/usr/local/lib/pkgconfig'
 /usr/bin/install -c -m 644 sphinxbase.pc '/usr/local/lib/pkgconfig'
make[2]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxbase'
make[1]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxbase'

That’s it! You should have successfully installed sphinxbase. To check if you’ve actually installed it, just go to the terminal and do a tab-completion for sphinx_. You will see all the options of what you’ve just installed.

josh@yoga:~$ sphinx_
sphinx_cepview     sphinx_fe          sphinx_lm_convert  sphinx_pitch
sphinx_cont_seg    sphinx_jsgf2fsg    sphinx_lm_eval

At this point, if you try to run any one of these by entering it at the command line, you get an error:

josh@yoga:~$ sphinx_lm_convert
sphinx_lm_convert: error while loading shared libraries: libsphinxbase.so.3: cannot open shared object file: No such file or directory

This error has been answered by Nikolay Shmyrev on stackoverflow already, and the reason for this error is the following:

This error means that system fails to find the shared library in the location where it is installed. Most likely you installed it with default prefix /usr/local/lib which is not included into the library search path.

There’s a few ways to solve this problem. You may have come across this one which doesn’t work well:

josh@yoga:~$ export LD_LIBRARY_PATH=/usr/local/lib

The problem is, this solution will work for as long as you’re in the same session in your terminal. When you logout and log back in, you will have to reset the variable again.

Rather, we can edit the file /etc/ld.so.conf so we always look into the right directory when we need to. If you take a look at the Linux Programmer’s Manual you find the following description:

/etc/ld.so.conf: File containing a list of directories, one per line, in which to search for libraries.

So, this is the right place to make a change.

If you take a look into the config file right now, you will probably just see one line:

josh@yoga:~$ cat /etc/ld.so.conf
include /etc/ld.so.conf.d/*.conf

We want to add /usr/local/lib to the file. So, you can use nano to open it up, and add a new line that just says /usr/local/lib. That’s it. Don’t delete anything else or add anything else or you might get some headaches.

josh@yoga:~$ sudo nano /etc/ld.so.conf

If you’ve added that new line in via nano, you should see something like this:

screenshot

Now save the modified file (CTRL+o) and exit (CTRL+x).

Re-configure with the following command:

josh@yoga:~$ sudo ldconfig

Now you can check that your computer is finding the shared libraries with the following:

josh@yoga:~$ ldconfig -p | grep local
	libsvn_ra_local-1.so.1 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libsvn_ra_local-1.so.1
	libsphinxbase.so.3 (libc6,x86-64) => /usr/local/lib/libsphinxbase.so.3
	libsphinxbase.so (libc6,x86-64) => /usr/local/lib/libsphinxbase.so

Now you should be able to run the sphinxbase executables, and get a more reasonable error:

josh@yoga:~$ sphinx_lm_convert
ERROR: "cmd_ln.c", line 679: No arguments given, available options are:
Arguments list definition:
[NAME]		[DEFLT]	[DESCR]
-case			Ether 'lower' or 'upper' - case fold to lower/upper case (NOT UNICODE AWARE)
-debug			Verbosity level for debugging messages
-help		no	Shows the usage of the tool
-i			Input language model file (required)
-ifmt			Input language model format (will guess if not specified)
-lm_trie	no	Whether trie structure should be used for model holding during convertion
-logbase	1.0001	Base in which all log-likelihoods calculated
-mmap		no	Use memory-mapped I/O for reading binary LM files
-o			Output language model file (required)
-ofmt			Output language model file (will guess if not specified)

Installing pocketsphinx

Now that we’ve got sphinxbase installed successfully, we can move onto installing pocketsphinx. According to the description on the pocketsphinx GitHub repository:

PocketSphinx is a lightweight speech recognition engine, specifically tuned for handheld and mobile devices, though it works equally well on the desktop.

Still using sphinx-source as our current working directory, we can clone pocketsphinx from GitHub with the following command:

josh@yoga:~/Desktop/sphinx-source$ git clone https://github.com/cmusphinx/pocketsphinx.git
Cloning into 'pocketsphinx'...
remote: Counting objects: 11810, done.
remote: Total 11810 (delta 0), reused 0 (delta 0), pack-reused 11810
Receiving objects: 100% (11810/11810), 178.73 MiB | 11.30 MiB/s, done.
Resolving deltas: 100% (8831/8831), done.
Checking connectivity... done.

If we peek inside the current working directory, we will see we have a new directory:

josh@yoga:~/Desktop/sphinx-source$ la
pocketsphinx  sphinxbase

Now lets take a look at all the stuff we’ve just cloned:

josh@yoga:~/Desktop/sphinx-source$ la pocketsphinx
AUTHORS       doc      indent.sh  Makefile.am  pocketsphinx.pc.in  README.md   swig
autogen.sh    .git     LICENSE    model        pocketsphinx.sln    regression  test
configure.ac  include  m4         NEWS         README              src         win32

Looks pretty similar to what we found in our sphinxbase source directory, right?

It basically is, and we can run the same installation procedure as we did above. So now we cd into the dir itself and run autogen.sh. We get some output that looks like the following (again, I’ve truncated the output here).

josh@yoga:~/Desktop/sphinx-source$ cd pocketsphinx
josh@yoga:~/Desktop/sphinx-source/pocketsphinx$ ./autogen.sh 
**Warning**: I am going to run `configure' with no arguments.
If you wish to pass any to it, please specify them on the
`./autogen.sh' command line.

processing .
Running libtoolize...
libtoolize: putting auxiliary files in `.'.
libtoolize: copying file `./ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIR, `m4'.
libtoolize: copying file `m4/libtool.m4'
libtoolize: copying file `m4/ltoptions.m4'
libtoolize: copying file `m4/ltsugar.m4'
libtoolize: copying file `m4/ltversion.m4'
libtoolize: copying file `m4/lt~obsolete.m4'
Running aclocal  ...
Running automake --foreign --copy  ...
configure.ac:11: installing './compile'
configure.ac:10: installing './config.guess'
configure.ac:10: installing './config.sub'
configure.ac:5: installing './install-sh'
                    .
                    .
                    .
config.status: creating model/Makefile
config.status: creating test/Makefile
config.status: creating test/testfuncs.sh
config.status: creating test/unit/Makefile
config.status: creating test/regression/Makefile
config.status: executing depfiles commands
config.status: executing libtool commands
Now type `make' to compile the package.

Now we’ve made all our necessary Makefiles, and we can see them in the pocketsphinx directory.

josh@yoga:~/Desktop/sphinx-source/pocketsphinx$ la
aclocal.m4      configure     libtool      model               README.md
AUTHORS         configure.ac  LICENSE      NEWS                regression
autogen.sh      doc           m4           pocketsphinx.pc     src
autom4te.cache  .git          Makefile     pocketsphinx.pc.in  swig
config.log      include       Makefile.am  pocketsphinx.sln    test
config.status   indent.sh     Makefile.in  README              win32

Same as we did above for sphinxbase, we run make now.

josh@yoga:~/Desktop/sphinx-source/pocketsphinx$ make
                             .
                             .
                             .
libtool: link: (cd ".libs" && rm -f "_pocketsphinx.so.0" && ln -s "_pocketsphinx.so.0.0.0" "_pocketsphinx.so.0")
libtool: link: (cd ".libs" && rm -f "_pocketsphinx.so" && ln -s "_pocketsphinx.so.0.0.0" "_pocketsphinx.so")
libtool: link: ar cru .libs/_pocketsphinx.a  pocketsphinx_wrap.o
libtool: link: ranlib .libs/_pocketsphinx.a
libtool: link: ( cd ".libs" && rm -f "_pocketsphinx.la" && ln -s "../_pocketsphinx.la" "_pocketsphinx.la" )
make[3]: Leaving directory `/home/josh/Desktop/sphinx-source/pocketsphinx/swig/python'
make[2]: Leaving directory `/home/josh/Desktop/sphinx-source/pocketsphinx/swig/python'
make[2]: Entering directory `/home/josh/Desktop/sphinx-source/pocketsphinx/swig'
make[2]: Nothing to be done for `all-am'.
make[2]: Leaving directory `/home/josh/Desktop/sphinx-source/pocketsphinx/swig'
make[1]: Leaving directory `/home/josh/Desktop/sphinx-source/pocketsphinx/swig'
make[1]: Entering directory `/home/josh/Desktop/sphinx-source/pocketsphinx'
make[1]: Nothing to be done for `all-am'.
make[1]: Leaving directory `/home/josh/Desktop/sphinx-source/pocketsphinx'

And now we can actually do the installation with make install and root privledges.

josh@yoga:~/Desktop/sphinx-source/pocketsphinx$ sudo make install
Making install in src
make[1]: Entering directory `/home/josh/Desktop/sphinx-source/pocketsphinx/src'
Making install in libpocketsphinx
make[2]: Entering directory `/home/josh/Desktop/sphinx-source/pocketsphinx/src/libpocketsphinx'
make[3]: Entering directory `/home/josh/Desktop/sphinx-source/pocketsphinx/src/libpocketsphinx'
                             .
                             .
                             .
libtool: install: /usr/bin/install -c .libs/libpocketsphinx.lai /usr/local/lib/libpocketsphinx.la
libtool: install: /usr/bin/install -c .libs/libpocketsphinx.a /usr/local/lib/libpocketsphinx.a
libtool: install: chmod 644 /usr/local/lib/libpocketsphinx.a
libtool: install: ranlib /usr/local/lib/libpocketsphinx.a
libtool: finish: PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/sbin" ldconfig -n /usr/local/lib
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
                             .
                             .
                             .
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/lib/python2.7/dist-packages/pocketsphinx

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
                             .
                             .
                             .
make[3]: Leaving directory `/home/josh/Desktop/sphinx-source/pocketsphinx/swig'
make[2]: Leaving directory `/home/josh/Desktop/sphinx-source/pocketsphinx/swig'
make[1]: Leaving directory `/home/josh/Desktop/sphinx-source/pocketsphinx/swig'
make[1]: Entering directory `/home/josh/Desktop/sphinx-source/pocketsphinx'
make[2]: Entering directory `/home/josh/Desktop/sphinx-source/pocketsphinx'
make[2]: Nothing to be done for `install-exec-am'.
 /bin/mkdir -p '/usr/local/lib/pkgconfig'
 /usr/bin/install -c -m 644 pocketsphinx.pc '/usr/local/lib/pkgconfig'
make[2]: Leaving directory `/home/josh/Desktop/sphinx-source/pocketsphinx'
make[1]: Leaving directory `/home/josh/Desktop/sphinx-source/pocketsphinx'

Let’s see if we got something. If you type in pocketsphinx_ and do a tab completion to list all options, you should see something like this:

josh@yoga:~/Desktop/sphinx-source/pocketsphinx$ pocketsphinx_
pocketsphinx_batch         pocketsphinx_continuous    pocketsphinx_mdef_convert

Now if you try to run one of them, we get a sensible error that says we didn’t supply any of the needed arguments.

josh@yoga:~/Desktop/sphinx-source/pocketsphinx$ pocketsphinx_continuous 
ERROR: "cmd_ln.c", line 679: No arguments given, available options are:
Arguments list definition:
[NAME]			[DEFLT]		[DESCR]
-adcdev					Name of audio device to use for input.
-agc			none		Automatic gain control for c0 ('max', 'emax', 'noise', or 'none')
-agcthresh		2.0		Initial threshold for automatic gain control
-allphone				Perform phoneme decoding with phonetic lm
-allphone_ci		no		Perform phoneme decoding with phonetic lm and context-independent units only
-alpha			0.97		Preemphasis parameter
                              .
                              .
                              .
-varfloor		0.0001		Mixture gaussian variance floor (applied to data from -var file)
-varnorm		no		Variance normalize each utterance (only if CMN == current)
-verbose		no		Show input filenames
-warp_params				Parameters defining the warping function
-warp_type		inverse_linear	Warping function type (or shape)
-wbeam			7e-29		Beam width applied to word exits
-wip			0.65		Word insertion penalty
-wlen			0.025625	Hamming window length

INFO: continuous.c(295): Specify '-infile <file.wav>' to recognize from file or '-inmic yes' to recognize from microphone.

Huzzah! We now have a functional version of pocketsphinx installed with all it’s sphinxbase dependencies (if you followed the first section). If you already have a language model, an acoustic model, and a phonetic dictionary, you’re good to go!

However, if you’d like to train or adapt an acoustic model, you need to install sphinxtrain as shown below.

Installing sphinxtrain

Let’s clone sphinxtrain into the temporary directory we’ve been using to store our source code (sphinx-source):

josh@yoga:~/Desktop/sphinx-source$ git clone https://github.com/cmusphinx/sphinxtrain.git
Cloning into 'sphinxtrain'...
remote: Counting objects: 15997, done.
remote: Total 15997 (delta 0), reused 0 (delta 0), pack-reused 15997
Receiving objects: 100% (15997/15997), 13.15 MiB | 1.80 MiB/s, done.
Resolving deltas: 100% (11174/11174), done.
Checking connectivity... done.

If we look inside the temorary directory, we see sphinxtrain right where it should be, alongside our other directories of source code.

josh@yoga:~/Desktop/sphinx-source$ la
pocketsphinx  sphinxbase  sphinxtrain

Now, if we look inside this new sourcecode, we will see something pretty familiar.

josh@yoga:~/Desktop/sphinx-source$ la sphinxtrain
AUTHORS       etc      LICENSE      NEWS    scripts          templates
autogen.sh    .git     m4           python  SphinxTrain.sln  test
configure.ac  include  Makefile.am  README  src              win32

Let’s cd into sphinxtrain and run the script which generates the Makefiles.

josh@yoga:~/Desktop/sphinx-source$ cd sphinxtrain
josh@yoga:~/Desktop/sphinx-source/sphinxtrain$ ./autogen.sh 
**Warning**: I am going to run `configure' with no arguments.
If you wish to pass any to it, please specify them on the
`./autogen.sh' command line.

processing .
Running libtoolize...
libtoolize: putting auxiliary files in `.'.
libtoolize: copying file `./ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIR, `m4'.
libtoolize: copying file `m4/libtool.m4'
libtoolize: copying file `m4/ltoptions.m4'
libtoolize: copying file `m4/ltsugar.m4'
libtoolize: copying file `m4/ltversion.m4'
                      .
                      .
                      .
config.status: creating src/programs/param_cnt/Makefile
config.status: creating src/programs/printp/Makefile
config.status: creating src/programs/prunetree/Makefile
config.status: creating src/programs/tiestate/Makefile
config.status: creating test/Makefile
config.status: executing depfiles commands
config.status: executing libtool commands
Now type `make' to compile the package.

Let’s take a look at what we just did.

josh@yoga:~/Desktop/sphinx-source/sphinxtrain$ la
aclocal.m4      config.status  include     Makefile.am  SphinxTrain.sln
AUTHORS         config.sub     install-sh  Makefile.in  src
autogen.sh      configure      libtool     missing      templates
autom4te.cache  configure.ac   LICENSE     NEWS         test
compile         depcomp        ltmain.sh   python       win32
config.guess    etc            m4          README
config.log      .git           Makefile    scripts

As with all the other installations, we now compile with make.

josh@yoga:~/Desktop/sphinx-source/sphinxtrain$ make
                            .
                            .
                            .
make[3]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxtrain/src/programs/tiestate'
make[3]: Entering directory `/home/josh/Desktop/sphinx-source/sphinxtrain/src/programs'
make[3]: Nothing to be done for `all-am'.
make[3]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxtrain/src/programs'
make[2]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxtrain/src/programs'
make[2]: Entering directory `/home/josh/Desktop/sphinx-source/sphinxtrain/src'
make[2]: Nothing to be done for `all-am'.
make[2]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxtrain/src'
make[1]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxtrain/src'
Making all in test
make[1]: Entering directory `/home/josh/Desktop/sphinx-source/sphinxtrain/test'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxtrain/test'
make[1]: Entering directory `/home/josh/Desktop/sphinx-source/sphinxtrain'
make[1]: Nothing to be done for `all-am'.
make[1]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxtrain'

Moving right along, we can run make install to seal the deal.

josh@yoga:~/Desktop/sphinx-source/sphinxtrain$ sudo make install
                            .
                            .
                            .
make[2]: Entering directory `/home/josh/Desktop/sphinx-source/sphinxtrain/src'
make[3]: Entering directory `/home/josh/Desktop/sphinx-source/sphinxtrain/src'
make[3]: Nothing to be done for `install-exec-am'.
make[3]: Nothing to be done for `install-data-am'.
make[3]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxtrain/src'
make[2]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxtrain/src'
make[1]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxtrain/src'
Making install in test
make[1]: Entering directory `/home/josh/Desktop/sphinx-source/sphinxtrain/test'
make[2]: Entering directory `/home/josh/Desktop/sphinx-source/sphinxtrain/test'
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxtrain/test'
make[1]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxtrain/test'
make[1]: Entering directory `/home/josh/Desktop/sphinx-source/sphinxtrain'
make[2]: Entering directory `/home/josh/Desktop/sphinx-source/sphinxtrain'
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxtrain'
make[1]: Leaving directory `/home/josh/Desktop/sphinx-source/sphinxtrain'

Hopefully now you can try out sphinxtrain and get some sensible output:

josh@yoga:~/Desktop/sphinx-source/sphinxtrain$ sphinxtrain 

Sphinxtrain processes the audio files and creates and acoustic model 
for CMUSphinx toolkit. The data needs to have a certain layout 
See the tutorial http://cmusphinx.sourceforge.net/wiki/tutorialam 
for details

Usage: sphinxtrain [options] <command>

Commands:
     -t <task> setup - copy configuration into database
     [-s <stage1,stage2,stage3>] [-f <stage>] run - run the training or just selected stages

You should be ready to go now!

Hopefully this was helpful for you. If you ran into issues or have suggestions on how to make this better, be sure to leave a comment!

Installing cmuclmtk

I can’t seem to find the code on CMU-Sphinx’s GitHub account, so I’m just went through sourceforge instead.

NB A reader recommended to try this link from svn instead: svn://svn.code.sf.net/p/cmusphinx/code/trunk/cmuclmtk

josh@yoga:~/Desktop$ svn checkout svn://svn.code.sf.net/p/cmusphinx/code/trunk cmusphinx-code
                           .
                           .
                           .
A    cmusphinx-code/logios/Tools/MakeLM/bin/x86-nt/wfreq2vocab.exe
A    cmusphinx-code/logios/Tools/MakeLM/bin/x86-nt/idngram2stats.exe
A    cmusphinx-code/logios/Tools/MakeLM/bin/x86-nt/text2wngram.exe
A    cmusphinx-code/logios/Tools/MakeLM/bin/x86-nt/lm_combine.exe
A    cmusphinx-code/logios/Tools/MakeLM/bin/x86-nt/interpolate.exe
A    cmusphinx-code/logios/Tools/MakeLM/bin/x86-nt/binlm2arpa.exe
A    cmusphinx-code/logios/Tools/MakeLM/bin/x86-nt/phoenix2corpus.exe
A    cmusphinx-code/logios/Tools/MakeLM/bin/x86-nt/text2idngram.exe
A    cmusphinx-code/logios/Tools/MakeLM/bin/x86-nt/ngram2mgram.exe
A    cmusphinx-code/logios/Tools/MakeLM/bin/x86-nt/text2wfreq.exe
A    cmusphinx-code/logios/Tools/MakeLM/bin/x86-nt/idngram2lm.exe
Checked out external at revision 10678.

Checked out revision 13167.

As you can see below, we just downloaded pretty much everything they’ve got. Importantly, cmuclmtk is there, too.

josh@yoga:~/Desktop$ cd cmusphinx-code/
josh@yoga:~/Desktop/cmusphinx-code$ la
cmuclmtk  htk2s3conv  multisphinx   pocketsphinx-android       sphinx2  sphinx4     sphinxtrain
cmudict   logios      pocketsphinx  pocketsphinx-android-demo  sphinx3  sphinxbase  .svn

Let’s cd into cmuclmtk and take a look:

josh@yoga:~/Desktop/cmusphinx-code$ cd cmuclmtk/
josh@yoga:~/Desktop/cmusphinx-code/cmuclmtk$ la
AUTHORS     ChangeLog     configure.ac  doc      Makefile.am  perl    src   TODO
autogen.sh  cmuclmtk.sln  debian        LICENSE  NEWS         README  test  win32

Familiar set up, right? We do the same steps as before, starting with ./autogen.sh.

josh@yoga:~/Desktop/cmusphinx-code/cmuclmtk$ ./autogen.sh 
**Warning**: I am going to run `configure' with no arguments.
If you wish to pass any to it, please specify them on the
`./autogen.sh' command line.

processing .
Running libtoolize...
libtoolize: putting auxiliary files in `.'.
libtoolize: copying file `./ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIR, `m4'.
libtoolize: copying file `m4/libtool.m4'
libtoolize: copying file `m4/ltoptions.m4'
libtoolize: copying file `m4/ltsugar.m4'
libtoolize: copying file `m4/ltversion.m4'
              .
              .
              .
config.status: creating Makefile
config.status: creating src/Makefile
config.status: creating test/Makefile
config.status: creating src/liblmest/Makefile
config.status: creating src/libs/Makefile
config.status: creating src/programs/Makefile
config.status: creating config.h
config.status: executing depfiles commands
config.status: executing libtool commands
Now type `make' to compile the package.

Here’s all the things we’ve just generated:

josh@yoga:~/Desktop/cmusphinx-code/cmuclmtk$ la
aclocal.m4      cmuclmtk.sln  config.log     debian      LICENSE      Makefile.in  src
AUTHORS         compile       config.status  depcomp     ltmain.sh    missing      stamp-h1
autogen.sh      config.guess  config.sub     doc         m4           NEWS         test
autom4te.cache  config.h      configure      install-sh  Makefile     perl         TODO
ChangeLog       config.h.in   configure.ac   libtool     Makefile.am  README       win32

Now we run make.

josh@yoga:~/Desktop/cmusphinx-code/cmuclmtk$ make
                       .
                       .
                       .
libtool: link: gcc -I../../src/libs -I../../src/liblmest -I../../src/win32 -g -O2 -o .libs/lm_combine lm_combine.o  ../../src/.libs/libcmuclmtk.so -lm
make[3]: Leaving directory `/home/josh/Desktop/cmusphinx-code/cmuclmtk/src/programs'
make[2]: Leaving directory `/home/josh/Desktop/cmusphinx-code/cmuclmtk/src'
Making all in test
make[2]: Entering directory `/home/josh/Desktop/cmusphinx-code/cmuclmtk/test'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/home/josh/Desktop/cmusphinx-code/cmuclmtk/test'
make[2]: Entering directory `/home/josh/Desktop/cmusphinx-code/cmuclmtk'
make[2]: Nothing to be done for `all-am'.
make[2]: Leaving directory `/home/josh/Desktop/cmusphinx-code/cmuclmtk'
make[1]: Leaving directory `/home/josh/Desktop/cmusphinx-code/cmuclmtk'

And finally, sudo make install.

josh@yoga:~/Desktop/cmusphinx-code/cmuclmtk$ sudo make install
[sudo] password for josh: 
Making install in src
make[1]: Entering directory `/home/josh/Desktop/cmusphinx-code/cmuclmtk/src'
                              .
                              .
                              .
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
                              .
                              .
                              .
make[1]: Leaving directory `/home/josh/Desktop/cmusphinx-code/cmuclmtk/test'
make[1]: Entering directory `/home/josh/Desktop/cmusphinx-code/cmuclmtk'
make[2]: Entering directory `/home/josh/Desktop/cmusphinx-code/cmuclmtk'
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/home/josh/Desktop/cmusphinx-code/cmuclmtk'
make[1]: Leaving directory `/home/josh/Desktop/cmusphinx-code/cmuclmtk'

Now we can see a couple of the executables if we do a tab completion as such:

josh@yoga:~/Desktop/cmusphinx-code/cmuclmtk$ text2
text2idngram  text2wfreq    text2wngram   

And if we run one without input, it hangs up and runs for a while, but works.

josh@yoga:~/Desktop/cmusphinx-code/cmuclmtk$ text2wfreq 
text2wfreq : Reading text from standard input...

Source: http://jrmeyer.github.io/installation/2016/01/09/Installing-CMU-Sphinx-on-Ubuntu.html

Selenium Grid Step by Step Guide


Install java jar:

1. Add the PPA.

Open terminal (Ctrl+Alt+T) and run the command:

sudo add-apt-repository ppa:webupd8team/java

Type in your password when it asks and hit Enter.

2. Update and install the installer script:

Run commands to update system package index and install Java installer script:

sudo apt update; sudo apt install oracle-java8-installer

You may replace oracle-java8-installer with oracle-java9-installer to install Java 9.

While the install process, you have to accept Java license to continue downloading & installing Java binaries.

3. Check the Java version

To check the Java version after installing the package, run command:

javac -version

4. Set Java environment variables

The PPA also contains a package to automatically set Java environment variables, just run command:

sudo apt install oracle-java8-set-default

For Java 9, install the package oracle-java9-set-default instead.

Setup Selenium Standalone Server

 1. Download Selenium Selenium Standalone Server:

Go to http://www.seleniumhq.org/download/ and then download Selenium Standalone Server by clicking ‘Download version 3.0.1‘ (version number may vary).

You need to download this for both hub and node PCs

2. Now, start the Hub machine:

Open the terminal, CD to the location where the selenium standalone server file is being kept and type:

java -jar selenium-server-standalone-2.30.0.jar -role hub

It will start the hub.

Another way to verify whether the hub is running is by using a browser. Selenium Grid, by default, uses hub’s port 4444 for its web interface. Simply open up a browser and go to http://localhost:4444/grid/console

Also, you can find if the node can access the hub. For this, open a browser in the node machine and type http://192.168.136.130:4444/grid/console as URL. Here ‘192.168.136.130’ should replace with the node machine’s IP address.

3. Now, the hub is up and running. Let’s setup node:

In the node machine, open a terminal, CD to the location where the selenium standalone jar file is located and type the following command:

java -jar selenium-server-standalone-3.0.1.jar -role webdriver -hub http://192.168.136.130:4444/grid/register -port 5566

Here, 192.168.136.130 should be replaced with the hub machine’s IP address.

We also used port 5566 though you may choose any free port number you desire.

If everything went well, the node will up and show it’s status.

You can also verify if the node is connected with hub properly from the web browser.

Refresh the http://192.168.136.130:4444/grid/console URL and it will show the connected nodes.

4. Run the selenium script:

Now, we will run a selenium remote control script from the hub machine and it will execute to the node machines.

Here is a sample python script we are using:

Please Note: To run this script the node pc must have installed the following things:

  1. Python
  2. Python PIP
  3. Selenium
  4. Latest Chrome driver

Remote Control Script:

# -*- coding: utf-8 -*-
from selenium import selenium
import unittest, time, re

class sample-script(unittest.TestCase):
 def setUp(self):
 self.verificationErrors = []
 self.selenium = selenium("localhost", 4444, "*chrome", "http://jaxara.com/")
 self.selenium.start()
 
 def test_sample-script(self):
 sel = self.selenium
 sel.open("/")
 sel.type("id=edit-search-block-form--4", "test")
 sel.click("xpath=.//*[@value='Search']")
 for i in range(60):
 try:
 if sel.is_element_present("xpath=.//*[@id='block-system-main']/div/h2"): break
 except: pass
 time.sleep(1)
 else: self.fail("time out")
 try: self.failUnless(sel.is_element_present("xpath=.//*[@id='block-system-main']/div/h2"))
 except AssertionError as e: self.verificationErrors.append(str(e))
 
 def tearDown(self):
 self.selenium.stop()
 self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
 unittest.main()

To verify if the above listed items are already been installed, run this script from the terminal. If the following scripts run properly then everything is installed and ready.

Sample Script:

# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re

class SampleWebScriptPy(unittest.TestCase):
 def setUp(self):
 self.driver = webdriver.Chrome()
 self.driver.implicitly_wait(30)
 self.base_url = "http://jaxara.com/"
 self.verificationErrors = []
 self.accept_next_alert = True
 
 def test_sample_web_script_py(self):
 driver = self.driver
 driver.get(self.base_url + "/")
 driver.find_element_by_id("edit-search-block-form--4").clear()
 driver.find_element_by_id("edit-search-block-form--4").send_keys("test")
 driver.find_element_by_xpath(".//*[@value='Search']").click()
 for i in range(60):
 try:
 if self.is_element_present(By.XPATH, ".//*[@id='block-system-main']/div/h2"): break
 except: pass
 time.sleep(1)
 else: self.fail("time out")
 try: self.assertTrue(self.is_element_present(By.XPATH, ".//*[@id='block-system-main']/div/h2"))
 except AssertionError as e: self.verificationErrors.append(str(e))
 
 def is_element_present(self, how, what):
 try: self.driver.find_element(by=how, value=what)
 except NoSuchElementException as e: return False
 return True
 
 def is_alert_present(self):
 try: self.driver.switch_to_alert()
 except NoAlertPresentException as e: return False
 return True
 
 def close_alert_and_get_its_text(self):
 try:
 alert = self.driver.switch_to_alert()
 alert_text = alert.text
 if self.accept_next_alert:
 alert.accept()
 else:
 alert.dismiss()
 return alert_text
 finally: self.accept_next_alert = True
 
 def tearDown(self):
 self.driver.quit()
 self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
 unittest.main()

Good luck!

Device Testing Local Virtual Hosts


We often need to test many features in our site for several devices like, phones, tabs etc. In SDLC process, when we need to maintain the proper deployment process, many times we need to test a new feature or fix in out local environments. Most of us use a local setup (maybe XAMP, WAMP, LAMP etc) with virtual hosts for maintaining several projects. Therefore, it become difficult to test on mobile phones or tabs there is no easy option to set new host entry for those devices. However, we can solve this problem by adding single line of code in our virtual host settings.

Here, I am using WAMP. For WAMP:

First: You need to have a virtual host for the test site/project. (If you don’t have a virtual host then you should be able to access the local site by hitting the ip address of your PC on the browser of the device on which you need to test).

Second: Open the “httpd-vhosts.conf” in the “C:\wamp64\bin\apache\apache2.4.17\conf\extra” location. (location can vary depending on the apache and wamp version).

Third: Here, in the “httpd-vhosts.conf” file add “ServerAlias myproject.local.*.xip.io” line between the virtual host settings like bellow:

<VirtualHost *>
  ServerName "myproject.local"
  DocumentRoot "/Users/jeremy/Sites/myproject"
  ServerAlias myproject.local.*.xip.io
</VirtualHost>

Now, Save the file and restart all WAMP services.

Forth: Now, you should have the ability to browse the local site from any devices under the same network, but you need to use the following URL pattern to access:

http://myproject.local.[local ip address].xip.io/
ie.
http://bangladroid.local.192.168.0.101.xip.io/

Its Done!!

The ServerAlias directive allows for alternate names that Apache should map to the virtual host. The xip.io domain is a free wildcard DNS service from 37signals, which essentially resolves to your local ip address, and sends it back in the response. Now just fire up your various mobile devices and browse to the server alias above, substituting * with your local ip address.

What makes this so streamlined is that it allows for a consistent naming pattern that is easy to remember, and it removes unnecessary complication. As a bonus, it really comes in handy when a request comes in from a project manager to troubleshoot an issue on a recent project that you still have running on your local machine.

Source: https://www.viget.com/articles/device-testing-local-virtual-hosts

Python Robot Framework Install


To install Robot Framework, you need to pre-installed the following items:

  1. Python 2 or 3
  2. Selenium
  3. PIP
  4. PATH setting in Environment Variables

See How to Install Python, PIP, Selenium, Chrome Driver post if you already have not the above things.

Install Robot:

Open CMD as an administrator user.

Type:

pip install robotframework
pip install robotframework-selenium2library

After completion you can start working on the Robot framework.

You can simply create a .txt file and put the following codes to check the Robot framework is working or not:

*** Settings ***
Library     Selenium2Library
Suite Setup     Go to homepage
Suite Teardown  Close All Browsers

*** Variables ***
${HOMEPAGE}     http://mytestsite/wp-admin
${BROWSER}      chrome
${user}         abc@example.com
${pass}         password

*** Test Cases ***
Open Browser To Login Page
    Input Username    abc@example.com
    Input Password    password
    Submit Credentials

*** Keywords ***
Open Browser To Login Page
    Maximize Browser Window
    Open Browser    ${HOMEPAGE}    ${BROWSER}
    Login Page Should Be Open

Go to homepage
    Open Browser    ${HOMEPAGE}     ${BROWSER}

Input Username
    [Arguments]    ${username}
    Input Text    id=user_login    ${username}

Input Password
    [Arguments]    ${password}
    Input Text    id=user_pass    ${password}

Submit Credentials
    Click Button    xpath=//input[contains(@id, 'wp-submit')]

Save this code in a text file like, demo-robot.txt

Now from CMD or terminal type

pybot demo-robot.txt

It will run the script and generate the detail report, log file and other necessary output.

You can also save the file as robot file like, debo-robot.robot

It that case you need to add “C:\Python27\Lib\site-packages\robot” in your Environment Variable.

Now type the following code to run the robot script:

robot demo-robot.robot

Please Note: If you are using any IDE like Pycharm, some notification will appear after installing Robot framework, which will say that there are some plugins for Robot, do you want to install it or not. In that case you should install it in the IDE.

Create a free website or blog at WordPress.com.

Up ↑