Пример #1
0
def gen_audio_stim(MatrixDir, OutDir, indexes):
    if os.path.exists(OutDir):
        shutil.rmtree(OutDir)
        os.makedirs(OutDir)
    wavFiles = globDir(MatrixDir, '*.wav')
    wavFileMatrix = organiseWavs(wavFiles)
    wavDir = os.path.join(OutDir, "wav")
    dir_must_exist(wavDir)
    wavDir = os.path.join(wavDir, "noise-sentences")
    dir_must_exist(wavDir)
    files = []
    n = 0
    o = 0
    for sentenceList in indexes:
        n += 1
        o = 0
        files.append([])
        for ind in sentenceList:
            o += 1
            y, wavInfo, partnames = synthesize_trial(wavFileMatrix, ind)
            fileName = os.path.join(wavDir,
                                    'Trial_{0:02d}_{1:02d}.wav'.format(n, o))
            print("Generating: " + fileName)
            sndio.write(fileName, y, **wavInfo)
            files[-1].append(fileName)

    return files
Пример #2
0
def generateAudioStimulus(MatrixDir, OutDir, Length, indexes, socketio=None):
    # Get matrix wav file paths
    wavFiles = globDir(MatrixDir, '*.wav')
    wavFileMatrix = organiseWavs(wavFiles)
    with open(os.path.join(OutDir, 'stim_parts.csv'), 'w') as csvfile:
        partwriter = csv.writer(csvfile)
        # Synthesize audio for each trial using generated word choices
        l = 0
        n = 0
        files = []
        while l < Length:
            if socketio:
                percent = (l / Length) * 100.
                socketio.emit('update-progress',
                              {'data': '{}%'.format(percent)},
                              namespace='/main')
            #print("Generating Trial_{0:05d}".format(n))
            y, wavInfo, partnames = synthesizeTrial(wavFileMatrix,
                                                    indexes[n, :])
            partwriter.writerow(partnames)
            fileName = os.path.join(OutDir, 'Trial_{0:05d}.wav'.format(n))
            pysndfile.sndio.write(fileName, y, **wavInfo)
            n += 1
            l += y.size / wavInfo['rate']
            files.append(fileName)
    return files
Пример #3
0
def generate_audio_stimulus(MatrixDir, OutDir, indexes, socketio=None):
    # Get matrix wav file paths
    wavFiles = globDir(MatrixDir, '*.wav')
    wavFileMatrix = organiseWavs(wavFiles)

    wav_dir = os.path.join(args['OutDir'], "wav")
    dir_must_exist(wav_dir)
    sentence_dir = os.path.join(wav_dir, "sentence-lists")
    dir_must_exist(sentence_dir)
    # Synthesize audio for each trial using generated word choices
    sentence_lists = {}
    for key in indexes.keys():
        files = []
        list_dir = os.path.join(sentence_dir, key)
        dir_must_exist(list_dir)
        with open(os.path.join(list_dir, 'stim_parts.csv'), 'w') as csvfile:
            partwriter = csv.writer(csvfile)
            inds, strings = indexes[key]
            for sentence_ind, (component_inds, component_strings) in enumerate(
                    zip(inds, strings)):
                if socketio:
                    percent = (l / Length) * 100.
                    socketio.emit('update-progress',
                                  {'data': '{}%'.format(percent)},
                                  namespace='/main')
                y, wavInfo, partnames = synthesize_trial(
                    wavFileMatrix, component_inds)
                partwriter.writerow(component_strings)
                file_name = os.path.join(
                    list_dir, 'Trial_{0:05d}.wav'.format(sentence_ind + 1))
                sndio.write(file_name, y, **wavInfo)
                files.append(file_name)

            sentence_lists[key] = np.array(files)
    return sentence_lists
Пример #4
0
def gen2(MatrixDir, OutDir, indexes):
    wavFiles = globDir(MatrixDir, '*.wav')
    wavFileMatrix = organiseWavs(wavFiles)
    files = []
    for sentenceList in indexes:
        for ind in sentenceList:
            y, wavInfo, partnames = synthesizeTrial(wavFileMatrix, ind)