Skip to content

Commit

Permalink
have a warning when not able to read sample rate rather than code fai…
Browse files Browse the repository at this point in the history
…lure
  • Loading branch information
LoannPeurey committed Oct 31, 2023
1 parent 23abaf1 commit ad1be77
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions ChildProject/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,18 +522,29 @@ def validate(self, ignore_recordings: bool = False, profile: str = None, accumul
if os.path.exists(path):
if not profile:
info = mediainfo(path)
if int(info['sample_rate']) != STANDARD_SAMPLE_RATE:
if 'sample_rate' not in info or int(info['sample_rate']) != STANDARD_SAMPLE_RATE:
try:
std_path = self.get_recording_path(raw_filename, STANDARD_PROFILE)
if os.path.exists(std_path):
std_info = mediainfo(std_path)
if 'sample_rate' in std_info and int(std_info['sample_rate']) != STANDARD_SAMPLE_RATE:
if 'sample_rate' not in std_info:
self.warnings.append(
f"Could not read the sample rate of converted version of recording '{raw_filename}' at '{std_path}'. {STANDARD_SAMPLE_RATE}Hz is expected for profile {STANDARD_PROFILE}")
elif int(std_info['sample_rate']) != STANDARD_SAMPLE_RATE:
self.warnings.append(f"converted version of recording '{raw_filename}' at '{std_path}' has unexpected sampling rate {std_info['sample_rate']}Hz when {STANDARD_SAMPLE_RATE}Hz is expected for profile {STANDARD_PROFILE}")
else:
self.warnings.append(f"recording '{raw_filename}' at '{path}' has a non standard sampling rate {info['sample_rate']}Hz and no converted version found in the standard profile at {std_path}. The file content may not be downloaded. you can create the missing standard converted audios with 'child-project process {self.path} {STANDARD_PROFILE} basic --format=wav --sampling={STANDARD_SAMPLE_RATE} --codec=pcm_s16le --skip-existing'")
if 'sample_rate' in info:
self.warnings.append(
f"recording '{raw_filename}' at '{path}' has a non standard sampling rate of {info['sample_rate']}Hz and no standard conversion in profile {STANDARD_PROFILE} was found. Does the standard profile exist? Does {profile_metadata} exist? you can create the standard profile with 'child-project process {self.path} {STANDARD_PROFILE} basic --format=wav --sampling={STANDARD_SAMPLE_RATE} --codec=pcm_s16le --skip-existing'")
else:
self.warnings.append(
f"Could not read the sample rate of recording '{raw_filename}' at '{path}' and no standard conversion in profile {STANDARD_PROFILE} was found. Does the standard profile exist? Does {profile_metadata} exist? you can create the standard profile with 'child-project process {self.path} {STANDARD_PROFILE} basic --format=wav --sampling={STANDARD_SAMPLE_RATE} --codec=pcm_s16le --skip-existing'")
except:
profile_metadata = os.path.join(self.path,CONVERTED_RECORDINGS,STANDARD_PROFILE,RECORDINGS_CSV,)
self.warnings.append(f"recording '{raw_filename}' at '{path}' has a non standard sampling rate of {info['sample_rate']}Hz and no standard conversion in profile {STANDARD_PROFILE} was found. Does the standard profile exist? Does {profile_metadata} exist? you can create the standard profile with 'child-project process {self.path} {STANDARD_PROFILE} basic --format=wav --sampling={STANDARD_SAMPLE_RATE} --codec=pcm_s16le --skip-existing'")
if 'sample_rate' in info:
self.warnings.append(f"recording '{raw_filename}' at '{path}' has a non standard sampling rate of {info['sample_rate']}Hz and no standard conversion in profile {STANDARD_PROFILE} was found. Does the standard profile exist? Does {profile_metadata} exist? you can create the standard profile with 'child-project process {self.path} {STANDARD_PROFILE} basic --format=wav --sampling={STANDARD_SAMPLE_RATE} --codec=pcm_s16le --skip-existing'")
else:
self.warnings.append(f"Could not read the sample rate of recording '{raw_filename}' at '{path}' and no standard conversion in profile {STANDARD_PROFILE} was found. Does the standard profile exist? Does {profile_metadata} exist? you can create the standard profile with 'child-project process {self.path} {STANDARD_PROFILE} basic --format=wav --sampling={STANDARD_SAMPLE_RATE} --codec=pcm_s16le --skip-existing'")
elif profile == STANDARD_PROFILE:
info = mediainfo(path)
if 'sample_rate' in info and int(info['sample_rate']) != STANDARD_SAMPLE_RATE:
Expand Down

0 comments on commit ad1be77

Please sign in to comment.