티스토리 뷰

반응형

[음성녹음 *.wav 파일로 저장하기]

음성 녹음 후 파일을 공유하기 위해서 파일 확장자를 wav 설정해야만 했다.


다소 파일의 크기가 커진다는 문제점이 있긴 하지만 음질을 최대한 낮게 해놓아서 음질이나 크기면에서 나쁘지 않는듯 하다.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//.h
NSError                    *error;
NSMutableDictionary        *recordSetting;
NSURL                    *recordedTmpFile;    //재생시 불러올 경로
NSString                *recordedFileStr;    //삭제시 경로
AVAudioRecorder            *recorder;
AVAudioSession            *audioSession;
 
//.maudioSession = [AVAudioSession sharedInstance];
[audioSession setDelegate:self];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];
[audioSession setActive:YES error:&error];
 
recordSetting = [[NSMutableDictionary alloc] init];
[recordSetting setValue:[NSNumber numberWithInt:kAudioFileWAVEType] forKey:AVFileTypeWAVE];[recordSetting setValue:[NSNumber numberWithFloat:2410.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt:1] forKey:AVNumberOfChannelsKey];
[recordSetting setValue:[NSNumber numberWithInt:AVAudioQualityMin] forKey:AVEncoderAudioQualityKey]; [recordSetting setValue:[NSNumber numberWithInt:96] forKey:AVEncoderBitRateKey];
[recordSetting setValue:[NSNumber numberWithInt:16] forKey:AVEncoderBitDepthHintKey];
 
//record
 
int timeStamp = [[NSDate date] timeIntervalSince1970];
 
//load
recordedTmpFile = [NSURL fileURLWithPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent: [NSString stringWithFormat: @"record_%d.wav",timeStamp]]];
 
//delete
self.recordedFileStr = [NSString stringWithString:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent: [NSString stringWithFormat: @"record_%d.wav",timeStamp]]];
 
//record
recorder = [[ AVAudioRecorder alloc] initWithURL:recordedTmpFile settings:recordSetting error:&error];
[recorder setDelegate:self];
recorder.meteringEnabled = YES;
 
cs




반응형

'iOS > 자료정리' 카테고리의 다른 글

[iPhone]sqlite  (0) 2011.06.15
[iPhone]NSMutableArray, NSArray  (0) 2011.06.10
[iPhone]화면 회전  (0) 2011.04.13
[iPhone]TabbarController  (0) 2011.04.12
[iPhone][UIApplication sharedApplication]  (0) 2011.04.07
댓글
반응형