Initial setup: added src structure, input functionality, tests, and updated .gitignore
This commit is contained in:
@@ -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}")
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user