Archived
63 lines
2.2 KiB
Python
63 lines
2.2 KiB
Python
from playsound import playsound
|
|
import os
|
|
import random
|
|
import time
|
|
import numpy as np
|
|
import soundfile as sf
|
|
# from expe_options import expe_options
|
|
# from expe_build_conditions import expe_build_conditions
|
|
from tqdm import tqdm
|
|
from to_noise import noise
|
|
|
|
|
|
def main(source):
|
|
'''
|
|
Simply plays the stimulus files in the tmp folders generated either by:
|
|
PyWorld - source is either "python" or "p";
|
|
or Matalb - source is either "matlab" or "m"
|
|
'''
|
|
folder = ''
|
|
if source[0].lower() == "p":
|
|
folder = "/home/nao/Documents/Sam_files/Python_scripts/tmp/"
|
|
elif source[0].lower() == 'm':
|
|
folder = "/home/nao/Documents/Sam_files/Nao-PICKA scripts/Expe_files/tmp/"
|
|
elif source[0].lower() == 'e':
|
|
folder = "/home/nao/Documents/Sam_files/Python_scripts/stimuli/emotion/"
|
|
files = os.listdir(folder)
|
|
y = np.array([])
|
|
|
|
for i in tqdm(range(len(files))):
|
|
if files[i].endswith(".wav"):
|
|
r = random.randint(0, len(files) - 1)
|
|
x, fs = sf.read(os.path.join(folder, str(files[r])))
|
|
# x = x * np.power(10, -(options["attenuation_dB"]/20.0))
|
|
# sf.write("cal_" + str(i) + ".wav", np.concatenate((np.zeros((1024*3, 2)),
|
|
# np.tile(x, (2, 1)).T, np.zeros((1024*3, 2)))), fs)
|
|
# sfile = os.path.join(
|
|
# "/home/nao/Documents/Sam_files/Python_scripts/", "cal_" + str(i) + ".wav")
|
|
|
|
# playsound(sfile)
|
|
# os.remove("cal_" + str(i) + ".wav")
|
|
# time.sleep(0.05)
|
|
y = np.append(y, x)
|
|
y = noise(y, 44100)
|
|
sf.write(
|
|
"calibration_emotion.wav",
|
|
np.concatenate((np.zeros(
|
|
(1024 * 3, 2)), np.tile(y, (2, 1)).T, np.zeros((1024 * 3, 2)))),
|
|
fs)
|
|
sfile = os.path.join("/home/nao/Documents/Sam_files/Python_scripts",
|
|
"calibration_e.wav")
|
|
# playsound(sfile)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
# options = expe_options()
|
|
# expe_build_conditions(options)
|
|
import argparse
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("source", type=str, help="Source for the play files")
|
|
args = parser.parse_args()
|
|
|
|
main(args.source)
|