Почему мой код выводит «audio_features пуст. Пропуск подготовки LSTM».Python

Программы на Python
Ответить
Anonymous
 Почему мой код выводит «audio_features пуст. Пропуск подготовки LSTM».

Сообщение Anonymous »

Я пытаюсь импортировать набор данных librispeech в свой код, а затем обучаюсь его использованию, но постоянно получаю:

audio_features пусто . Пропуск подготовки LSTM.

Папки librispeech содержат файлы .txt вверху и файлы .flac внизу. Файлы .txt.
import librosa
import os
import numpy as np

def load_librispeech_dataset(directory):
audio_files = []
labels = []
for root, _, files in os.walk(directory):
for file in files:
if file.endswith('.flac'):
file_path = os.path.join(root, file)
try:
audio, sr = librosa.load(file_path, sr=None)
mfccs = librosa.feature.mfcc(y=audio, sr=sr, n_mfcc=40)
audio_files.append(np.mean(mfccs.T, axis=0))

# Assuming the label (transcription) is in a corresponding text file
label_path = file_path.replace('.flac', '.txt')
with open(label_path, 'r') as label_file:
label = label_file.read().strip()
labels.append(label)
except Exception as e:
print(f"Error processing {file_path}: {e}")

return np.array(audio_files), labels # Indentation corrected: Return after processing all files

dataset_directory = 'C:\\Users\\rowro\\Downloads\\train-clean-100\\LibriSpeech\\train-clean-100'
audio_features, transcriptions = load_librispeech_dataset(dataset_directory)
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, LSTM, Dropout
from tensorflow.keras.utils import to_categorical # Import to_categorical

if audio_features.size == 0:
print("audio_features is empty. Skipping LSTM preparation.")
else:

audio_features = audio_features.reshape(audio_features.shape[0], 1, audio_features.shape[1]) # Reshape for LSTM

vocabulary = sorted(list(set(transcriptions)))

transcription_to_index = {transcription: index for index, transcription in enumerate(vocabulary)}

indexed_transcriptions = [transcription_to_index[transcription] for transcription in transcriptions]

one_hot_transcriptions = to_categorical(indexed_transcriptions, num_classes=len(vocabulary))

dataset = tf.data.Dataset.from_tensor_slices((audio_features, one_hot_transcriptions))

epochs = 50


Подробнее здесь: https://stackoverflow.com/questions/793 ... reparation
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»