O_1001_O 2013-07-02 03:26 采纳率: 0%
浏览 2460

在文档目录下保存wav录音

下面的代码用来保存一个.wav格式的录音文件,然后加到Email中,但是在Email中没有成功邮出。可能是在录音中出了问题,请大家帮忙看一下。

NSArray *pathComponents = [NSArray arrayWithObjects:
                           [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject],
                           @"MyAudioMemo.wav",
                           nil];
NSURL *outputFileURL = [NSURL fileURLWithPathComponents:pathComponents];

// Setup audio session
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryRecord error:nil];

// Define the recorder setting
recordSetting = [[NSMutableDictionary alloc] init];

[recordSetting setValue:[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
[recordSetting setValue:[NSNumber numberWithInt: 16] forKey:AVLinearPCMBitDepthKey];
[recordSetting setValue:[NSNumber numberWithBool: NO] forKey:AVLinearPCMIsBigEndianKey];
[recordSetting setValue:[NSNumber numberWithBool: NO] forKey:AVLinearPCMIsFloatKey];
[recordSetting setValue:[NSNumber numberWithInt: AVAudioQualityHigh] forKey:AVEncoderAudioQualityKey];

// Initiate and prepare the recorder
audioRecorder = [[AVAudioRecorder alloc] initWithURL:outputFileURL settings:recordSetting error:NULL];
audioRecorder.delegate = self;
audioRecorder.meteringEnabled = YES;
[audioRecorder prepareToRecord];
  • 写回答

1条回答 默认 最新

  • prettYYoyic 2013-07-02 06:58
    关注
    - (void)mailPressed {
    
    // recipient address
    
    NSMutableArray *toRecipient = [[NSMutableArray alloc]initWithObjects:@"mail id here ",nil];
    
    MFMailComposeViewController *mailcmp = [[MFMailComposeViewController alloc] init];
    mailcmp.mailComposeDelegate = self;
    
    // attachment
    NSData *data = [NSData dataWithContentsOfFile:[self filePathAudio]];
    
    [mailComposer addAttachmentData:myData mimeType:@"audio/wav" fileName:fileName] //file name is name of youw audio file
    
    // set subject
    [mailcmp setSubject:mailsubject];
    
    // set message
    [mailcmp setMessageBody:msgbody isHTML:NO];
    
    [mailcmp setToRecipients:toRecipient];
    [self presentViewController:mailcmp animated:YES completion:NULL];
    
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件