I am working in Kaggle notebooks. What I am trying to do is save an audio file dataset to a folder on my present working directory using .save_to_disk
method and then reload it using .file_from_disk
method. However, when I do so, the file path shows just the filename instead of the full path. Since it is just a file name (a string), I am unable to play the audio file. How do I rectify this? Appreciate any inputs on what is wrong here? The code and error message are as follows:
sds
DatasetDict({
train: Dataset({
features: ['audio', 'sentence'],
num_rows: 47
})
test: Dataset({
features: ['audio', 'sentence'],
num_rows: 3
})
})
sds['train'][0]
{'audio': {'path': '/kaggle/working/traindata/f98ef22eeace.mp3',
'array': array([ 0.00000000e+00, -8.73114914e-11, 0.00000000e+00, ...,
-2.53720846e-05, -2.61863424e-05, -2.18840050e-05]),
'sampling_rate': 16000},
'sentence': 'เฆนเง, เฆ เฆฟเฆ เฆเฆเง, เฆฎเงเงเฆพเฆฐ เฆเฆฎเฆฟ เฆเฆพเฆ เฆคเงเฆฎเฆฟ เฆถเงเฆฌเฆพเฆธ เฆจเฆพเฆ, เฆ เฆฟเฆ เฆเฆเง?'}
sds.save_to_disk('/kaggle/working/split_datasets')
os.listdir('/kaggle/working')
['.virtual_documents', 'split_datasets', 'traindata']
split_datasets = load_from_disk('/kaggle/working/split_datasets')
split_datasets
DatasetDict({
train: Dataset({
features: ['audio', 'sentence'],
num_rows: 47
})
validation: Dataset({
features: ['audio', 'sentence'],
num_rows: 3
})
})
split_datasets['train'][0]
{'audio': {'path': 'f98ef22eeace.mp3',
'array': array([ 0.00000000e+00, -8.73114914e-11, 0.00000000e+00, ...,
-2.53720846e-05, -2.61863424e-05, -2.18840050e-05]),
'sampling_rate': 16000},
'sentence': 'เฆนเง, เฆ เฆฟเฆ เฆเฆเง, เฆฎเงเงเฆพเฆฐ เฆเฆฎเฆฟ เฆเฆพเฆ เฆคเงเฆฎเฆฟ เฆถเงเฆฌเฆพเฆธ เฆจเฆพเฆ, เฆ เฆฟเฆ เฆเฆเง?'}
As you see, the file path is just the file name - โpathโ: โf98ef22eeace.mp3โ.
song_sample = random.choice(split_datasets["train"])
print(song_sample)
song_path = song_sample['audio']['path']
print(song_sample['sentence'])
AudioSegment.from_mp3(song_path)
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ in <module>:5 โ
โ โ
โ 2 print(song_sample) โ
โ 3 song_path = song_sample['audio']['path'] โ
โ 4 print(song_sample['sentence']) โ
โ โฑ 5 AudioSegment.from_mp3(song_path) โ
โ 6 โ
โ โ
โ /opt/conda/lib/python3.10/site-packages/pydub/audio_segment.py:796 in from_mp3 โ
โ โ
โ 793 โ โ
โ 794 โ @classmethod โ
โ 795 โ def from_mp3(cls, file, parameters=None): โ
โ โฑ 796 โ โ return cls.from_file(file, 'mp3', parameters=parameters) โ
โ 797 โ โ
โ 798 โ @classmethod โ
โ 799 โ def from_flv(cls, file, parameters=None): โ
โ โ
โ /opt/conda/lib/python3.10/site-packages/pydub/audio_segment.py:651 in from_file โ
โ โ
โ 648 โ โ โ filename = fsdecode(file) โ
โ 649 โ โ except TypeError: โ
โ 650 โ โ โ filename = None โ
โ โฑ 651 โ โ file, close_file = _fd_or_path_or_tempfile(file, 'rb', tempfile=False) โ
โ 652 โ โ โ
โ 653 โ โ if format: โ
โ 654 โ โ โ format = format.lower() โ
โ โ
โ /opt/conda/lib/python3.10/site-packages/pydub/utils.py:60 in _fd_or_path_or_tempfile โ
โ โ
โ 57 โ โ close_fd = True โ
โ 58 โ โ
โ 59 โ if isinstance(fd, basestring): โ
โ โฑ 60 โ โ fd = open(fd, mode=mode) โ
โ 61 โ โ close_fd = True โ
โ 62 โ โ
โ 63 โ try: โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
FileNotFoundError: [Errno 2] No such file or directory: '174010aad27c.mp3'
Hope someone can clarify and provide inputs to resolve the problem.