From 2982aaaafd96b34bf58f0adcaab38ce7d9f0ac87 Mon Sep 17 00:00:00 2001 From: Joel Mathew Thomas <90510078+joelmathewthomas@users.noreply.github.com> Date: Tue, 28 Jan 2025 20:33:57 +0530 Subject: [PATCH] add postprocessing package and create module for audio export --- src/postprocessing/__init__.py | 12 ++++++++++++ src/postprocessing/audio_writer.py | 17 +++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/postprocessing/__init__.py create mode 100644 src/postprocessing/audio_writer.py diff --git a/src/postprocessing/__init__.py b/src/postprocessing/__init__.py new file mode 100644 index 0000000..636a4ce --- /dev/null +++ b/src/postprocessing/__init__.py @@ -0,0 +1,12 @@ +# __init__.py + +import logging +from datetime import datetime + +# Configure logging +logging.basicConfig( + format='%(asctime)s : %(message)s', + level = logging.INFO +) + +logging.info("freq-split-enhance/postprocessing package has been imported.") \ No newline at end of file diff --git a/src/postprocessing/audio_writer.py b/src/postprocessing/audio_writer.py new file mode 100644 index 0000000..ba8228c --- /dev/null +++ b/src/postprocessing/audio_writer.py @@ -0,0 +1,17 @@ +import soundfile as sf + +def export_audio(audio, output_path, sr): + """ + Save a NumPy audio array to a specified audio file. + + Args: + audio (numpy.ndarray): The audio data to be saved.` + output_path (str): The path where the audio file should be saved. + sr (int): The sampling rate of the audio. + """ + + try: + sf.write(output_path, audio, sr) + print(f"Audio saved to {output_path}") + except Exception as e: + print(f"Error saving audio: {e}") \ No newline at end of file