当我希望用户分享他的语音备忘录时,我正在编写Titanium iPhone应用程序。
有两种选择: (1)记录 - >保存 - >分享 (2)浏览语音备忘录 - >共享
我在这两方面都面临着问题。在(1)中,我设法录制了一个音频并进行播放。但我很困惑如何将这个录制的声音对象转换为文件对象,以便我可以共享该文件。在(2)中,我无法找到以编程方式访问语音备忘录记录的方法。
任何帮助???
答案 0 :(得分:0)
不要回答什么是语音备忘录,但我可以帮助你解决第一个问题:
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *err = nil;
[audioSession setCategory :AVAudioSessionCategoryPlayAndRecord 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:16000.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];
// Create a new dated file
recorderFilePath = [[NSString stringWithFormat:@"%@/Parking.caf", DOCUMENTS_FOLDER] retain];
NSLog(@"recorderFilePath: %@",recorderFilePath);
NSURL *url = [NSURL fileURLWithPath:recorderFilePath];
err = nil;
NSData *audioData = [NSData dataWithContentsOfFile:[url path] options: 0 error:&err];
if(audioData)
{
NSFileManager *fm = [NSFileManager defaultManager];
[fm removeItemAtPath:[url path] error:&err];
}
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];
[alert release];
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];
[cantRecordAlert release];
return;
}
// start recording
[recorder recordForDuration:(NSTimeInterval) 30];
答案 1 :(得分:0)
问题1的解决方案:
您可以直接创建文件对象并在其上写下您记录的数据,
// Save the data to file. Overwrite if fill
var file = Titanium.Filesystem.getFile( 'Your path', 'yourfile.wav' );
// Write the data.
file.write( recordData );
问题2的解决方案: 我不确定Titanium中是否有Voice Memos。
答案 2 :(得分:0)
var file = var file = Titanium.Filesystem.getFile( 'thePath', 'newRecording.wav' );
// Write the data.
file.write( sound.toBlob() );
仍在努力解决第二个问题。任何帮助???