Я пытаюсь импортировать набор данных 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
Почему мой код выводит «audio_features пуст. Пропуск подготовки LSTM». ⇐ Python
Программы на Python
1735405592
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
Подробнее здесь: [url]https://stackoverflow.com/questions/79314222/why-is-my-code-outputting-audio-features-is-empty-skipping-lstm-preparation[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия