diff --git a/README.md b/README.md index 8a31aea..217e7ad 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ Recording settings that can be specified in the config file: ### 10. Termination The program clean-exits at any time using the 'q' key. Lowercase only right now, lol. It will execute the rest of the main control loop, skipping recording loops, close all streams and files, stop recording, still check for silence and delete if silent. -ONE CAVEAT: If the program is closed or terminated, unexpectedly or not, during the padding interval after a silent recording that was deleted, anything recorded during that padding will NOT be saved. This could be solved by writing to a temp file and deleting it at the top of loop. +ONE CAVEAT: If the program is closed or terminated, unexpectedly or not, during the padding interval after a silent recording that was deleted, anything recorded during that padding will be saved in `temp.wav`. Basically, whenever the program says "DELETED: filename.wav, still recording padding..." it writes to `temp.wav` until the next file starts, then deletes it since it's saved in the new file. `temp.wav` only exists to save this bit of audio in case the program terminates. ### Extraneous Info diff --git a/config.ini b/config.ini deleted file mode 100644 index 50daf7c..0000000 --- a/config.ini +++ /dev/null @@ -1,14 +0,0 @@ -[FILE] -maxfiles = 200 -waveoutputfilename = wcfm -deleteold = False -recordmin = 60 -padmin = 5 - -[RECORD] -rate = 44100 -format = 8 -chunk = 1024 -channels = 2 -threshold = 333 - diff --git a/dist/wcfmarchiver.exe b/dist/wcfmarchiver.exe index 62ceea7..4daa8d8 100644 Binary files a/dist/wcfmarchiver.exe and b/dist/wcfmarchiver.exe differ diff --git a/doc/devnotes.txt b/doc/devnotes.txt index 46210bd..1491579 100644 --- a/doc/devnotes.txt +++ b/doc/devnotes.txt @@ -2,6 +2,4 @@ Ideas: Specify max files and max size on disk? Or max amount of time, and use some math to get #files or size on disk. -Lowercase and uppercase q to quit - -If the program is closed or terminated, unexpectedly or not, during the padding interval after a silent recording that was deleted, anything recorded during that padding will NOT be saved. This could be solved by writing to a temp file and deleting it at the top of loop. \ No newline at end of file +Lowercase and uppercase q to quit \ No newline at end of file diff --git a/wcfmarchiver.py b/wcfmarchiver.py index f1c87b4..9ead23d 100644 --- a/wcfmarchiver.py +++ b/wcfmarchiver.py @@ -44,8 +44,8 @@ # Parse config.ini for configuration settings if (os.path.isfile("config.ini")): config.read("config.ini") -RECORD_MIN = int(config['FILE']['RecordMin']) -PAD_MIN = int(config['FILE']['PadMin']) +RECORD_MIN = float(config['FILE']['RecordMin']) +PAD_MIN = float(config['FILE']['PadMin']) WAVE_OUTPUT_FILENAME = config['FILE']['WaveOutputFilename'] MAX_FILES = int(config['FILE']['MaxFiles']) DELETE_OLD = config['FILE'].getboolean('DeleteOld') @@ -138,6 +138,10 @@ def quitPressed(): os.remove(toDelete) output("* DELETED: \t\t" + toDelete) + # delete temp file + if (os.path.isfile("archives/temp.wav")): + os.remove("archives/temp.wav") + # open file output("* now writing to: \tarchives/" + fileName) wf = wave.open("archives/" + fileName, 'wb') @@ -169,23 +173,31 @@ def quitPressed(): fileNames.pop(len(fileNames)-1) output("* DELETED SILENCE: \tarchives/"+fileName) - #record padding for next file + #record padding to temp and for next file + wf = wave.open("archives/temp.wav", 'wb') + wf.setnchannels(CHANNELS) + wf.setsampwidth(p.get_sample_size(FORMAT)) + wf.setframerate(RATE) output("* still recording padding...") framesOverlap = [] while (not quitPressed() and int(time.time())%RECORD_SECONDS != PAD_SEC): data = stream.read(CHUNK) + frame.append(data) + wf.writeframes(b''.join(frame)) + frame = [] framesOverlap.append(data) + wf.close() # no silence detected else: # write +/-5 min at bottom of hour, and record into framesOverlap framesOverlap = [] while (not quitPressed() and int(time.time())%RECORD_SECONDS != PAD_SEC): - data = stream.read(CHUNK) - frame.append(data) - wf.writeframes(b''.join(frame)) - frame = [] - framesOverlap.append(data) + data = stream.read(CHUNK) + frame.append(data) + wf.writeframes(b''.join(frame)) + frame = [] + framesOverlap.append(data) # close audio file wf.close()