gpt4 book ai didi

iphone - 我们如何保存多个具有不同音频数据(声音)和不同名称的音频录制文件(.caf)?

转载 作者:行者123 更新时间:2023-12-03 21:17:17 26 4
gpt4 key购买 nike

谁能告诉我如何获取录音数据?我想用不同的数据保存多个录制文件。我正在做的是访问 url 、目录路径并重命名它们,但结果是它们使用不同的名称保存,但不使用不同的数据。所有文件都播放我录制的相同的最后一个声音。

源代码:-

- (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;
}

请帮忙。谢谢:)

最佳答案

首先在sqlite中创建数据库,然后创建表。下面是插入代码。

[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=查询字符串 Blob =nsdataloc=整数值1尝试一下,如果有任何说明让我知道,它对我来说效果很好......

关于iphone - 我们如何保存多个具有不同音频数据(声音)和不同名称的音频录制文件(.caf)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10347704/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com