有谁能告诉我如何获取音频录制的数据?我想用不同的数据保存录制文件的数量。我正在做的是访问网址,目录路径并重命名它们,但结果是他们使用不同的名称保存,但没有使用不同的数据保存。所有文件正在播放我记录的最后一个声音。
源代码: -
- (IBAction) startRecording
{
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *err = nil;
[audioSession setCategory :AVAudioSessionCategoryPlayAndRecord error:&err];
[audioSession setMode:AVAudioSessionModeVoiceChat error:&err];
if(err)
{
NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
return;
}
[audioSession setActive:YES error:&err];
err = nil;
if(err)
{
NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
return;
}
recordSetting = [[NSMutableDictionary alloc] init];
// We can use kAudioFormatAppleIMA4 (4:1 compression) or kAudioFormatLinearPCM for nocompression
[recordSetting setValue :[NSNumber numberWithInt:kAudioFormatAppleIMA4] forKey:AVFormatIDKey];
// We can use 44100, 32000, 24000, 16000 or 12000 depending on sound quality
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
// We can use 2(if using additional h/w) or 1 (iPhone only has one microphone)
[recordSetting setValue:[NSNumber numberWithInt: 1] forKey:AVNumberOfChannelsKey];
[recordSetting setObject:[NSNumber numberWithInt:12800] forKey:AVEncoderBitRateKey];
[recordSetting setObject:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
[recordSetting setObject:[NSNumber numberWithInt: AVAudioQualityMax] forKey: AVEncoderAudioQualityKey];
recorderFilePath = [NSString stringWithFormat:@"%@/My Sound.caf",DOCUMENTS_FOLDER];
url = [NSURL fileURLWithPath:recorderFilePath];
err = nil;
recorder = [[AVAudioRecorder alloc] initWithURL:url settings:recordSetting error:&err];
soundData = [[NSData alloc] initWithContentsOfURL: url];
NSLog(@"soundData:%@",soundData);
NSLog(@"url:%@",url);
err = nil;
recorder = [[ AVAudioRecorder alloc] initWithURL:url settings:recordSetting error:&err];
if(!recorder)
{
NSLog(@"recorder: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
UIAlertView *alert =
[[UIAlertView alloc] initWithTitle: @"Warning"
message: [err localizedDescription]
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
return;
}
//prepare to record
[recorder setDelegate:self];
[recorder prepareToRecord];
recorder.meteringEnabled = YES;
BOOL audioHWAvailable = audioSession.inputIsAvailable;
if (! audioHWAvailable)
{
UIAlertView *cantRecordAlert =
[[UIAlertView alloc] initWithTitle: @"Warning"
message: @"Audio input hardware not available"
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[cantRecordAlert show];
}
// start recording
[recorder recordForDuration:(NSTimeInterval) 60];
Tag=30;
}
- (IBAction)saveRecording
{
if([recordingNameTextField.text isEqualToString: @""])
{
[alertView setMessage:@"Recording File Name not set.\n\n"];
[alertView show];
}
else
{
recorderFilePath = [NSString stringWithFormat:@"%@/My Sound.caf",DOCUMENTS_FOLDER];
NSLog(@"%@",recorderFilePath);
NSLog(@"%@",url);
renameString =[NSString stringWithFormat:@"%@/%@.caf",DOCUMENTS_FOLDER,recordingNameTextField.text];
NSLog(@"%@",renameString);
url2 = [NSURL fileURLWithPath:renameString];
NSLog(@"%@",url2);
NSFileManager *fm = [NSFileManager defaultManager];
NSError *renameError;
[fm moveItemAtURL:url toURL:url2 error:&renameError];
[recordingFile checkAndCreateDatabase];
[recordingFile addRecord:1 andname:recordingNameTextField.text];
[recordingFile readDatabase];
recordingNameTextField.text = @"";
NSLog(@"Text Field: %@",recordingNameTextField.text);
saveRecording.userInteractionEnabled=NO;
}
请帮忙。谢谢:)
答案 0 :(得分:1)
首先在sqlite中创建一个数据库,然后创建一个table.below是插入代码。
[self databasePath];
BOOL checkQuery=NO;
const char *sqlStatement;
sqlStatement = [sql UTF8String];
blob=voicedata;
//if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {
if(sqlite3_prepare_v2(database, sqlStatement, -1, &statement, NULL)!= SQLITE_OK) {
checkQuery=NO;
}
else {
sqlite3_bind_blob(statement, Loc, [blob bytes], [blob length], NULL);
if(SQLITE_DONE != sqlite3_step(statement)) {
checkQuery=NO;
}
else {
// NSLog(@"Query Working nicely");
checkQuery=YES;
sqlite3_reset(statement);
}
}
//}
//sqlite3_close(database);
sqlite3_finalize(statement);
在上面的代码中, sql =查询字符串 斑点= NSData的 loc = int value 1 如果有任何澄清让我知道的话,试试这个对我有用......