This repository has been archived on 2026-10-21. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
PICKA_python/fishy/preprocess.py
T
2026-09-22 11:52:03 +02:00

47 lines
1.5 KiB
Python

import os
import soundfile as sf
import pyworld as pw
import numpy as np
import scipy.io as spio
from expe_options import expe_options
from expe_build_conditions import expe_build_conditions
def preprocess(language):
options = {}
options["language"] = language
options["subject_name"] = ''
options = expe_options(options)
_, options = expe_build_conditions(options)
for i in range(len(options["syllables"])):
syll = options["syllables"][i]
print "%02d/%02d - %s\n" % (i, len(options["syllables"]), syll)
wavIn = os.path.join(options["sound_path"], syll + ".wav")
mat = os.path.join(options["sound_path_store"], syll + '.pyworld.mat')
if not os.path.exists(mat):
x, fs = sf.read(wavIn)
_f0, t = pw.dio(x, fs)
f0 = pw.stonemask(x, _f0, t, fs)
sp = pw.cheaptrick(x, f0, t, fs)
ap = pw.d4c(x, f0, t, fs)
freq = np.arange(0, np.size(sp, axis=1),
dtype='float64') / (np.size(sp)) * fs/2
temp_pos = t
x_rms = np.sqrt(np.mean(x**2))
duration = len(x/fs)
spio.savemat(mat, mdict={'fs': fs, 'f0': f0,
'sp': sp, 'ap': ap,
'x_rms': x_rms,
'frequencies': freq,
'temporal_positions': t,
'duration': duration
})