Datasets:
Tasks:
Audio Classification
Modalities:
Image
Formats:
imagefolder
Languages:
English
Size:
< 1K
Tags:
SER
Speech Emotion Recognition
Speech Emotion Classification
Audio Classification
Audio
Emotion
License:
Upload parquet2csv_wav.py
Browse files- parquet2csv_wav.py +18 -1
parquet2csv_wav.py
CHANGED
@@ -10,29 +10,46 @@ import numpy as np
|
|
10 |
from scipy.io.wavfile import write
|
11 |
|
12 |
import os
|
|
|
|
|
13 |
n_cores = str(os.cpu_count())
|
14 |
os.environ['OMP_NUM_THREADS'] = n_cores
|
15 |
os.environ['MKL_NUM_THREADS'] = n_cores
|
16 |
|
|
|
17 |
if not os.path.isdir('wavs'):
|
18 |
os.makedirs('wavs')
|
19 |
|
|
|
20 |
columns = ['ytid', 'ytid_seg', 'start', 'end', 'sentiment', 'happiness', 'sadness', 'anger', 'fear', 'disgust', 'surprise']
|
21 |
|
|
|
|
|
|
|
|
|
|
|
22 |
df = pl.read_parquet('sqe_messai.parquet', columns = columns)
|
23 |
|
|
|
24 |
df.write_csv('sqe_messai_nowav.csv')
|
25 |
-
|
26 |
print(df)
|
27 |
|
|
|
28 |
columns2 = ['ytid_seg', 'wav2numpy']
|
29 |
|
|
|
30 |
df2 = pl.read_parquet('sqe_messai.parquet', use_pyarrow=False, columns = columns2)
|
31 |
|
|
|
|
|
|
|
|
|
|
|
32 |
def numpy2wav(row):
|
33 |
segment = os.path.splitext(os.path.basename(os.path.normpath(row[0])))[0]
|
34 |
print('PROCESSED:', segment)
|
35 |
write('wavs/' + segment + '.wav', 16000, np.array(row[1]))
|
36 |
return segment
|
37 |
|
|
|
38 |
df2.apply(lambda x: numpy2wav(x))
|
|
|
10 |
from scipy.io.wavfile import write
|
11 |
|
12 |
import os
|
13 |
+
# User all available cores
|
14 |
+
# It seems useless in the context of this script
|
15 |
n_cores = str(os.cpu_count())
|
16 |
os.environ['OMP_NUM_THREADS'] = n_cores
|
17 |
os.environ['MKL_NUM_THREADS'] = n_cores
|
18 |
|
19 |
+
# Create the wavs dir if it does not exist
|
20 |
if not os.path.isdir('wavs'):
|
21 |
os.makedirs('wavs')
|
22 |
|
23 |
+
# All columns from the parquet file except the one with the audio numpy arrays (it is huge)
|
24 |
columns = ['ytid', 'ytid_seg', 'start', 'end', 'sentiment', 'happiness', 'sadness', 'anger', 'fear', 'disgust', 'surprise']
|
25 |
|
26 |
+
### Add replace line here to change the paths from the ytid_seg column ###
|
27 |
+
# https://pola-rs.github.io/polars/py-polars/html/reference/expressions/api/polars.Expr.str.replace.html
|
28 |
+
# replace the subtring '/home/emoman/Downloads/mosei/samples' with the actual path
|
29 |
+
|
30 |
+
# Read the parquet file with polars
|
31 |
df = pl.read_parquet('sqe_messai.parquet', columns = columns)
|
32 |
|
33 |
+
# Export the csv file (excluding the last column)
|
34 |
df.write_csv('sqe_messai_nowav.csv')
|
|
|
35 |
print(df)
|
36 |
|
37 |
+
# Now we are only interested on the column with the paths and the audio numpy arrays
|
38 |
columns2 = ['ytid_seg', 'wav2numpy']
|
39 |
|
40 |
+
# Read the parquet file with polars (this will take a while)
|
41 |
df2 = pl.read_parquet('sqe_messai.parquet', use_pyarrow=False, columns = columns2)
|
42 |
|
43 |
+
### Add replace line here to change the paths from the ytid_seg column ###
|
44 |
+
# https://pola-rs.github.io/polars/py-polars/html/reference/expressions/api/polars.Expr.str.replace.html
|
45 |
+
# replace the subtring '/home/emoman/Downloads/mosei/samples' with the actual path
|
46 |
+
|
47 |
+
# Function to convert the numpy arrays to wav files stored in the wavs folders
|
48 |
def numpy2wav(row):
|
49 |
segment = os.path.splitext(os.path.basename(os.path.normpath(row[0])))[0]
|
50 |
print('PROCESSED:', segment)
|
51 |
write('wavs/' + segment + '.wav', 16000, np.array(row[1]))
|
52 |
return segment
|
53 |
|
54 |
+
# Apply the function (this will take a while)
|
55 |
df2.apply(lambda x: numpy2wav(x))
|