Skip to content

Commit

Permalink
[TTS] Add format validation
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan <rlangman@nvidia.com>
  • Loading branch information
rlangman committed Jul 26, 2023
1 parent 4f08a6a commit a3c535f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion scripts/dataset_processing/tts/preprocess_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def get_args():
)
parser.add_argument(
"--output_format",
default=".flac",
default="flac",
type=str,
help="If provided, format output audio will be saved as. If not provided, will keep original format.",
)
Expand Down Expand Up @@ -164,6 +164,7 @@ def _process_entry(
if audio.size > 0:
sf.write(file=output_path, data=audio, samplerate=sample_rate)
output_duration = librosa.get_duration(y=audio, sr=sample_rate)
sf.available_formats()
else:
output_duration = 0.0

Expand Down Expand Up @@ -208,6 +209,11 @@ def main():
else:
audio_trimmer = None

if output_format:
if output_format.upper() not in sf.available_formats():
raise ValueError(f"Unsupported output audio format: {output_format}")
output_format = f".{output_format}"

output_audio_dir.mkdir(exist_ok=True, parents=True)

entries = read_manifest(input_manifest_path)
Expand Down

0 comments on commit a3c535f

Please sign in to comment.