I have the following functions to read audio files along with their labels using tf.data
def get_waveform(file_path):
audio_binary = tf.io.read_file(file_path)
waveform, sr = tf.audio.decode_wav(contents=audio_binary,
desired_channels=1)
waveform = tf.squeeze(waveform, axis=-1)
frames = tf.signal.frame(waveform, sr * 3, (sr * 3) // 2, pad_end=True)
return frames
def get_label(file_path):
parts = tf.strings.split(
input=file_path,
sep=os.path.sep)
return parts[-2]
def get_waveform_and_label(file_path):
label = get_label(file_path)
waveform = get_waveform(file_path)
label = ???
return waveform, label
The get_waveform function will return N frames of a waveform for a single audio file and all frames will have the same label. So how can I repeat it N times and return it by zipping frames and their corresponding labels?