Blog do projektu Open Source JavaHotel

niedziela, 30 marca 2014

octave, Mel-frequency cepstrum

Introduction
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
Usage
I tried to use this package for recognizing numbers in voice command but failed. As a reference voice I downloaded samples from http://dictionary.reference.com/ (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

Introduction
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.
Example
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/instantclient_12_1/
Make sure that libsqora.so.12.1 library has all dependency resolved.
[sb@host ~]$ ldd /usr/local/instantclient_12_1/libsqora.so.12.1 
 linux-vdso.so.1 =>  (0x00007ffff43ff000)
 libdl.so.2 => /lib64/libdl.so.2 (0x00007ff65554a000)
 libm.so.6 => /lib64/libm.so.6 (0x00007ff6552c5000)
 libpthread.so.0 => /lib64/libpthread.so.0 (0x00007ff6550a8000)
 libnsl.so.1 => /lib64/libnsl.so.1 (0x00007ff654e8f000)
 librt.so.1 => /lib64/librt.so.1 (0x00007ff654c86000)
 libclntsh.so.12.1 => /usr/local/instantclient_12_1/libclntsh.so.12.1 (0x00007ff651f99000)
 libodbcinst.so.2 => /usr/lib64/libodbcinst.so.2 (0x00007ff651d88000)
 libc.so.6 => /lib64/libc.so.6 (0x00007ff6519f3000)
 /lib64/ld-linux-x86-64.so.2 (0x0000003732c00000)
 libnnz12.so => /usr/local/instantclient_12_1/libnnz12.so (0x00007ff6512dd000)
 libons.so => /usr/local/instantclient_12_1/libons.so (0x00007ff651099000)
 libaio.so.1 => /lib64/libaio.so.1 (0x00007ff650e97000)
 libclntshcore.so.12.1 => /usr/local/instantclient_12_1/libclntshcore.so.12.1 (0x00007ff650947000)
 libltdl.so.7 => /usr/lib64/libltdl.so.7 (0x00007ff65073e000)
[sb@host ~]$ 
Create /etc/tnsnames.ora connection  file 
(example)
[sb@host ~]$ cat /etc/tnsnames.ora 
testdb=
 ( DESCRIPTION =
  (ADDRESS_LIST =
  (ADDRESS =
  (PROTOCOL = TCP)
  (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 12.1.0.1.0 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 11.2.0.1.0 - 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
[ORACLE]
Description = Oracle
Driver   = /usr/local/instantclient_12_1/libsqora.so.12.1
[sb@host ~]$ cat /etc/odbc.ini
[testdb]
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                                  |
|                                       |
+---------------------------------------+
SQL> 
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

Introduction
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.
PDF
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
    document.open()
    # step 4
    document.add(Paragraph("Hello World!"))
    #step 5
    document.close()
    return b.toByteArray()
Practical test in Google App Engine environment: http://jythonui.appspot.com/?start=startleft.xml  -> Different lists -> Dialog with attachments -> Upload -> PDF