test_audiodataset / 1.local_files.py
Mike1794's picture
Upload 1.local_files.py
64bed63 verified
raw
history blame contribute delete
No virus
1.69 kB
from datasets import Dataset, Audio
audio_paths = ["Creating_audio_dataset/audios/audio1.wav",
"Creating_audio_dataset/audios/audio2.wav",
"Creating_audio_dataset/audios/audio3.wav"]
transcript_data = ["this law was given to the jews after the like distribution plato who grounds his laws on this division made the fame regulation which had been received as a law by the athenians",
"two praise the lord with harp men need all the help they can get to stir them up to praise this is the lesson to be gathered from the use of musical instruments under the old dispensation israel was at school and used childish things to help her to learn",
"i always expect to discover a secret yet never do still the post haunts me for once boy chickadee kept house there"]
audio_data = {"audio" : audio_paths, "transcript": transcript_data}
# #load the dataset from dict
audio_dataset = Dataset.from_dict(audio_data)
# Cast the "audio" column to Audio feature
audio_dataset = audio_dataset.cast_column("audio", Audio())
# upload the dataset
audio_dataset.push_to_hub("Mike1794/test_audiodataset")
# Access the first element (audio file) in the dataset
first_audio = audio_dataset[0]
# # Get details of the loaded audio
print(f"Audio path: {first_audio['audio']['path']}") # Path to the audio file
print(f"Sampling rate: {first_audio['audio']['sampling_rate']}") # Sampling rate in Hz
print(f"Audio data (first few elements): {first_audio['audio']['array'][:5]}") # Array containing audio samples (float32)
# You can now access and process the audio data for your machine learning tasks.