-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcalculate_number_of_sounds.py
28 lines (22 loc) · 1.07 KB
/
calculate_number_of_sounds.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import os.path
from argparse import ArgumentParser
def calculate_sound_files_in_directory(dir_name):
number_of_sound_files = 0
for cur_name in os.listdir(dir_name):
if cur_name in {'.', '..'}:
continue
full_name = os.path.join(dir_name, cur_name)
if os.path.isdir(full_name):
number_of_sound_files += calculate_sound_files_in_directory(full_name)
if cur_name.lower().endswith('.wav'):
number_of_sound_files += 1
return number_of_sound_files
if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument('-s', '--src', dest='source_dir', help='Source directory with sound files in WAVE PCM format.',
required=True)
args = parser.parse_args()
source_dir = os.path.normpath(args.source_dir)
assert os.path.isdir(source_dir), 'Source directory with sound files in WAVE PCM format does not exist!'
n = calculate_sound_files_in_directory(source_dir)
print('Number of WAV PCM files in a specified directory and all its subdirectories is {0}.'.format(n))