Latest 1.0.2
License LGPLv3
Platforms ios 5.0, requires ARC
Dependencies PYCore
Frameworks AVFoundation

A simple audio recorder and player for iOS.

This is a CocoaPods project.


The player support both HLS audio and local file audio.
Usually, we just need to invoke [_player playUrl:[NSURL URLWithString:@"..."] to play a specified audio stream.
For an http live stream(HLS), the player will use AVPlayer and AVPlayerItem to load audio data and play it. It will check the status of the item use KVO.
For a local audio file, the player will use AVAudioPlayer to play, which is very simple.

We can use [prepareUrl:seekFrom:autoPlay:] and set autoPlay to NO to load the stream buffer only and not start the audio session.
Or we can set the seekFrom to tell the player to start play at specified position of the audio stream.

The HLS player will check the buffer status and will automatically recover from a network broken.


The recorder use AudioQueueRef to record. The audio format and the file format should be set at initialization.
When enabled the meter fetching, the recorder will invoke the delegate 60 times per second, and return the first channel’s audio weight.
You can use [startToGatherEnvorinmentSound] and [startMeterFetching] to build a dynamic graph for background envorinment.


  1. Create ‘Podfile’ or modify the file under the root path of your Xcode project
  2. Add the following line before end

    pod "PYAudioKit", "~> 0.3"

  3. Run pod install or pod update to get the source code
  4. open *.xcworkspcae


#import <PYAudioKit/PYAudioKit.h>

@interface MyViewController {
    PYAudioPlayer         *_audioPlayer;
    PYAudioRecorder       *_audioRecorder;
    UIButton              *_recordBtn;

@implementation MyViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    // Initialize the player and recorder
    _recordBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_recordBtn setBackgroundColor:[UIColor blueColor]];
    [_recordBtn setFrame:CGRectMake(80, 80, 160, 88)];
    [_recordBtn addTarget:self action:@selector(actionTouchDown:)
    [_recordBtn addTarget:self action:@selector(actionTouchUpInside:)
    [self.view addSubView:_recordBtn];

- (void)actionTouchDown:(id)sender {
    // the recorder use m4a format, default with 2 channels, 8000 sample rate
    _audioRecorder = [PYAudioRecorder 
    [_audioRecorder startToRecord];

- (void)actionTouchUpInside:(id)sender {
    if ( _audioRecorder == nil ) return;
    NSString *_savedAudioPath = [_audioRecorder stopRecordAndSaveWithFileName:@"example.m4a"];

    // Play the audio
    _audioPlayer = [PYAudioPlayer object];
    [_audioPlayer playUrl:[NSURL fileURLWithPath:_savedAudioPath]];


Latest podspec

    "name": "PYAudioKit",
    "version": "1.0.2",
    "summary": "A simple audio recorder and player for iOS.",
    "homepage": "",
    "license": {
        "type": "LGPLv3",
        "file": "LICENSE"
    "authors": {
        "Push Chen": "[email protected]"
    "platforms": {
        "ios": "5.0"
    "source": {
        "git": "",
        "tag": "1.0.2"
    "source_files": [
    "frameworks": "AVFoundation",
    "requires_arc": true,
    "dependencies": {
        "PYCore": []

Pin It on Pinterest

Share This