ofxTrueTypeFontUC + oF systemSpeak “Kyoko” test

openFrameworksのサンプルで英語で発音できていたので日本語でも発音できないのかな〜と思ったら普通に出来ました。

testApp.h

#pragma once
#include "ofMain.h"
#include "ofxTrueTypeFontUC.h"  // https://github.com/hironishihara/ofxTrueTypeFontUC

// ---------------------------------------------
class testApp : public ofBaseApp, public ofThread {
	
public:
    
    void setup();
    void draw();
    void exit();
    void threadedFunction();
    
    ofxTrueTypeFontUC font;
    vector <string> words;
    int step;
    
    string voice;
};

testApp.cpp

#include "testApp.h"

//--------------------------------------------------------------
void testApp::setup() {

    font.loadFont("ヒラギノ明朝 ProN W3.otf", 34);  //日本語対応フォントを ./bin/data下に
    voice = "Kyoko";                           //http://veadardiary.blog29.fc2.com/blog-entry-3854.html参照

    // load the lyrics from a text file and split them
    // up in to a vector of strings
    string lyrics = ofBufferFromFile("lyrics.txt").getText();  //適当な文章を。区切りたいところに半角スペースを入れる
    step = 0;
    words = ofSplitString(lyrics, " ");

    // we are running the systems commands
    // in a sperate thread so that it does
    // not block the drawing
    startThread();
}

//--------------------------------------------------------------
void testApp::threadedFunction() {

    while (isThreadRunning()) {
        // call the system command say
        #ifdef TARGET_OSX
            string cmd = "say -v "+voice+" "+words[step]+" ";   // create the command
            system(cmd.c_str());
        #endif
        #ifdef TARGET_WIN32
            string cmd = "data\\SayStatic.exe "+words[step];   // create the command
            cout << cmd << endl;
            system(cmd.c_str());
        #endif

        // step to the next word
        step ++;
        step %= words.size();

        // slowdown boy
        ofSleepMillis(10);
    }
}
//--------------------------------------------------------------
void testApp::draw() {
    // center the word on the screen
    float x = (ofGetWidth() - font.stringWidth(words[step])) / 2;
    float y = ofGetHeight() / 2;

    // draw the word
    ofSetColor(0);
    font.drawString(words[step], x, y);    
}

//--------------------------------------------------------------
void testApp::exit() {
    // stop the thread on exit
    waitForThread(true);
}

元は↓の歌詞でした。

Benny Benassi – Satisfaction


09/03 17:19

Finger tracking + ofxUGen test

指の検出はここ https://github.com/jvcleave/ofxKinect_Box2D
ofxUGenはここを参照しました。 http://ugen.googlecode.com/svn/doc/modules.html

もちっときっちり検出できるように精進致します…。


07/08 01:09

ofxNI2-user-tracker-test


07/06 13:10