Ios 如何将CoreData(NSManagedObject)设置为AvAudioRecorder的目标?
我可以通过什么方法将NSManagedObject设置为AVAudioRecorder的目标(与NSURL相反)?我想在选择“外部存储”选项的情况下,将微小的声音片段保存为二进制核心数据类型。。。当然,也会播放它们。我已经看到了一些围绕这个主题的问题,似乎有一些正在这样做,但我还没有找到任何核心代码示例。到目前为止,我已经按照本教程成功地录制了基本文件类型:,我只想将其直接带到核心数据 仅供参考-我确实意识到最佳实践是存储URL,然后检索,但如果可能的话,我真的希望直接将二进制文件输入CoreData 谢谢Ios 如何将CoreData(NSManagedObject)设置为AvAudioRecorder的目标?,ios,core-data,swift,avaudiorecorder,Ios,Core Data,Swift,Avaudiorecorder,我可以通过什么方法将NSManagedObject设置为AVAudioRecorder的目标(与NSURL相反)?我想在选择“外部存储”选项的情况下,将微小的声音片段保存为二进制核心数据类型。。。当然,也会播放它们。我已经看到了一些围绕这个主题的问题,似乎有一些正在这样做,但我还没有找到任何核心代码示例。到目前为止,我已经按照本教程成功地录制了基本文件类型:,我只想将其直接带到核心数据 仅供参考-我确实意识到最佳实践是存储URL,然后检索,但如果可能的话,我真的希望直接将二进制文件输入CoreD
p、 如果您有Swift的样品,我们将不胜感激 您需要将音频另存为NSData。您需要将文件保存在磁盘中并转换为NSData 我有一个功能,配置我的音频,一秒钟的功能,使转换
-(void)persistDataAudioPlaylet{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"myAudio.caf"];
NSData *fileContents = [NSData dataWithContentsOfFile:filePath];
self.playlet.sound = fileContents;
}
-(void)configureAudioRecord{
NSArray *dirPaths;
NSString *docsDir;
dirPaths = NSSearchPathForDirectoriesInDomains(
NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = dirPaths[0];
NSString *soundFilePath = [docsDir
stringByAppendingPathComponent:@"myAudio.caf"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
NSDictionary *recordSettings = [NSDictionary
dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:AVAudioQualityMin],
AVEncoderAudioQualityKey,
[NSNumber numberWithInt:16],
AVEncoderBitRateKey,
[NSNumber numberWithInt: 2],
AVNumberOfChannelsKey,
[NSNumber numberWithFloat:44100.0],
AVSampleRateKey,
nil];
NSError *error = nil;
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord
error:nil];
self.audioRecorder = [[AVAudioRecorder alloc]
initWithURL:soundFileURL
settings:recordSettings
error:&error];
if (error)
{
NSLog(@"error: %@", [error localizedDescription]);
} else {
[self.audioRecorder prepareToRecord];
}
}
您需要将音频另存为NSData。您需要将文件保存在磁盘中并转换为NSData 我有一个功能,配置我的音频,一秒钟的功能,使转换
-(void)persistDataAudioPlaylet{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"myAudio.caf"];
NSData *fileContents = [NSData dataWithContentsOfFile:filePath];
self.playlet.sound = fileContents;
}
-(void)configureAudioRecord{
NSArray *dirPaths;
NSString *docsDir;
dirPaths = NSSearchPathForDirectoriesInDomains(
NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = dirPaths[0];
NSString *soundFilePath = [docsDir
stringByAppendingPathComponent:@"myAudio.caf"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
NSDictionary *recordSettings = [NSDictionary
dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:AVAudioQualityMin],
AVEncoderAudioQualityKey,
[NSNumber numberWithInt:16],
AVEncoderBitRateKey,
[NSNumber numberWithInt: 2],
AVNumberOfChannelsKey,
[NSNumber numberWithFloat:44100.0],
AVSampleRateKey,
nil];
NSError *error = nil;
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord
error:nil];
self.audioRecorder = [[AVAudioRecorder alloc]
initWithURL:soundFileURL
settings:recordSettings
error:&error];
if (error)
{
NSLog(@"error: %@", [error localizedDescription]);
} else {
[self.audioRecorder prepareToRecord];
}
}
您需要将音频另存为NSData。您需要将文件保存在磁盘中并转换为NSData 我有一个功能,配置我的音频,一秒钟的功能,使转换
-(void)persistDataAudioPlaylet{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"myAudio.caf"];
NSData *fileContents = [NSData dataWithContentsOfFile:filePath];
self.playlet.sound = fileContents;
}
-(void)configureAudioRecord{
NSArray *dirPaths;
NSString *docsDir;
dirPaths = NSSearchPathForDirectoriesInDomains(
NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = dirPaths[0];
NSString *soundFilePath = [docsDir
stringByAppendingPathComponent:@"myAudio.caf"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
NSDictionary *recordSettings = [NSDictionary
dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:AVAudioQualityMin],
AVEncoderAudioQualityKey,
[NSNumber numberWithInt:16],
AVEncoderBitRateKey,
[NSNumber numberWithInt: 2],
AVNumberOfChannelsKey,
[NSNumber numberWithFloat:44100.0],
AVSampleRateKey,
nil];
NSError *error = nil;
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord
error:nil];
self.audioRecorder = [[AVAudioRecorder alloc]
initWithURL:soundFileURL
settings:recordSettings
error:&error];
if (error)
{
NSLog(@"error: %@", [error localizedDescription]);
} else {
[self.audioRecorder prepareToRecord];
}
}
您需要将音频另存为NSData。您需要将文件保存在磁盘中并转换为NSData 我有一个功能,配置我的音频,一秒钟的功能,使转换
-(void)persistDataAudioPlaylet{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"myAudio.caf"];
NSData *fileContents = [NSData dataWithContentsOfFile:filePath];
self.playlet.sound = fileContents;
}
-(void)configureAudioRecord{
NSArray *dirPaths;
NSString *docsDir;
dirPaths = NSSearchPathForDirectoriesInDomains(
NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = dirPaths[0];
NSString *soundFilePath = [docsDir
stringByAppendingPathComponent:@"myAudio.caf"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
NSDictionary *recordSettings = [NSDictionary
dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:AVAudioQualityMin],
AVEncoderAudioQualityKey,
[NSNumber numberWithInt:16],
AVEncoderBitRateKey,
[NSNumber numberWithInt: 2],
AVNumberOfChannelsKey,
[NSNumber numberWithFloat:44100.0],
AVSampleRateKey,
nil];
NSError *error = nil;
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord
error:nil];
self.audioRecorder = [[AVAudioRecorder alloc]
initWithURL:soundFileURL
settings:recordSettings
error:&error];
if (error)
{
NSLog(@"error: %@", [error localizedDescription]);
} else {
[self.audioRecorder prepareToRecord];
}
}
我认为这是不可能的。如果你看到其他人声称正在这样做,请在他们讨论的地方发布一些URL。谢谢你的回复,Tom。我可能误解了这一点,但这里有一个URL,我认为这是不可能的。如果你看到其他人声称正在这样做,请在他们讨论的地方发布一些URL。谢谢你的回复,Tom。我可能误解了这一点,但这里有一个URL,我认为这是不可能的。如果你看到其他人声称正在这样做,请在他们讨论的地方发布一些URL。谢谢你的回复,Tom。我可能误解了这一点,但这里有一个URL,我认为这是不可能的。如果你看到其他人声称正在这样做,请在他们讨论的地方发布一些URL。谢谢你的回复,Tom。我可能误解了这一点,但这里有一个URL