Initial setup: added src structure, input functionality, tests, and updated .gitignore

This commit is contained in:
Joel Mathew Thomas
2024-12-24 17:52:27 +05:30
parent 17f929e504
commit 919a798437
8 changed files with 91 additions and 1 deletions
+21
View File
@@ -0,0 +1,21 @@
import os
import librosa
def read_audio(file_path):
"""
Reads an audio file and returns the audio time series and sampling rate.
Args:
file_path (str): Path to the audio file.
Returns:
tuple: audio_time_series (numpy.ndarray), sampling_rate (int)
"""
if not os.path.exists(file_path):
raise FileNotFoundError(f"File not found: {file_path}")
try:
audio, sr = librosa.load(file_path, sr=None) # Load with original sampling rate.
return audio, sr
except Exception as e:
raise RuntimeError(f"Error reading the audio file: {e}")
+15
View File
@@ -0,0 +1,15 @@
import mimetypes
def is_supported_format(file_path):
"""
Checks if the audio file is in a supported format.
Args:
file_path (str): Path to the audio file.
Returns:
bool: True if supported, False otherwise.
"""
supported_formats = ["audio/mpeg", "audio/wav", "audio/x-aiff", "audio/x-wav", ...]
mime_type, _ = mimetypes.guess_type(file_path)
return mime_type in supported_formats