Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion klaam/utils/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import librosa
import torch
import numpy as np

from klaam.external.FastSpeech2.buckwalter import bw2ar

Expand All @@ -8,7 +9,15 @@

def load_file_to_data(file, srate=16_000):
batch = {}
speech, sampling_rate = librosa.load(file, sr=srate)

if isinstance(file, str): # If it's a file path
speech, sampling_rate = librosa.load(file, sr=srate)
elif isinstance(file, np.ndarray): # If it's a NumPy array
speech = file
sampling_rate = srate
else:
raise TypeError(f"Unsupported input type: {type(file)}. Expected str (file path) or np.ndarray.")

batch["speech"] = speech
batch["sampling_rate"] = sampling_rate
return batch
Expand Down