def record_vt_sound(art,time, fs = 11025):
    diva_synth = Divapy()
    n_arts = round((time/0.005))+1
    arts = np.tile(art, (int(n_arts), 1))
    sound = diva_synth.get_sound(arts)
    scaled = np.int16(sound / np.max(np.abs(sound)) * 32767)
    wavfile.write("vt" + '.wav', 11025, scaled)
    diva_synth.play_sound(sound)
def create_german_files(german_art, time, fs=11025):
    diva_synth = Divapy()
    n_arts = round((time/0.005))+1
    vow_names = ['-E', '-E_', '-I', '-O', '-U', '-Y', '-Z_', '-a', '-a_', '-at', '-b', '-e_', '-i_', '-o_', '-p', '-u_', '-y']
    for i in range(len(german_art[:, 0])):
        german_vowels = german_art[i, :]
        german_vowels = np.tile(german_vowels, (int(n_arts), 1))
        german_sound = diva_synth.get_sound(german_vowels)
        scaled = np.int16(german_sound / np.max(np.abs(german_sound)) * 32767)
        wavfile.write("vt" + vow_names[i] + '.wav', fs, scaled)
# matplotlib.rcParams['ytick.major.pad'] = 8

class Articulation(object):
    def __init__(self, **kargs):
        default_params_ = {'x0': np.array([0.0] * 13),
                          'xp0': np.array([0.0] * 13), 'm': np.array([0.0] * 13),
                          'w0': 2 * np.pi / 0.4, 'damping_factor': 1.01, 'D_t': 0.4}
        self.params = default_params_
        for key in kargs.keys():
            self.params[key] = kargs[key]

    def defaul(self):
        # params = {'x0': 0.0, 'm': np.array([0.0] * 13),'w0': 2 * np.pi / 0.4, 'damping_factor':1.01, 'D_t': 0.4}
        self.params = default_params

sys = Diva()
sys.af_play = np.array([0.]*5)
sys.outline_play = [np.array([0.]*5)]*5
sys.articulations = []
sys.articulatory_x0 = np.zeros((13,))
sys.articulatory_xp0 = np.zeros((13,))

m = []
for i in range(10):
    m += [widgets.FloatSlider(value=0, min=-3., max=3.,
                              step=0.01,
                              disabled=False,
                              continuous_update=False,
                              description='M' + str(i),
                              orientation='vertical',
                              readout=True,
Exemple #4
0
import h5py, time
import numpy as np
import matplotlib.pyplot as plt
from divapy import Diva as Divapy
from divaml import Diva as Divaml


def h5_to_ndarray(key_, file_name):
    with h5py.File(file_name, 'r') as hf:
        data = hf[key_][:]
    return data


if __name__ == '__main__':
    diva_synth = Divapy()
    diva_synth_ml = Divaml()

    art = [
        -2.82586455, 0.6511439, 0.41705491, -0.16636287, 1.52612695,
        -0.65089551, 2.71660497, -2.8833028, -1.46663703, -2.10624563,
        0.21783021, 0.74918289, 0.48187699
    ]

    art = h5_to_ndarray('arts', '../data/hard_arts.h5')

    # art = [0.1]*10 + [1]*3

    # Using get_sample
    aud, som, outline, af, d = diva_synth.get_sample(np.array(art[0, :]))
    print(aud)
Exemple #5
0
def get_random_motor_set(system, n_samples):
    n_motor = system.n_motor
    raw_rnd_data = np.random.random((n_samples, n_motor))
    min_values = system.min_motor_values
    max_values = system.max_motor_values

    min_values = np.array(n_samples * [np.array(min_values)])
    max_values = np.array(n_samples * [np.array(max_values)])

    motor_commands = min_values + raw_rnd_data * (max_values - min_values)

    return motor_commands


pydiva_synth = PyDiva()
mldiva_synth = MlDiva()

n_static_test = 100
n_static_sound_test = 100
n_random_sound_test = 100

static_test = True
static_sound_test = True
random_sound_test = True

if __name__ == '__main__':
    static_commands = get_random_motor_set(mldiva_synth, n_static_test)

    print("Validating with static samples...")
    for i in range(n_static_test):
Exemple #6
0
def get_random_motor_set(system, n_samples):
    n_motor = system.n_motor
    raw_rnd_data = np.random.random((n_samples, n_motor))
    min_values = system.min_motor_values
    max_values = system.max_motor_values

    min_values = np.array(n_samples * [np.array(min_values)])
    max_values = np.array(n_samples * [np.array(max_values)])

    motor_commands = min_values + raw_rnd_data * (max_values - min_values)

    return motor_commands


pydiva_synth1 = PyDiva()
pydiva_synth2 = PyDiva()
mldiva_synth = MlDiva()

n_static_sound_test = 100

static_sound_test = True

if __name__ == '__main__':

    static_commands = get_random_motor_set(mldiva_synth, n_static_sound_test)
    print("Evaluating performance with with static sound samples...")

    t = time.time()
    for i in range(n_static_sound_test):
        m_tmp = static_commands[i, :]
Exemple #7
0
def get_random_motor_set(system, n_samples):
    n_motor = system.n_motor
    raw_rnd_data = np.random.random((n_samples, n_motor))
    min_values = system.min_motor_values
    max_values = system.max_motor_values

    min_values = np.array(n_samples * [np.array(min_values)])
    max_values = np.array(n_samples * [np.array(max_values)])

    motor_commands = min_values + raw_rnd_data * (max_values - min_values)

    return motor_commands


pydiva_synth = PyDiva()
mldiva_synth = PyDiva()

foo = MlDiva()

n_static_test = 1
n_static_sound_test = 1
n_random_sound_test = 200

static_test = False
static_sound_test = True
random_sound_test = True

if __name__ == '__main__':
    static_commands = get_random_motor_set(foo, n_static_sound_test)
Exemple #8
0
import h5py, time
import numpy as np
import matplotlib.pyplot as plt
from divapy import Diva as Divapy
from divaml import Diva as Divaml


def h5_to_ndarray(key_, file_name):
    with h5py.File(file_name, 'r') as hf:
        data = hf[key_][:]
    return data


if __name__ == '__main__':
    diva_synth = Divapy()
    diva_synth_ml = Divaml()

    art = [
        -2.82586455, 0.6511439, 0.41705491, -0.16636287, 1.52612695,
        -0.65089551, 2.71660497, -2.8833028, -1.46663703, -2.10624563,
        0.21783021, 0.74918289, 0.48187699
    ]

    art = h5_to_ndarray('arts', '../data/hard_arts.h5')

    sound = diva_synth.get_sound(art)
    sound2 = diva_synth_ml.get_sound(art)
    fig = plt.figure()
    plt.plot(sound)
    plt.hold(True)
"""
Created on June,2017

@author: Juan Manuel Acevedo Valle
"""

from exploration.algorithm.utils.functions import get_random_motor_set
from divapy import  Diva

import numpy as np

system = Diva()
system.n_motor = 13
system.min_motor_values = np.array([-3]*10+[0]*3)
system.max_motor_values = np.array([3]*10+[1]*3)

n_samples_train = 1000000
n_samples_test = 1000
motor_commands = get_random_motor_set(system, n_samples_train)
motor_commands_test = get_random_motor_set(system, n_samples_test)

af_train = np.zeros((n_samples_train, 220))
ss_train = np.zeros((n_samples_train, 6))
for i in range(n_samples_train):
    # print(motor_commands[i,:])
    a,ss,c,af = system.get_audsom(motor_commands[i,:])
    af_train[i,:len(af)] = af
    ss_train[i,:] = ss[:6]
    if i/n_samples_train in [0.2, 0.4, 0.6, 0.8]:
        print('{}% of training samples has been obtained'.format(i/n_samples_train*100))