Created
April 21, 2019 10:11
-
-
Save Romern/9ff892d833249847cc9d6025de46d927 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import soundfile as sf | |
import pyloudnorm as pyln | |
from numpy import inf | |
data, rate = sf.read("example_file.wav") # load audio (with shape (samples, channels)) | |
meter = pyln.Meter(rate) # create BS.1770 meter | |
threshold = -inf | |
loudness = [] | |
currently_quiet = False | |
timestamps = [] | |
timestamps.append(0) | |
for i in range(0, len(data),rate): | |
if ((not currently_quiet) and (meter.integrated_loudness(data[i:i + rate]) <= threshold)) or (currently_quiet and (meter.integrated_loudness(data[i:i + rate]) > threshold)): | |
timestamps.append(i/rate) | |
currently_quiet = not currently_quiet | |
with open('outfile.txt', 'a') as the_file: | |
the_file.write(';FFMETADATA1\n') | |
for i in range(0, len(timestamps)-1): | |
the_file.write('[CHAPTER]\nTIMEBASE=1/1000\nSTART={}\nEND={}\ntitle=Chapter {}\n'.format(int(timestamps[i])*1000,int(timestamps[i+1])*1000,i)) | |
print(timestamps) | |
#;FFMETADATA1 | |
#[CHAPTER] | |
#TIMEBASE=1/1000 | |
#START=0 | |
#END=10000 | |
#title=Chapter 01 | |
#[CHAPTER] | |
#TIMEBASE=1/1000 | |
#START=10000 | |
#END=20000 | |
#title=Chapter 02 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment