Skip to content

Instantly share code, notes, and snippets.

@alessaba
Created August 29, 2015 11:07
Show Gist options
  • Save alessaba/8b21ea99721ff2bb3606 to your computer and use it in GitHub Desktop.
Save alessaba/8b21ea99721ff2bb3606 to your computer and use it in GitHub Desktop.
Recorder.py
# coding: utf-8
from objc_util import *
AVAudioSession = ObjCClass('AVAudioSession')
shared_session = AVAudioSession.sharedInstance()
category_set = shared_session.setCategory_error_('AVAudioSessionCategoryPlayAndRecord', None)
settings = ObjCClass('NSMutableDictionary').dictionary()
kAudioFormatMPEG4AAC = 1633772320
settings.setObject_forKey_(kAudioFormatMPEG4AAC,'AVFormatIDKey')
settings.setObject_forKey_(44100.0,'AVSampleRateKey')
settings.setObject_forKey_(2,'AVNumberOfChannelsKey')
output_path = os.path.abspath('Recording.m4a')
out_url = nsurl(output_path)
recorder = ObjCClass('AVAudioRecorder').alloc()
recorder.initWithURL_settings_error_(out_url,settings,None)
started_recording= recorder.record()
if started_recording:
print 'Recording started, press the "stop script" button to end recording...'
try:
while True:
pass
except KeyboardInterrupt:
print 'Stopping...'
recorder.stop()
recorder.release()
print 'Stopped recording.'
import console
console.quicklook(os.path.abspath('Recording.m4a'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment