Post date: Feb 11, 2013 2:27:11 PM
http://julius.sourceforge.jp/ のディクテーションキットをダウンロードしてくるとjuliusで遊ぶことができる。
juliusをダウンロードしたときはrun_fast.batで音声認識を起動できるが、これではProcessingやHSPと連携することが出来ない。
ここでrun_fast.batをコピーして、中身をテキストエディタで開く。そして文末に「 -module」を追加。
するとモジュールモードとして動かすことができる。
とりあえず、Processingのサンプルソースを上げておこう。
//まず「julius_fast_module.bat」起動
import processing.net.*;
Client myClient; //Juliusとの連携で必要
float x;
float y;
String word="";
color col=color(0,0,0);
void setup(){
size(500, 500);
myClient = new Client(this,"localhost",10500); //Juliusとの連携で必要
x = 500;
y = random(500);
}
void draw(){
String tmpword = getWord(); //ここでJuliusで認識した音声を読み取る
if(tmpword.indexOf("赤")!=-1)col=color(255,0,0);
if(tmpword.indexOf("青")!=-1)col=color(0,0,255);
if(tmpword.indexOf("緑")!=-1)col=color(0,255,0);
if(tmpword.indexOf("白")!=-1)col=color(255,255,255);
if(tmpword.indexOf("黒")!=-1)col=color(0,0,0);
if(tmpword.indexOf("黄")!=-1)col=color(255,255,0);
if(tmpword.indexOf("ピンク")!=-1)col=color(255,0,255);
if(tmpword.indexOf("水")!=-1)col=color(0,255,255);
background(col);
x -= 1;
if ( x == -50) {
x = 550;
y = random(width - 50);
}
text(word,x,y);
}
//これ以降がJuliusとの連携部分
String getWord(){
String word = "";
if (myClient.available()>0){
String dataIn = myClient.readString();
String[] sList = split(dataIn, "WORD");
for(int i=1;i<sList.length;i++){
String tmp = sList[i];
String[] tList = split(tmp, '"');
word += tList[1];
}
}
if (word != ""){
println(word);
}
return word;
}
プログラム起動前にモジュールモードでjuliusを起動しておく必要がある。