How to read records terminated by custom separator from file in python?

There is nothing in the Python 2.x file object, or the Python 3.3 io classes, that lets you specify a custom delimiter for readline. (The for line in file is ultimately using the same code as readline.) But it’s pretty easy to build it yourself. For example: def delimited(file, delimiter=”\n”, bufsize=4096): buf=”” while True: newbuf … Read more

How to simulate bit-fields in Delphi records?

Thanks everyone! Based on this information, I reduced this to : RBits = record public BaseMid: BYTE; private Flags: WORD; function GetBits(const aIndex: Integer): Integer; procedure SetBits(const aIndex: Integer; const aValue: Integer); public BaseHi: BYTE; property _Type: Integer index $0005 read GetBits write SetBits; // 5 bits at offset 0 property Dpl: Integer index $0502 … Read more

Detect and record a sound with python

You could try something like this: based on this question/answer # this is the threshold that determines whether or not sound is detected THRESHOLD = 0 #open your audio stream # wait until the sound data breaks some level threshold while True: data = stream.read(chunk) # check level against threshold, you’ll have to write getLevel() … Read more

Android : Record sound in mp3 format

There’s a work around for saving .mp3 files using MediaRecorder. Here’s how: recorder = new MediaRecorder(); recorder.setAudioSource(MediaRecorder.AudioSource.MIC); recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); recorder.setOutputFile(Environment.getExternalStorageDirectory() .getAbsolutePath() + “/myrecording.mp3”); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); recorder.prepare(); recorder.start(); The important part here is the setOuputFormat and the setAudioEncoder. Apparently MediaRecorder records playable mp3 if you’re using MediaRecorder.OutputFormat.MPEG_4 and MediaRecorder.AudioEncoder.AAC together. Hope this helps somebody. Of course, if you’d … Read more

Record audio and save permanently in iOS

Ok I finally solved it. The problem was that I was setting up the AVAudioRecorder and file the path in the viewLoad of my ViewController.m overwriting existing files with the same name. After recording and saving the audio to file and stopping the app, I could find the file in Finder. (/Users/xxxxx/Library/Application Support/iPhone Simulator/6.0/Applications/0F107E80-27E3-4F7C-AB07-9465B575EDAB/Documents/sound1.caf) When … Read more