Log on: Remember me
Powered by Elgg

Timo Baumann :: Blog Archives

April 2008

April 12, 2008

This has been programmed before, but here it is for you to see (and use):

IPATextField, a simple descendant of JTextField that will only accept phonetic input (either SAMPA or IPA if you know your uni codes by heart) and show IPA symbols.

You can try it out directly, as a main routine is included. It's even useful as your tiny copy-and-paste-IPA-editor.

/** Copyright (C) 2008 Timo Baumann
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License,
 * or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 **/

import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.text.CharacterIterator;
import java.text.StringCharacterIterator;

import javax.swing.AbstractAction;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.PlainDocument;

public class IPATextField extends JTextField {

    public IPATextField(int cols) {
        super(cols);
    }

    protected Document createDefaultModel() {
        return new IPADocument();
    }

    static class IPADocument extends PlainDocument {

        String search  = "Q?ɡTDSZCχʁNR=" + "IEA{OUY29@6:_";
        char[] replace = "ʔʔgθðʃʒçxrŋʀu0329ɪɛɑæɔʊʏøœəɐːu032F".toCharArray();
        String pass = search + replace + "pbtdkgfvszwjxhmnlrieaouy .";
       
        public void insertString(int offs, String str, AttributeSet a)
           throws BadLocationException
        {
           if (str == null) {
                return;
           }
           StringBuffer sb = new StringBuffer();
           CharacterIterator ci = new StringCharacterIterator(str);
           while (ci.getIndex() < ci.getEndIndex()) {
               char[] c = new char[1];
               c[0] = ci.current();
               String s = new String(c);
               if (pass.contains(s)) {
                   int replaceIndex = search.indexOf(s);
                   if (replaceIndex == -1) {
                       sb.append(s);
                   } else {
                       sb.append(replace[replaceIndex]);
                   }
               }
               ci.next();
           }
           super.insertString(offs, sb.toString(), a);
        }
    }
   
    /**
     * pretty much stolen from the Swing-Tutorial...
     * @param args does not take any arguments
     */
    public static void main(String[] args) {

        //Create the top-level container and add contents to it.
        JFrame frame = new JFrame("VoxforgeDE Lexicon Tool");
        final IPATextField tf = new IPATextField(10);
        tf.addActionListener(new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                System.out.println(tf.getText());
            }
        });
        frame.add(tf);

        //Finish setting up the frame, and show it.
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        frame.pack();
        frame.setVisible(true);
    }
}
 

Keywords: howto, java

Posted by Timo Baumann | 0 comment(s)

April 16, 2008

I am currently investigating the ton of classes that implement the Sphinx interface "SearchSpace", or one of the three sub-interfaces. There are 19 in total and I am likely to have to add another one for the feature that I have in mind.

Anyway, I decided that I need something, preferably an Eclipse-plugin to visualize class dependencies, and there are actually a few options:

  • X-Ray would probably do the job, but it doesn't work. Maybe I just don't know how to install it correctly.
  • Byecycle have a great screencast on their page and more friendly installation instructions. It shows a dependency graph between classes and automatically and incrementally optimizes the graph layout. Infinitely. Using 20% of your processor(s). It's quite slow and it seems to be limited to only show dependencies within the package, while the dependencies I'm interested in often cross dependency boundaries (classes from different packages implementing an interface).
Also, I found Fat Jar, an Eclipse plugin that turns your whole project into a single jar. That's something my collegue asked my about the other day.

Keywords: eclipse, java, sphinx

Posted by Timo Baumann | 0 comment(s)

April 25, 2008

If you just upgraded your Ubuntu to 8.04 and use sox, then you may get the error "sox soxio: Failed reading `some.file': unknown file type `auto'"

In Hardy, all audio formats for sox have been refactored in separate packages libsox-fmt-XYZ. So, either install just the base formats from libsox-fmt-base or get all possible formats with libsox-fmt-all.

Keywords: howto, sox, ubuntu

Posted by Timo Baumann | 0 comment(s)