ios之使用录音功能和设置音效播放

本文详细介绍了如何在iOS平台上实现录音功能,并通过导入音频工具框架来播放预定义的音效。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

录音 功能的实现(依然需要导入音频工具框架)


    AVAudioSession * session = [[AVAudioSession alloc]init];//创建录音实例
    NSError * error = nil;
    [session setCategory:@"AVAudioSessionCategoryPlayAndRecord" error:&error];
    
    NSString * string = NSHomeDirectory();// 获取Home路径
    
    NSURL * url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/Documents/recordd.caf",string]];// 创建录音文件
    
    recorder = [[AVAudioRecorder alloc]initWithURL:url settings:@{@"AVSampleRateKey": [NSNumber numberWithFloat:44100.0]} error:&error];//配置录音参数
    [recorder prepareToRecord];// 准备录音
    [recorder record];// 开始录音


音效播放  <span style="font-family: Arial, Helvetica, sans-serif;">(依然需要导入音频工具框架)</span>


    SystemSoundID systemSoundID;
    NSURL * url = [[NSBundle mainBundle] URLForAuxiliaryExecutable:@"SystemSound.wav"];//用音效文件创建URL 
    AudioServicesCreateSystemSoundID((CFURLRef)url, &systemSoundID); //创建音效
    AudioServicesPlaySystemSound(systemSoundID);//音效播放


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值