Skip to Content
iOS 7 Programming Cookbook
book

iOS 7 Programming Cookbook

by Vandad Nahavandipoor
October 2013
Intermediate to advanced
1053 pages
28h 7m
English
O'Reilly Media, Inc.
Content preview from iOS 7 Programming Cookbook

12.3. Recording Audio

Problem

You want to be able to record audio files on an iOS device.

Solution

Use the AVAudioRecorder class in the AV Foundation framework.

Discussion

The AVAudioRecorder class in the AV Foundation framework facilitates audio recording in iOS applications. To start a recording, you need to pass various pieces of information to the initWithURL:settings:error: instance method of AVAudioRecorder:

The URL of the file where the recording should be saved

This is a local URL. The AV Foundation framework will decide which audio format should be used for the recording based on the file extension provided in this URL, so choose the extension carefully.

The settings that must be used before and while recording

Examples include the sampling rate, channels, and other information that will help the audio recorder start the recording. This is a dictionary object.

The address of an instance of NSError where any initialization errors should be saved to

The error information could be valuable later, and you can retrieve it from this instance method in case something goes wrong.

The settings parameter of the initWithURL:settings:error: method is particularly interesting. There are many keys that could be saved in the settings dictionary, but we will discuss only some of the most important ones in this recipe:

AVFormatIDKey

The format of the recorded audio. Some of the values that can be specified for this key are the following:

  • kAudioFormatLinearPCM

  • kAudioFormatAppleLossless

AVSampleRateKey

The ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

iOS 4 Programming Cookbook

iOS 4 Programming Cookbook

Vandad Nahavandipoor
iOS 6 Programming Cookbook

iOS 6 Programming Cookbook

Vandad Nahavandipoor

Publisher Resources

ISBN: 9781449372446Errata Page