• 締切済み

LinearPCMをwavで保存する方法

ios(objective-c)で録音機能を作っているのですが、下記の様な宣言で行った場合 LinearPCMで保存することができると思います。 これをwavフォーマット保存するにはどの様に(変換?)すれば良いのでしょうか? よろしくお願いいたします。 NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithUnsignedInt:kAudioFormatLinearPCM], AVFormatIDKey, [NSNumber numberWithFloat:44100.0], AVSampleRateKey, [NSNumber numberWithUnsignedInt:1], AVNumberOfChannelsKey, [NSNumber numberWithUnsignedInt:16], AVLinearPCMBitDepthKey,nil]; AVAudioRecorder *recorder = [[AVAudioRecorder alloc] initWithURL:[NSURL fileURLWithPath:filePath] settings:settings error:&error];

みんなの回答

回答No.1

http://objective-audio.jp/2010/09/avassetreaderavassetwriter.html に、ミュージックライブラリ内の音楽データをwav形式で書き出す例が ありますので、これを参考にすると変換できるかもしれません。 ただ http://stackoverflow.com/questions/23798605/convert-recorded-audio-file-in-to-wav-format-in-ios では、同じようなことをしていてうまく行かなくて質問している人がいますので AVAudioRecorderで録音したデータを変換するのは何か問題があるのかもしれませんし、 この質問者のコードのどこかにミスがあるだけなのかもしれません。 これらを参考にして頑張ればなんとかなるかもしれません。 ただ、なぜwav形式のデータが必要なのかわかりませんが、 PCに転送して再生したいなら、mp3やaac形式で録音した方が サイズも小さくなるし、取り扱いし易いと思います。

全文を見る
すると、全ての回答が全文表示されます。

関連するQ&A

  • xcodeの音を鳴らすのを遅らせる方法

    xcodeで音を鳴らしたいんですけど、 ボタンを押して数秒したら音が鳴るようにしたいんですけどどうしたらいいでしょうか? ループさせるので音源の最初を空白にするわけにはいきません。 あとAVAudioPlayerを使ったやり方だと助かります。 NSString *bgmPath = [[NSBundle mainBundle] pathForResource:@"music"ofType:@"mp3"]; NSURL *bgmUrl = [NSURL fileURLWithPath:bgmPath]; sound = [[AVAudioPlayer alloc] initWithContentsOfURL:bgmUrl error:nil]; [sound setNumberOfLoops:0]; //ここに指定した時間遅らせるというのを入れたい// [sound play]; どうかよろしくお願いします。

  • objective-Cについてご相談があります。

    現在objective-cを勉強中なのですが、 jsonについて教えて頂きたい事があります。 jsonのファイル・データ・オブジェクトそれぞれを 取得する必要があると習ったのですが、それらの違いが 今ひとつ分かりません。 下記のような記述なのですが、それぞれの違いをどなたか ご教示頂けないでしょうか。 // 対象Jsonファイル取得 NSBundle *bnd = [NSBundle mainBundle]; NSString *ptn = [bnd pathForResource:@"Test01" ofType:@"json"]; NSURL *url = [NSURL fileURLWithPath:ptn]; // Jsonオブジェクトの取得 NSURLRequest *req =[NSURLRequest requestWithURL:url]; NSData *dat = [NSURLConnection sendSynchronousRequest:req returningResponse:nil error:nil]; // Jsonデータの取得 NSDictionary *dick01 = (NSDictionary *) [NSJSONSerialization JSONObjectWithData:dat options:NSJSONReadingMutableContainers error:nil]; 以上、何卒宜しくお願い致します。

  • サウンドレコーダーの音源をwavで保存する方法

    OSの標準アクセサリで付いているサウンドレコーダーで録音した音源を wav形式で保存したいと考えています。 OSは windows vista home premium です。 xpを使用していた時はwavで保存出来ていたと思うんですが、色々調べてみたところ vistaの仕様では、サウンドレコーダーはwma形式での保存しか出来ない様になっているとありました。 wma→wavにエンコードすればいいのかもしれませんが できることなら手間を省いて簡単にwavで保存したいのです…。 もし、何か裏技のようなものがあれば、ご教授のほど宜しくお願いいたします。

  • iPhoneアプリの開発についてです。

    ウェブサイトをローカルに保存しオフラインでUIWebViewに表示したいです。 http://blog.livedoor.jp/sionami/archives/3551091.htmlのサイトを参考にし実行してみましたが、オフラインでは表示されませんでした。また、表示されたサイトは(オンライン時)スマートフォン向けだったページがPC版の表示で表示されました。 以下が実行したプログラムです。コードの一部が間違っているのでしょうか。それともやり方そのものが間違っているのでしょうか。ご指摘お願いします。(エラー時のプログラムは省略しました) NSString *filePath; - (void)downloadHTML:(NSString *)html { NSString *directoryPath = [NSHomeDirectory() stringByAppendingPathComponent:@"tmp"]; //ダウンロードファイルの保存先 NSString *fileName = [html lastPathComponent]; filePath = [[directoryPath stringByAppendingPathComponent:fileName] stringByStandardizingPath];//保存したファイルへのパス NSURL *url = [NSURL URLWithString:html]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; NSURLResponse *response = nil; NSError *error = nil; NSData *data = [ NSURLConnection sendSynchronousRequest : request returningResponse : &response error : &error ]; //ファイル書き込み NSFileManager *fm = [NSFileManager defaultManager]; [fm createFileAtPath:filePath contents:[NSData data] attributes:nil]; NSFileHandle *file = [NSFileHandle fileHandleForWritingAtPath:filePath]; [file writeData:data]; } - (IBAction)refresh:(UIButton *)sender { NSString *htmlStr = [NSString stringWithContentsOfFile:filePath]; [_myWebView loadHTMLString:htmlStr baseURL:nil]; } また、http://qiita.com/EntreGulss/items/8da6847e4dae59bfb1ebのサイトの方法も試しましたが同じくオフラインで表示されませんでした。

  • Wavで保存した太鼓の音色を軽くする保存方法を教えて下さい。

    作成したHP の祭り紹介画面に(音楽のメロディー)のように(祭り太鼓)の音色をいれましたが、[SONYのICレコーダーで録音を取り保存を Win 上で音が出るように、”Wavの拡張子”で取り込みました] が20秒の音色が”300KB”位の重い音色になってしまいます。”MIDI素材ピアノソロ倶楽部”のけっこう長いピヤノ曲を DL しても、せいぜい 30 KB位です。 HP で使用でき”midの拡張子”で保存する方法、軽く保存する方法を知りたいのですがよろしく願い致します。 URL http://www.hi-ho.ne.jp/c-ogawa/ の(秋祭り1)に太鼓の音色を入れてあり、DL に時間がかかります。

  • WAVファイルをCD-Rに書き込めません(涙)

    ICレコーダーで録音したファイルをWAVファイルに変換し、 コンポやカーステでも聴けるようにオーディオCDの形式で書き込み しようとしたのですが、エラーになってしまいます。 2時間ほどの会議で、もとのWavファイルは150MB程度です。 どうしたらいいでしょう???

  • iPhone開発について

    初歩的な質問ですが、お願い致します。 ボタンをタップで音が鳴り、再びタップで音を止めるという動きを AVAudioPlayerを利用し実装したいと考えておりますがストップが思い通りに動きません。 プレイは正常に動作しております。 xCode4 で xib を利用しております。 該当部分だけコードを以下に抜粋させていただきます。 hogeController.m - (IBAction)btn{ NSString *path = [[NSBundle mainBundle] pathForResource:@"hoge" ofType:@"mp3"]; NSURL *url = [NSURL fileURLWithPath:path]; AVAudioPlayer *oto = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil]; if (hogeFlg == NO){ hogeFlg = YES; [oto play]; }else{ hogeFlg = NO; [oto stop]; } } デバッグでは、2回目のタップで、[oto stop];は通過しております。 基本的なところが理解できていないためということはわかっているのですが、解決策がわかりません。 また、xib を利用しておりますので、起動時に、- (void)viewDidload を読み込むのかな? と思い、入れてみたのですが通っておりません。 本当は、ここでセットして、ボタンタップじでは、再生と停止の処理だけを入れたいのですが、そういうことは可能なのでしょうか。 どうぞ、よろしくお願い致します。

  • NSTimerカウントダウンで音楽を停止するには?

    Xcodeで iPhoneアプリ作りに奮闘している初心者です。 NSTimerでカウントダウンタイマーを設定しましたが、タイマー終了とともに BGM音楽を停止したいのですが、.p ファイルに #import <AVFoundation/AVFoundation.h> と追加して、.m ファイルに タイマー終了時にイベントとして、 if (RestTime == 0) { timeflag = false; NSString *bgmPath = [[NSBundle mainBundle] pathForResource:@"xxxx"ofType:@"mp3" ]; NSURL *bgmUrl = [NSURL fileURLWithPath:bgmPath]; sound = [[AVAudioPlayer alloc] initWithContentsOfURL:bgmUrl error:nil]; [sound setNumberOfLoops:-1]; [sound stop]; とコードをいれてみましたが、タイマーは終了しても音楽は止まらず鳴りっぱなしです。 NSTimer周辺に詳しい方で、カウントダウンタイマー終了と同時に他の作動をとめる設定(プログラムコード)をお知りのかたお助けねがいます。 また、すでに鳴っている(他のページ又は同じページ,controller内の)音楽をタイマーに合わせて止めることが不可能なら、タイマースタートボタンを押すと同時に音楽をスタートし、タイマー終了とともに音楽を停止するプログラムコードを教えていただけたら助かります。 よろしくお願いします。

  • iphoneアプリの開発

    電卓アプリを作っています。 今困っているのは 1.割り算で小数点以下の計算ができない。 2.3つ以上の計算が(2×3×4のような)足し算しかできない。 3.間違えて数値を入力した場合に使うバックスペース的なボタンの作り方。 です。 どれか一つでもいいのでアドバイスいただけたらありがたいです。 #import "myViewController.h" @implementation myViewController // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. /* - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization. } return self; } */ // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; startInput = YES; currentValue = 0; } -(IBAction)numberButtonPressed:(id)sender { UIButton *b = (UIButton *)sender; if( startInput ){ // 最初の1桁目が0なら表示しない if( b.tag == 0 ) return; // 新しく表示する文字列を作成 label.text = [NSString stringWithFormat:@"%d", b.tag]; startInput = NO; } else { // すでに表示されている文字列に連結 label.text = [NSString stringWithFormat:@"%@%d", label.text, b.tag]; } NSString *path = [[NSBundle mainBundle] pathForResource:@"button5" ofType:@"wav"]; NSURL *url = [NSURL fileURLWithPath:path]; AVAudioPlayer *audio = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil]; [audio play]; } -(IBAction)equalButtonPressed:(id)sender { currentValue = sum; sum = sum-sum; // 直前に押された演算子で場合分け if( operation == 0 ){ currentValue += [label.text intValue]; } else if( operation == 1 ){ currentValue -= [label.text intValue]; } else if( operation ==2){ currentValue *= [label.text intValue]; } else if (operation ==3){ currentValue /= [label.text intValue]; } // 表示の更新 label.text = [NSString stringWithFormat:@"%d", currentValue]; startInput = YES; label2.text =@"="; NSString *path = [[NSBundle mainBundle] pathForResource:@"button5" ofType:@"wav"]; NSURL *url = [NSURL fileURLWithPath:path]; AVAudioPlayer *audio = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil]; [audio play]; } -(IBAction)opButtonPressed:(id)sender { UIButton *b = (UIButton *)sender; // 現在値の保存 if( operation == 0 ){ currentValue= [label.text intValue]; sum +=currentValue; label.text =[NSString stringWithFormat:@"%d", sum]; } // 演算の保存 operation = b.tag; startInput = YES; if( operation == 0 ){ label2.text =@"+"; } if( operation == 1 ){ label2.text =@"-"; } if( operation == 2 ){ label2.text =@"×"; } if( operation == 3 ){ label2.text =@"÷"; } NSString *path = [[NSBundle mainBundle] pathForResource:@"button5" ofType:@"wav"]; NSURL *url = [NSURL fileURLWithPath:path]; AVAudioPlayer *audio = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil]; [audio play]; } -(IBAction)clearButtonPressed:(id)sender { label.text = @"0"; startInput = YES; label2.text =@""; NSString *path = [[NSBundle mainBundle] pathForResource:@"button5" ofType:@"wav"]; NSURL *url = [NSURL fileURLWithPath:path]; AVAudioPlayer *audio = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil]; [audio play]; } /* // Override to allow orientations other than the default portrait orientation. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations. return (interfaceOrientation == UIInterfaceOrientationPortrait); } */ - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc. that aren't in use. } - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (void)dealloc { [super dealloc]; } @end

  • MKMapkitの緯度経度を配列から呼びたい

    Objective-cで開発を行っている初心者です。 最近、MKMapkitを使って地図上にピンを立てられるようになったのですが、ピンを立てる位置情報をNSMutableArrayから呼んでこようとしたところつまづいてしまいました。 [Latitude addObject:[NSNumber numberWithDouble:35]]; [Latitude addObject:[NSNumber numberWithDouble:36]]; // CustomAnnotationクラスの初期化(インスタンス化) CustomAnnotation *Pin = [[CustomAnnotation alloc] initWithLocationCoordinate:CLLocationCoordinate2DMake(Latitude[0], 139.763153) title:@"テスト" subtitle:@"test"]; 以上の部分で、"Passing 'id' to parameter of incompatible type 'CLLocationDegrees' (aka 'double')"のエラーが・・・。 latitude,longitudeの型を調べたところdouble型であるとあったのでそのようにして配列をつくったのですが、まだなにかしなければならないことがあるのでしょうか? 初歩的な質問かとは思いますが、どうかよろしくお願いします。