Blog do projektu Open Source JavaHotel

niedziela, 30 marca 2014

octave, Mel-frequency cepstrum

I created Octave version of Mel-frequency spectrum implementation. I followed approach from this article. Source is available here. In order to run this code two additional packages should be installed : nan and signal.
General description
The implementation is controlled by several global variables.
  • NOMELS: the size of MEL filterbank
  • STARTHZ : lower frequency
  • LASTHZ : upper frequency (usually half of the sample frequency).
  • FFTSIZE : FFT resolution (usually 512 or 1024)
There are several functions defined.
  • readsound1 : read wav file (only one channel if more defined)
  • applyhunning : apply window Hunning function
  • countmel : convert Hertz value to Mel scale
  • revmel : inverse to countmel
  • calcpoints: calculate NOMELS mel scale points from STARTHZ to LASTHZ
  • calfreq : trasforms calcpoints to Hertz 
  • calcbins : transforms calfreq to FFT bins equvalence 
  • melbins : calcpoints -> calfreq ->calcbins
  • creatembank : create mel filterbank for single mel filter
  • createfilters : create the whole filter bank (a vector of single filter)
  • calculateenergy : create mel coefficient (energy sum) for FFT output
  • transformenergy : calculateenergy->log->dct
  • transformmel : create mel coefficients for input signal
I tried to use this package for recognizing numbers in voice command but failed. As a reference voice I downloaded samples from (for instance for one). As an input voice recording I tried automatically generated voices from text-to-speech demo and some natural voices.
The matching function is defined as matchsinglefile. It simply scans through input signal (using global variables SLICESIZE and OFFSET) and cuts off consecutive slices. Then compares mel coefficients for this slices against mel coefficient of reference sound using rms (Euclide distance) function. 
 But I failed to find a treshold allowing to tell number from non-number. Probably all stuff requires more elaboration.

środa, 12 marca 2014

InfoSphere Sreams and Oracle

InfoSphere Streams can connect to Oracle database also. InfoSphere Streams installation contains Database Toolkit which provides several operators which allow integration with external databases (including Oracle). The functionality is very limited (it is nothing more then insert/update and select) but it is enough for typical InfoSphere Stream application.
Oracle and unixODBC
First thing to do is to download, install and setup unixODBC connection with Oracle database.
Oracle client
Download and install Oracle client software.  At least two products should be installed: Basic and ODBC. Also SQL*Plus is recommended for testing and administering.
unixODBC connection
Set LD_LIBRARY_PATH environment variable pointing to Instant Client installation.
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/instantclient_12_1/
Make sure that library has all dependency resolved.
[sb@host ~]$ ldd /usr/local/instantclient_12_1/ =>  (0x00007ffff43ff000) => /lib64/ (0x00007ff65554a000) => /lib64/ (0x00007ff6552c5000) => /lib64/ (0x00007ff6550a8000) => /lib64/ (0x00007ff654e8f000) => /lib64/ (0x00007ff654c86000) => /usr/local/instantclient_12_1/ (0x00007ff651f99000) => /usr/lib64/ (0x00007ff651d88000) => /lib64/ (0x00007ff6519f3000)
 /lib64/ (0x0000003732c00000) => /usr/local/instantclient_12_1/ (0x00007ff6512dd000) => /usr/local/instantclient_12_1/ (0x00007ff651099000) => /lib64/ (0x00007ff650e97000) => /usr/local/instantclient_12_1/ (0x00007ff650947000) => /usr/lib64/ (0x00007ff65073e000)
[sb@host ~]$ 
Create /etc/tnsnames.ora connection  file 
[sb@host ~]$ cat /etc/tnsnames.ora 
  (Host = think)
  (Port = 1521)
 (CONNECT_DATA = (SID = testdb)
Make sure that connection by sqlplus is working
[sb@host ~]$ sqlplus testuser/testuser@testdb

SQL*Plus: Release Production on Wed Mar 12 23:06:24 2014

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Modify (or create) /etc/odbcinst and /etc/odbc.ini configuration files
[sb@host ~]$ cat /etc/odbcinst.ini
Description = Oracle
Driver   = /usr/local/instantclient_12_1/
[sb@host ~]$ cat /etc/odbc.ini
Description  = Oracle
Driver   = ORACLE
ServerName  = testdb
UserID   = testuser
Password = testuser
Verify that isql utility is working with Oracle
[sb@host ~]$ isql testdb
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
create table testid (id integer, name varchar(100))
InfoSphere Streams application
A simple StreamsStudio project is available here.
Database Toolkit operators use connection.xml file which specifies how application connects with external database. Connection.xml file contains information about connection and tables used in the database by InfoSphere Streams application.
Example of connection.xml file is available here.
Next step is to create application itself. It is very easy if one uses StreamsStudio framework, just drag operators to the application graph and connects input and output ports.
An example of sample application adding stream of data to external Oracle database is available here.
Visualization of this application:
Important limitation related to Oracle
Oracle does not support SPL int64 and uint64 data type. Also BIGINT in connection.xml file cannot containt BIGINT type (use INTEGER instead).

poniedziałek, 3 marca 2014

Jython MVP, enhancement

I added several enhancement to MVP Jython framework. The source code is available here. The sample application (Google App Engine) is available here.
Show, hide, enable and disable buttons
The description is available here.
Custom button in list tool bar and image button

Description is available here.
Blobs, download and upload
All blob content (files) are stored in a single table. It is possible to upload and download content via UI and also API for blob handling is available directly. More information is available here.
I want also add a PDF creation. But it is not easy to find a package which works in Google App Engine. The iText looks promising. It can be reached from Jython directly - look sample.
from com.itextpdf.text import DocumentException
from com.itextpdf.text import Paragraph
from com.itextpdf.text.pdf import PdfWriter

def createPDF(var) :
    # step 1
    document = Document()
    b = ByteArrayOutputStream()
    # step 2
    PdfWriter.getInstance(document, b)
    # step 3
    # step 4
    document.add(Paragraph("Hello World!"))
    #step 5
    return b.toByteArray()
Practical test in Google App Engine environment:  -> Different lists -> Dialog with attachments -> Upload -> PDF