'/content/drive/MyDrive/School21/day09/datasets/audioyesno/waves_yesno 2'
- User
'/content/drive/MyDrive/School21/day09/datasets/audio_yes_no/waves_yesno 2'
- Assistant
It seems you are trying to access a directory or file path located at "/content/drive/MyDrive/School21/day09/datasets/audio_yes_no/waves_yesno 2". In order to help you, I need to understand if you want to access this location using Python or any other programming language. Please provide more context or information on what you are trying to achieve, and I would be happy to assist you.
- User
import librosa import librosa.display import matplotlib.pyplot as plt import IPython.display as ipd
Загрузите аудиофайл
filename = '/content/drive/MyDrive/School21/day09/datasets/audio_yes_no/waves_yesno 2/0_1_0_1_1_1_0_0.wav' y, sr = librosa.load(filename)
Визуализируйте форму волны
plt.figure(figsize=(12, 4)) librosa.display.waveshow(y, sr=sr) plt.title('Waveform of the audio file') plt.show()
Воспроизвести аудиофайл
ipd.Audio(filename)
- Assistant
It seems you are trying to load an audio file, visualize its waveform, and play the audio content using Python libraries called librosa, matplotlib, and IPython.display. Below is the code provided:
import librosa import librosa.display import matplotlib.pyplot as plt import IPython.display as ipd # Load the audio file filename = '/content/drive/MyDrive/School21/day09/datasets/audio_yes_no/waves_yesno 2/0_1_0_1_1_1_0_0.wav' y, sr = librosa.load(filename) # Visualize the waveform plt.figure(figsize=(12, 4)) librosa.display.waveplot(y, sr=sr) plt.title('Waveform of the audio file') plt.show() # Play the audio file ipd.Audio(filename)Make sure you have the required libraries (librosa, matplotlib, and IPython) installed in your Python environment. You can install them with the following commands:
pip install librosa pip install matplotlib pip install IPythonRun the code in your Python environment or Jupyter Notebook, and it should display the waveform for the given audio file and play the audio using IPython.display.Audio.
- User
import librosa import librosa.display import matplotlib.pyplot as plt import numpy as np
Load the audio file
file_path = '/content/drive/MyDrive/School21/day09/datasets/audio_yes_no/waves_yesno 2/0_1_0_1_1_1_0_0.wav' audio_data, sample_rate = librosa.load(file_path)
Generate the spectrogram
spectrogram = librosa.stft(audio_data) spectrogram_db = librosa.amplitude_to_db(np.abs(spectrogram))
Display the spectrogram
plt.figure(figsize=(10, 4)) librosa.display.specshow(spectrogram_db, sr=sample_rate, x_axis='time', y_axis='hz') plt.colorbar() plt.tight_layout() plt.ylim(0, 4000) plt.show()
- Assistant
The provided code imports the necessary libraries, loads an audio file, and generates its spectrogram using the librosa library. Then, it visualizes the spectrogram using the matplotlib library. Here's the code:
import librosa import librosa.display import matplotlib.pyplot as plt import numpy as np # Load the audio file file_path = '/content/drive/MyDrive/School21/day09/datasets/audio_yes_no/waves_yesno 2/0_1_0_1_1_1_0_0.wav' audio_data, sample_rate = librosa.load(file_path) # Generate the spectrogram spectrogram = librosa.stft(audio_data) spectrogram_db = librosa.amplitude_to_db(np.abs(spectrogram)) # Display the spectrogram plt.figure(figsize=(10, 4)) librosa.display.specshow(spectrogram_db, sr=sample_rate, x_axis='time', y_axis='hz') plt.colorbar() plt.tight_layout() plt.ylim(0, 4000) plt.show()The code visualizes the spectrogram of the audio file by showing the amplitude (in decibels) at different frequency levels over time. To run this code, make sure you have the required libraries (librosa and matplotlib) installed in your Python environment. You can install them with the following commands:
- User
import os from glob import glob import librosa from sklearn.model_selection import train_test_split
def load_dataset(directory: str): sr = None X, labels, files = [], [], [] for f in glob(directory + "/*.wav"): filename = os.path.basename(f) name = filename[:-4] y = [int(label) for label in name.split("_")] x, sr = librosa.load(f) X.append(x) labels.append(y) files.append(filename)
return X, labels, sr, filesdirectory = '/content/drive/MyDrive/School21/day09/datasets/audio_yes_no/waves_yesno 2' X, labels, sample_rate, files = load_dataset(directory)
Split the dataset into train and test parts
X_train, X_test, labels_train, labels_test, files_train, files_test = train_test_split(X, labels, files, test_size=0.2, random_state=42)
Print the number of files in train and test parts
print(f"Number of files in train part: {len(X_train)}") print(f"Number of files in test part: {len(X_test)}")
- Assistant
The provided code defines a function
load_datasetthat takes a directory as an input, where the audio files are located. It loads the audio files with their corresponding labels using the librosa library. Then, it splits the dataset into train and test parts using thetrain_test_splitfunction from the sklearn library.Here's the code:
import os from glob import glob import librosa from sklearn.model_selection import train_test_split def load_dataset(directory: str): sr = None X, labels, files = [], [], [] for f in glob(directory + "/*.wav"): filename = os.path.basename(f) name = filename[:-4] y = [int(label) for label in name.split("_")] x, sr = librosa.load(f) X.append(x) labels.append(y) files.append(filename) return X, labels, sr, files directory = '/content/drive/MyDrive/School21/day09/datasets/audio_yes_no/waves_yesno 2' X, labels, sample_rate, files = load_dataset(directory) # Split the dataset into train and test parts X_train, X_test, labels_train, labels_test, files_train, files_test = train_test_split(X, labels, files, test_size=0.2, random_state=42) # Print the number of files in train and test parts print(f"Number of files in train part: {len(X_train)}") print(f"Number of files in test part: {len(X_test)}")