gpt4 book ai didi

iphone - iOS – 将录音保存到应用文档

转载 作者:行者123 更新时间:2023-11-29 11:16:18 26 4
gpt4 key购买 nike

我想将录制的文件保存到我的应用程序文档中,但不知道该怎么做。我做了一个录音,它存储在一个临时文件中,我可以播放那个声音。现在,当我离开该 View 时,我想将该文件以新名称保存到应用程序文档中。

录制声音的代码:

NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsDir = [dirPaths objectAtIndex:0];
NSString *soundFilePath = [docsDir
stringByAppendingPathComponent:@"tmpSound.caf"];

tempRecFile = [NSURL fileURLWithPath:soundFilePath];

NSDictionary *recSettings = [NSDictionary
dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:AVAudioQualityMin],
AVEncoderAudioQualityKey,
[NSNumber numberWithInt:16],
AVEncoderBitRateKey,
[NSNumber numberWithInt: 2],
AVNumberOfChannelsKey,
[NSNumber numberWithFloat:44100.0],
AVSampleRateKey,
nil];

recorder = [[AVAudioRecorder alloc] initWithURL:tempRecFile settings:recSettings error:nil];
[recorder setDelegate:self];
[recorder prepareToRecord];
[recorder record];

有没有人知道如何做到这一点,或者是否有可能做到这一点?

最佳答案

你应该能够用类似的东西来做到这一点:

NSError *error;
[[NSFileManager defaultManager] copyItemAtURL:tempRecFile toURL:newURL error:&error];

或者如果您不关心错误:

[[NSFileManager defaultManager] copyItemAtURL:tempRecFile toURL:newURL error:nil];

但请注意 - 您应该仔细考虑您是否真的需要将此音频保存在文档文件夹中,或者缓存文件夹是否足够。 Apple 对允许的内容有严格的规定。

关于iphone - iOS – 将录音保存到应用文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9296165/

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