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 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题