ページ

2012年8月28日火曜日

node.jsサーバ+socket.ioでiPhoneアプリを作ったのでその備忘録。

node.jsサーバ+socket.ioでiPhoneアプリを作ったのでその備忘録。

アプリ機能
 同じパスでサーバー接続したiPhone同士のブラウザをリアルタイムに共有させる。

サーバサイドのディレクトリ
 node.jsのディレクトリ/test/app_temp.js

app_temp.js
==============================
var io = require('socket.io').listen(PORT_NUMBER);

// WebSocket接続時
con = io.sockets.on('connection', function (socket) {
console.log('CONNECTION ok');

socket.emit('reset');

socket.on('login',function(data){
console.log('CATCH JOIN EVENT ok',data);
socket.join(data.pass);
socket.set('name',data.name);
socket.set('pass',data.pass);
//con.to(data.pass).emit('joining',data);
socket.emit('loggingin',data);
socket.broadcast.to(data.pass).emit('joining',data);
});

socket.on('scroll', function (data) {
var name,pass;
console.log('CATCH SCROLL EVENT ok', data);
socket.get('pass',function(err,_pass){
pass = _pass;
});
con.to(pass).emit('scrolling',data);
});

socket.on('load', function (data) {
var name,pass;
console.log('CATCH LOAD EVENT ok', data);
socket.get('pass',function(err,_pass){
pass = _pass;
});
con.to(pass).emit('loading',data);
});

socket.on('zoom',function(data){
var name,pass;
console.log('CATCH ZOOM EVENT ok',data);
socket.get('pass',function(err,_pass){
pass = _pass;
});
con.to(pass).emit('zooming',data);
});

socket.on('disconnect',function(){
console.log('DISCONNECT END');
var name,pass;
socket.get('pass',function(err,_pass){
pass = _pass;
});
socket.get('name',function(err,_name){
name = _name;
});
socket.leave(pass);
con.to(pass).emit('disconnect',name);
});
});
====================================

2012年4月17日火曜日

音声認識Julius(とportaudio)のインストールできた。

できました。

マシンはMacbookAirでOSはLionにアップグレード済み。

Homebrewでportaudioをダウンロード

brew install portaudio

Juliusのソースファイルをダウンロードしてコンパイル


cd julius4
./configure --enable-words-int --with-mictype=portaudio --disable-zlib
make
sudo make install


Google先生に聞くと、

CFLAGS='-arch i386'

を入れよとかあったけど、いれずに行けたのは謎。てかむしろ入れたらerrorでうまく行かなかったし。

ディクテーションキットをダウンロードして解凍。


tar xzf dictation-kit-v4.1.tar.gz

cd dictation-kit-v4.1


ここで、


julius -C fast.jconf -charconv EUC-JP UTF-8


で認識に成功。(はじめ、無意識にwin用のdictation-kitをDLしてたみたいで、文字化けしてうまくいかなかったでど、Linux用いれなおして成功。)

参考にしたサイト
http://ascii.jp/elem/000/000/547/547250/index-2.html
http://geisterchor.blogspot.jp/2012/02/macos-x-lion-portaudio.html
http://tanb.me/2009/12/julius-414-on-osx-1062-snow-leopard.html
http://d.hatena.ne.jp/kazekyo/20100821/1282406366

2012年4月14日土曜日

portaudioを入れようとしているが、makeがうまくいかない





Lionにアップグレードしたmacにportaudioを入れようとしているが、makeがうまくいかない。。。

ぐぐると同じような人もいて、

http://geisterchor.blogspot.jp/

http://www.fluxforge.com/blog/building-portaudio-under-os-x-107-lion

を参考にしてみたが、どうもうまく行かない。

make したあとのエラーを見ると、

llvm-gcc-4.2: error trying to exec '/usr/bin/../llvm-gcc-4.2/bin/powerpc-apple-darwin11-llvm-gcc-4.2': execvp: No such file or directory
lipo: can't figure out the architecture type of: /var/folders/gm/62k1k9jx7h1dzwwpsqy36wy80000gn/T//ccEBtqHw.out
make: *** [src/common/pa_allocation.lo] Error 1

コンパイラ?とかppc?の問題のような気もするけど、どうしたらよいのか。。。

http://www.fluxforge.com/blog/building-portaudio-under-os-x-107-lion

の中にDon’t forget to strip PPC code from the generated fat lib (man lipo) if you’re planning to submit to the Mac App Store
という記述があり、lipoでppcをsplitしとけ!的な感じなんだけど、lipoの使い方もいまいち分からないし。

lipo -remove ??とか?


そもそもこの辺りの知識がなさすぎなんだよね。ふぅ。

2012年3月16日金曜日

NSXMLParser途中でやめたときのメモ

NSXMLParser使ってみようと思ったけど、下記じゃあ動かない。



 NSLog(@"hooooooo");が実行されていない。


とりあえずJSON形式に変更したので、XMLは途中でやめたのだが、
また使うときのために備忘録メモしとく。てかyoutubeもJSON形式のようだし。

.hファイル

@interface FirstViewController : UITableViewController<
NSXMLParserDelegate
>{

NSMutableData *resultUnsync;
NSURLConnection *connection;
//---xml parsing---
NSXMLParser *xmlParser;
}



.mファイル

@implementation FirstViewController

// レスポンスが返ってきたときに呼び出されるメソッド
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
resultUnsync =[[NSMutableData alloc]init];
NSLog(@"returned response:%@",resultUnsync);
};

// データが返ってきたときに呼び出されるメソッド
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
[resultUnsync appendData:data];
NSLog(@"returned data :%@",data);
};

// データ受信が完了したときに呼び出されるメソッド
- (void)connectionDidFinishLoading:(NSURLConnection *)connection{
NSString *resultUnsyncString = [[NSString alloc]initWithData:resultUnsync encoding:NSASCIIStringEncoding];
NSLog(@"finished recieved datas :%@",resultUnsyncString);

if (xmlParser)
{
//[xmlParser release];
}
xmlParser = [[NSXMLParser alloc] initWithData: resultUnsync];
[xmlParser setDelegate: self];
[xmlParser setShouldResolveExternalEntities:YES];
NSLog(@"yaaaaaaaa");
[xmlParser parse];
}

//---when the start of an element is found---
-(void) parser:(NSXMLParser *) parser didStartElement:(NSString *) elementName namespaceURI:(NSString *) namespaceURI qualifiedName:(NSString *) qName attributes:(NSDictionary *) attributeDict {

NSLog(@"hooooooo");
if( [elementName isEqualToString:@"comment"]){
NSLog(@"haaaaaaa!");
}
}

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
NSString *keyword = [searchBar text];
NSLog(@"検索語: %@",keyword);
[searchBar resignFirstResponder];

NSString *requestFeed = @"http://gdata.youtube.com/feeds/api/videos?q=%@&v=2&format=1,6&alt=jsonc";
NSString *urlStirng = [NSString stringWithFormat:requestFeed,
[keyword stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"url=%@",urlStirng);
NSURL *url = [NSURL URLWithString:urlStirng];

NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];

// 非同期通信
connection = [NSURLConnection connectionWithRequest:urlRequest delegate:self];

}

2012年3月15日木曜日

NSURLとかNSURLConnectionとか

// 非同期通信用メソッド
 // レスポンスが返ってきたときに呼び出されるメソッド
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
 resultUnsync =[[NSMutableData alloc]init];
NSLog(@"init resultUnsync:%@",resultUnsync);
};
 // データが返ってきたときに呼び出されるメソッド
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
[resultUnsync appendData:data];
NSLog(@"append data :%@",data);
};

// データ受信が完了したときに呼び出されるメソッド
- (void)connectionDidFinishLoading:(NSURLConnection *)connection{
NSString *resultUn = [[NSString alloc]initWithData:resultUnsync encoding:NSASCIIStringEncoding];
NSLog(@"result :%@",resultUn);
};




- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
NSString *keyword = [searchBar text];
NSLog(@"検索語: %@",keyword);
[searchBar resignFirstResponder];

NSString *requestFeed = @"http://gdata.youtube.com/feeds/api/videos?q=%@&v=2&format=1,6&alt=jsonc";
NSString *urlStirng = [NSString stringWithFormat:requestFeed,
[keyword stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"url=%@",urlStirng);
NSURL *url = [NSURL URLWithString:urlStirng];

NSError *err=nil;

// 簡単なやり方
//id str2 = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&err];
//NSLog(@"%@",str2);

NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];

// 同期通信
/*
NSURLResponse *urlResponse = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&urlResponse error:&err];
NSString *result = [[NSString alloc]initWithData:data encoding:NSASCIIStringEncoding];
NSLog(@"result:%@",result);
*/

// 非同期通信
NSURLConnection *connection = [NSURLConnection connectionWithRequest:urlRequest delegate:self];

}

2012年3月10日土曜日

gimp でボタンを作ってみた。


gimp でボンタをつくてみた。
以下を参考に。
http://mygimptutorial.com/round-web-20-button-with-a-metal-ring
gimpむずいけど、チュートリアルがいっぱいあるので、
なにげにいろいろできて楽しくなってきた。

これ習得して、アプリの素材ばんばん自作できるようになろう、かな。

2012年2月25日土曜日

audiosessionで録音と再生(スピーカー)を使うメモ

AppDelegate.hで

#import
#import
@interface AppDelegate : UIResponder < UIApplicationDelegate ,AVAudioRecorderDelegate // 録音用 ,AVAudioPlayerDelegate // 再生用 >

AppDelegate.mで

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

//オーディオセッション設定
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *error = nil;
// 使用している機種が録音に対応しているか
if ([audioSession inputIsAvailable]) {
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];
}
if(error){
NSLog(@"audioSession: %@ %d %@", [error domain], [error code], [[error userInfo] description]);
//return;
}
// 録音機能をアクティブにする
[audioSession setActive:YES error:&error];
if(error){
NSLog(@"audioSession: %@ %d %@", [error domain], [error code], [[error userInfo] description]);
//return;
}

UInt32 doChangeDefaultRoute = 1;
AudioSessionSetProperty (
kAudioSessionProperty_OverrideCategoryDefaultToSpeaker,
sizeof (doChangeDefaultRoute),
&doChangeDefaultRoute
);

......

}


ViewController.hで

#import
@interface ViewController : UIViewController
< AVAudioRecorderDelegate // 録音用 ,AVAudioPlayerDelegate // 再生用 >

ViewController.mで

// 録音
-(void)audioRecorderDidFinishRecording:(AVAudioRecorder *)recorder successfully:(BOOL)flag{
NSLog(@"録音成功");
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"録音完了" message:@"録音完了しました。" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK" , nil];
[alert show];
[recorder release];
}

-(void)recordKey{
NSLog(@"録音");
NSString *docFolder = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSString *soundFilePath = [NSString stringWithFormat:@"%@/sound.caf",docFolder];
NSLog(@"%@",soundFilePath);
NSURL *soundURL = [NSURL fileURLWithPath:soundFilePath];
NSLog(@"%@",soundURL);
NSError *error = nil;
AVAudioRecorder *recorder = [[AVAudioRecorder alloc] initWithURL:soundURL settings:nil error:&error];
if(error != nil){
NSLog(@"AVAudioRecorderのイニシャライズでエラー(%@)",[error localizedDescription]);
return;
}
[recorder setDelegate:self];
[recorder recordForDuration:3.0f];
}

-(IBAction)tapRecord:(id)sender{
[self recordKey];
}

// 再生
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag {
NSLog(@"再生成功");
[player release];
}

- (void)playKey{
NSLog(@"再生開始");
NSString *docFolder = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSString *soundFilePath = [NSString stringWithFormat:@"%@/sound.caf", docFolder];
NSURL *soundURL = [NSURL fileURLWithPath:soundFilePath];
if ( [[NSFileManager defaultManager] fileExistsAtPath:soundFilePath] == NO ) {
NSLog(@"ファイルがないため再生できません");
return;
}
NSError *error = nil;
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundURL error:&error];
if (error != nil) {
NSLog(@"AVAudioPlayerのイニシャライズでエラー(%@)",[error localizedDescription]);
[player release];
error=nil;
return;
}
[player setDelegate:self];
player.volume=1.0f;
[player play];

}

-(IBAction)tapPlay:(id)sender{
[self playKey];
}

2012年2月23日木曜日

vncサーバーによるgnome接続方法

vi /etc/sysconfig/vncservers でディスプレイ番号など初期設定

/etc/init.d/vncserver start でvncサーバー起動

リモート端末からvncクライアントソフト起動

id,pwを入力して接続

pptp-client 接続方法

su - でroot権限に。

/etc/init.d/pptp-client status で状態確認


/etc/init.d/pptp-client start で接続

2012年2月16日木曜日

javascript regexp 正規表現

matchによる正規表現 。。。
var s = "Is this all there is ?";
var pat = /..../;
document.write(s.match(pat));


/.../
/i 大文字小文字とわない
/g マッチするものはすべて
/[abc]/ abcどれか
/[^abc]/ abc以外のどれか
/[a-h]/ aからhのどれか
/[a-z]/ aからzのどれか
/[A-z]/ AからZ、aからzのどれか

/¥w/ 文字
/¥W/ 文字以外
/¥d/ 数字
/¥D/ 数字以外
/¥s/ 空白
/¥S/ 空白以外
/¥b/ 文頭
/¥B/ 文頭以外


/n+/g 少なくとも1個以上のn
/n*/g 0個以上のn
/n?/g 0か1個のn
/n{X}/g X個のn
/n{X,Y}/g XからY個のn
/n{X,}/g 少なくともX個以上のn
/n$/g nで終わる
/^n/g nで始まる

/n(?= m)/ mにつづくn
/n(?! m/ mにつづかないn