Update audioset.py
Browse files- audioset.py +7 -1
audioset.py
CHANGED
|
@@ -15,6 +15,7 @@ import textwrap
|
|
| 15 |
import datasets
|
| 16 |
import requests
|
| 17 |
import itertools
|
|
|
|
| 18 |
import typing as tp
|
| 19 |
import pandas as pd
|
| 20 |
from pathlib import Path
|
|
@@ -108,7 +109,7 @@ class AudioSet(datasets.GeneratorBasedBuilder):
|
|
| 108 |
"To use AudioSet you have to download it manually. "
|
| 109 |
"Please download the dataset from https://huggingface.co/datasets/confit/audioset-full \n"
|
| 110 |
"Then extract all files in one folder called `audios` and load the dataset with: "
|
| 111 |
-
"`datasets.load_dataset('confit/audioset', '
|
| 112 |
"The tree structure of the downloaded data looks like: \n"
|
| 113 |
f"{DATA_DIR_STRUCTURE}"
|
| 114 |
)
|
|
@@ -164,12 +165,17 @@ class AudioSet(datasets.GeneratorBasedBuilder):
|
|
| 164 |
fileid = Path(wav_path).name
|
| 165 |
sound = fileid2labels.get(fileid)
|
| 166 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
yield guid, {
|
| 168 |
"id": str(guid),
|
| 169 |
"file": wav_path,
|
| 170 |
"audio": wav_path,
|
| 171 |
"sound": sound,
|
| 172 |
"label": sound,
|
|
|
|
| 173 |
}
|
| 174 |
except:
|
| 175 |
continue
|
|
|
|
| 15 |
import datasets
|
| 16 |
import requests
|
| 17 |
import itertools
|
| 18 |
+
import torchaudio
|
| 19 |
import typing as tp
|
| 20 |
import pandas as pd
|
| 21 |
from pathlib import Path
|
|
|
|
| 109 |
"To use AudioSet you have to download it manually. "
|
| 110 |
"Please download the dataset from https://huggingface.co/datasets/confit/audioset-full \n"
|
| 111 |
"Then extract all files in one folder called `audios` and load the dataset with: "
|
| 112 |
+
"`datasets.load_dataset('confit/audioset', '20k', data_dir='path/to/folder/audios')`\n"
|
| 113 |
"The tree structure of the downloaded data looks like: \n"
|
| 114 |
f"{DATA_DIR_STRUCTURE}"
|
| 115 |
)
|
|
|
|
| 165 |
fileid = Path(wav_path).name
|
| 166 |
sound = fileid2labels.get(fileid)
|
| 167 |
try:
|
| 168 |
+
metadata = torchaudio.info(wav_path)
|
| 169 |
+
duration = math.ceil(metadata.num_frames / metadata.sample_rate) # in seconds
|
| 170 |
+
if not (duration > 0):
|
| 171 |
+
continue
|
| 172 |
yield guid, {
|
| 173 |
"id": str(guid),
|
| 174 |
"file": wav_path,
|
| 175 |
"audio": wav_path,
|
| 176 |
"sound": sound,
|
| 177 |
"label": sound,
|
| 178 |
+
"duration": duration
|
| 179 |
}
|
| 180 |
except:
|
| 181 |
continue
|