Skip to content

Instantly share code, notes, and snippets.

@Dutcho
Forked from omz/Audio Recorder.py
Created December 26, 2015 14:30
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dutcho/030e8cc7ecbcfd0a1e50 to your computer and use it in GitHub Desktop.
Save Dutcho/030e8cc7ecbcfd0a1e50 to your computer and use it in GitHub Desktop.
Audio Recorder.py
# Retrieved from https://gist.githubusercontent.com/omz/9882a00abf59c6009fa4/raw/139afad596c6d46f2f104b16120eefbb36e9960c/Audio%2520Recorder.py on Sat 26-Dec-2015 07:22:53
# Olaf, 26 Dec 2015, updated to use objc_util instead of ctypes; also removed seemingly superfluous AVAudioSession
import objc_util, os
def main():
NSMutableDictionary = objc_util.ObjCClass('NSMutableDictionary')
settings = NSMutableDictionary.dictionary()
kAudioFormatMPEG4AAC = 1633772320
settings.setObject_forKey_(kAudioFormatMPEG4AAC, 'AVFormatIDKey')
settings.setObject_forKey_(44100.0, 'AVSampleRateKey')
settings.setObject_forKey_(2, 'AVNumberOfChannelsKey')
AVAudioRecorder = objc_util.ObjCClass('AVAudioRecorder')
recorder = AVAudioRecorder.alloc()
output_path = os.path.abspath('Recording.m4a')
out_url = objc_util.nsurl(output_path)
recorder = 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'))
if __name__ == '__main__':
main()
@wgaylord
Copy link

This does not seem to work with the latest version of pythonista. It never starts recording. The original one by omz works but.

@jsbain
Copy link

jsbain commented Jun 22, 2016

probably that superflouous audio session!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment