def init_motor_DMP(self, optim_initial_position=True, optim_end_position=True, default_motor_initial_position=None, default_motor_end_position=None): default = np.zeros(self.n_dynamic_motor_dims * (self.n_bfs + 2)) if not optim_initial_position: default[:self. n_dynamic_motor_dims] = default_motor_initial_position or [ 0. ] * self.n_dynamic_motor_dims dims_optim = [False] * self.n_dynamic_motor_dims else: dims_optim = [True] * self.n_dynamic_motor_dims dims_optim += [True] * (self.n_dynamic_motor_dims * self.n_bfs) if not optim_end_position: default[-self. n_dynamic_motor_dims:] = default_motor_end_position or [ 0. ] * self.n_dynamic_motor_dims dims_optim += [False] * self.n_dynamic_motor_dims else: dims_optim += [True] * self.n_dynamic_motor_dims self.motor_dmp = DmpPrimitive(self.n_dynamic_motor_dims, self.n_bfs, dims_optim, default, type='discrete', timesteps=self.move_steps)
def __init__(self, n_dmps, n_bfs, used, default, conf, sm, im, dmp_type='discrete', ay=None): Agent.__init__(self, conf, sm, im) self.n_dmps, self.n_bfs = n_dmps, n_bfs self.current_m = zeros(self.conf.m_ndims) if ay is None: self.dmp = DmpPrimitive(n_dmps, n_bfs, used, default, type=dmp_type) else: self.dmp = DmpPrimitive(n_dmps, n_bfs, used, default, type=dmp_type, ay=ones(n_dmps) * 1.)
def __init__(self, synth, m_mins, m_maxs, s_mins, s_maxs, m_used, s_used, n_dmps, n_bfs, dmp_move_steps, dmp_max_param, sensory_traj_samples, audio, diva_path=None): self.m_mins = m_mins self.m_maxs = m_maxs self.s_mins = s_mins self.s_maxs = s_maxs self.m_used = m_used self.s_used = s_used self.n_dmps = n_dmps self.n_bfs = n_bfs self.dmp_move_steps = dmp_move_steps self.dmp_max_param = dmp_max_param self.samples = array(linspace(-1, self.dmp_move_steps - 1, sensory_traj_samples + 1), dtype=int)[1:] self.audio = audio self.f0 = 1. self.pressure = 1. self.voicing = 1. if self.audio: import pyaudio self.pa = pyaudio.PyAudio() self.stream = self.pa.open(format=pyaudio.paFloat32, channels=1, rate=11025, output=True) if synth == "octave": self.synth = DivaOctaveSynth(diva_path) elif synth == "matlab": self.synth = DivaMatlabSynth() else: raise NotImplementedError self.art = array( [0.] * 10 + [self.f0, self.pressure, self.voicing] ) # 13 articulators is a constant from diva_synth.m in the diva source code self.max_params = array([1.] * self.n_dmps + [self.dmp_max_param] * self.n_bfs * self.n_dmps + [1.] * self.n_dmps) self.dmp = DmpPrimitive(dmps=self.n_dmps, bfs=self.n_bfs, timesteps=self.dmp_move_steps) Environment.__init__(self, self.m_mins, self.m_maxs, self.s_mins, self.s_maxs)
def init_sensori_DMP(self, optim_initial_position=True, optim_end_position=True, default_sensori_initial_position=None, default_sensori_end_position=None): default = np.zeros(self.n_dynamic_sensori_dims * (self.n_sensori_traj_points + 2)) if not optim_initial_position: default[:self. n_dynamic_sensori_dims] = default_sensori_initial_position dims_optim = [False] * self.n_dynamic_sensori_dims else: dims_optim = [True] * self.n_dynamic_sensori_dims dims_optim += [True] * (self.n_dynamic_sensori_dims * self.n_sensori_traj_points) if not optim_end_position: default[-self. n_dynamic_sensori_dims:] = default_sensori_end_position dims_optim += [False] * self.n_dynamic_sensori_dims else: dims_optim += [True] * self.n_dynamic_sensori_dims self.sensori_dmp = DmpPrimitive(self.n_dynamic_sensori_dims, self.n_sensori_traj_points, dims_optim, default, type='discrete', timesteps=self.move_steps)
def __init__(self, synth, m_mins, m_maxs, s_mins, s_maxs, m_used, s_used, n_dmps, n_bfs, dmp_move_steps, dmp_max_param, sensory_traj_samples, audio, diva_path=None): self.m_mins = m_mins self.m_maxs = m_maxs self.s_mins = s_mins self.s_maxs = s_maxs self.m_used = m_used self.s_used = s_used self.n_dmps = n_dmps self.n_bfs = n_bfs self.dmp_move_steps = dmp_move_steps self.dmp_max_param = dmp_max_param self.samples = array(linspace(-1, self.dmp_move_steps-1, sensory_traj_samples + 1), dtype=int)[1:] self.audio = audio self.f0 = 1. self.pressure = 1. self.voicing = 1. if self.audio: import pyaudio self.pa = pyaudio.PyAudio() self.stream = self.pa.open(format=pyaudio.paFloat32, channels=1, rate=11025, output=True) if synth == "octave": self.synth = DivaOctaveSynth(diva_path) elif synth == "matlab": self.synth = DivaMatlabSynth() else: raise NotImplementedError self.art = array([0.]*10 + [self.f0, self.pressure, self.voicing]) # 13 articulators is a constant from diva_synth.m in the diva source code self.max_params = array([1.] * self.n_dmps + [self.dmp_max_param] * self.n_bfs * self.n_dmps + [1.] * self.n_dmps) self.dmp = DmpPrimitive(dmps=self.n_dmps, bfs=self.n_bfs, timesteps=self.dmp_move_steps) Environment.__init__(self, self.m_mins, self.m_maxs, self.s_mins, self.s_maxs)
def init_motor_DMP(self, optim_initial_position=True, optim_end_position=True, default_motor_initial_position=None, default_motor_end_position=None): default = np.zeros(self.n_dynamic_motor_dims * (self.n_bfs + 2)) if not optim_initial_position: default[:self.n_dynamic_motor_dims] = default_motor_initial_position or [0.] * self.n_dynamic_motor_dims dims_optim = [False] * self.n_dynamic_motor_dims else: dims_optim = [True] * self.n_dynamic_motor_dims dims_optim += [True] * (self.n_dynamic_motor_dims * self.n_bfs) if not optim_end_position: default[-self.n_dynamic_motor_dims:] = default_motor_end_position or [0.] * self.n_dynamic_motor_dims dims_optim += [False] * self.n_dynamic_motor_dims else: dims_optim += [True] * self.n_dynamic_motor_dims self.motor_dmp = DmpPrimitive(self.n_dynamic_motor_dims, self.n_bfs, dims_optim, default, type='discrete', timesteps=self.move_steps)
class DmpAgent(Agent): def __init__(self, n_dmps, n_bfs, used, default, conf, sm, im, dmp_type='discrete', ay=None): Agent.__init__(self, conf, sm, im) self.n_dmps, self.n_bfs = n_dmps, n_bfs self.current_m = zeros(self.conf.m_ndims) if ay is None: self.dmp = DmpPrimitive(n_dmps, n_bfs, used, default, type=dmp_type) else: self.dmp = DmpPrimitive(n_dmps, n_bfs, used, default, type=dmp_type, ay=ones(n_dmps) * 1.) @classmethod def from_settings(cls, n_bfs, starting_position, babbling_name, sm_name, im_name): params = get_params(n_bfs, starting_position, babbling_name, sm_name, im_name) return cls(**params) def motor_primitive(self, m): self.m = bounds_min_max(m, self.conf.m_mins, self.conf.m_maxs) y = self.dmp.trajectory(self.m) self.current_m = y[-1, :] return y # y[:int(len(y) * ((n_bfs*2. - 1.)/(n_bfs*2.))), :] def sensory_primitive(self, s): return s[-1] # array([mean(s)]) #s[[-1]]
class DynamicEnvironment(Environment): def __init__(self, env_cls, env_cfg, m_mins, m_maxs, s_mins, s_maxs, n_bfs, move_steps, n_dynamic_motor_dims, n_dynamic_sensori_dims, max_params, motor_traj_type="DMP", sensori_traj_type="samples", optim_initial_position=False, optim_end_position=False, default_motor_initial_position=None, default_motor_end_position=None, default_sensori_initial_position=None, default_sensori_end_position=None): self.env = env_cls(**env_cfg) self.n_bfs = n_bfs self.n_motor_traj_points = self.n_bfs self.n_sensori_traj_points = self.n_bfs self.move_steps = move_steps self.n_dynamic_motor_dims = n_dynamic_motor_dims self.n_dynamic_sensori_dims = n_dynamic_sensori_dims self.max_params = max_params self.motor_traj_type = motor_traj_type self.sensori_traj_type = sensori_traj_type self.optim_initial_position = optim_initial_position self.optim_end_position = optim_end_position Environment.__init__(self, m_mins, m_maxs, s_mins, s_maxs) self.s_traj = None if self.motor_traj_type == "DMP": self.init_motor_DMP(optim_initial_position, optim_end_position, default_motor_initial_position, default_motor_end_position) else: raise NotImplementedError if self.sensori_traj_type == "DMP": self.init_sensori_DMP(optim_initial_position, optim_end_position, default_sensori_initial_position, default_sensori_end_position) elif self.sensori_traj_type == "samples": self.samples = np.array(np.linspace(-1, self.move_steps-1, self.n_sensori_traj_points + 1), dtype=int)[1:] elif self.sensori_traj_type == "end_point": self.end_point = self.move_steps-1 else: raise NotImplementedError def reset(self): self.env.reset() def init_motor_DMP(self, optim_initial_position=True, optim_end_position=True, default_motor_initial_position=None, default_motor_end_position=None): default = np.zeros(self.n_dynamic_motor_dims * (self.n_bfs + 2)) if not optim_initial_position: default[:self.n_dynamic_motor_dims] = default_motor_initial_position or [0.] * self.n_dynamic_motor_dims dims_optim = [False] * self.n_dynamic_motor_dims else: dims_optim = [True] * self.n_dynamic_motor_dims dims_optim += [True] * (self.n_dynamic_motor_dims * self.n_bfs) if not optim_end_position: default[-self.n_dynamic_motor_dims:] = default_motor_end_position or [0.] * self.n_dynamic_motor_dims dims_optim += [False] * self.n_dynamic_motor_dims else: dims_optim += [True] * self.n_dynamic_motor_dims self.motor_dmp = DmpPrimitive(self.n_dynamic_motor_dims, self.n_bfs, dims_optim, default, type='discrete', timesteps=self.move_steps) def init_sensori_DMP(self, optim_initial_position=True, optim_end_position=True, default_sensori_initial_position=None, default_sensori_end_position=None): default = np.zeros(self.n_dynamic_sensori_dims * (self.n_sensori_traj_points + 2)) if not optim_initial_position: default[:self.n_dynamic_sensori_dims] = default_sensori_initial_position dims_optim = [False] * self.n_dynamic_sensori_dims else: dims_optim = [True] * self.n_dynamic_sensori_dims dims_optim += [True] * (self.n_dynamic_sensori_dims * self.n_sensori_traj_points) if not optim_end_position: default[-self.n_dynamic_sensori_dims:] = default_sensori_end_position dims_optim += [False] * self.n_dynamic_sensori_dims else: dims_optim += [True] * self.n_dynamic_sensori_dims self.sensori_dmp = DmpPrimitive(self.n_dynamic_sensori_dims, self.n_sensori_traj_points, dims_optim, default, type='discrete', timesteps=self.move_steps) def compute_motor_command(self, m_ag): m_ag = bounds_min_max(m_ag, self.conf.m_mins, self.conf.m_maxs) if self.motor_traj_type == "DMP": dyn_idx = range(self.n_dynamic_motor_dims * self.n_motor_traj_points) m_weighted = m_ag[dyn_idx] * self.max_params if self.optim_initial_position: m_weighted[:self.n_dynamic_motor_dims] = m_weighted[:self.n_dynamic_motor_dims] / self.max_params if self.optim_end_position: m_weighted[-self.n_dynamic_motor_dims:] = m_weighted[-self.n_dynamic_motor_dims:] / self.max_params m_dyn = self.motor_dmp.trajectory(m_weighted) static_idx = range(self.n_dynamic_motor_dims * self.n_motor_traj_points, self.conf.m_ndims) m_static = m_ag[static_idx] m = [list(m_dyn_param) + list(m_static) for m_dyn_param in list(m_dyn)] else: raise NotImplementedError return m def compute_sensori_effect(self, m_traj): s = self.env.update(m_traj, reset=False, log=False) self.s_traj = s y = np.array(s[:self.move_steps]) if self.sensori_traj_type == "DMP": self.sensori_dmp.dmp.imitate_path(np.transpose(y)) w = self.sensori_dmp.dmp.w.flatten() s_ag = list(w) elif self.sensori_traj_type == "samples": w = y[self.samples,:] s_ag = list(np.transpose(w).flatten()) elif self.sensori_traj_type == "end_point": s_ag = y[self.end_point,:].flatten() else: raise NotImplementedError s = s_ag return bounds_min_max(s, self.conf.s_mins, self.conf.s_maxs) def update(self, m_ag, reset=True, log=False): if reset: self.reset() if len(np.array(m_ag).shape) == 1: s = self.one_update(m_ag, log) else: s = [] for m in m_ag: s.append(self.one_update(m, log)) s = np.array(s) return s def plot(self, fig, ax, **kwargs): ax.cla() ax.set_aspect('equal') ax.set_xlim((-1.5, 1.5)) ax.set_ylim((-1.5, 1.5)) def animate(i): return tuple(self.env.plot_update(ax, i)) return animation.FuncAnimation(fig, animate, frames=50, interval=50, blit=True).to_html5_video()
class DivaDMPEnvironment(Environment): def __init__(self, synth, m_mins, m_maxs, s_mins, s_maxs, m_used, s_used, n_dmps, n_bfs, dmp_move_steps, dmp_max_param, sensory_traj_samples, audio, diva_path=None): self.m_mins = m_mins self.m_maxs = m_maxs self.s_mins = s_mins self.s_maxs = s_maxs self.m_used = m_used self.s_used = s_used self.n_dmps = n_dmps self.n_bfs = n_bfs self.dmp_move_steps = dmp_move_steps self.dmp_max_param = dmp_max_param self.samples = array(linspace(-1, self.dmp_move_steps - 1, sensory_traj_samples + 1), dtype=int)[1:] self.audio = audio self.f0 = 1. self.pressure = 1. self.voicing = 1. if self.audio: import pyaudio self.pa = pyaudio.PyAudio() self.stream = self.pa.open(format=pyaudio.paFloat32, channels=1, rate=11025, output=True) if synth == "octave": self.synth = DivaOctaveSynth(diva_path) elif synth == "matlab": self.synth = DivaMatlabSynth() else: raise NotImplementedError self.art = array( [0.] * 10 + [self.f0, self.pressure, self.voicing] ) # 13 articulators is a constant from diva_synth.m in the diva source code self.max_params = array([1.] * self.n_dmps + [self.dmp_max_param] * self.n_bfs * self.n_dmps + [1.] * self.n_dmps) self.dmp = DmpPrimitive(dmps=self.n_dmps, bfs=self.n_bfs, timesteps=self.dmp_move_steps) Environment.__init__(self, self.m_mins, self.m_maxs, self.s_mins, self.s_maxs) def compute_motor_command(self, m): return bounds_min_max(m, self.m_mins, self.m_maxs) def compute_sensori_effect(self, m): m = self.trajectory(m) self.art_traj = zeros((13, array(m).shape[0])) self.art_traj[10, :] = self.f0 self.art_traj[11, :] = self.pressure self.art_traj[12, :] = self.voicing self.art_traj[self.m_used, :] = transpose(m) res = self.synth.execute(2. * (self.art_traj)) formants = log2(transpose(res[self.s_used, :])) formants[isnan(formants)] = 0. self.formants_traj = formants return list(formants[self.samples, 0]) + list(formants[self.samples, 1]) def trajectory(self, m): y = self.dmp.trajectory(array(m) * self.max_params) if len(y) > self.dmp_move_steps: ls = linspace(0, len(y) - 1, self.dmp_move_steps) ls = array(ls, dtype='int') y = y[ls] return y def update(self, mov, audio=True): s = Environment.update(self, mov) if self.audio and audio: self.play_sound(self.art_traj) return s def sound_wave(self, art_traj, power=2.): synth_art = self.art.reshape(1, -1).repeat(len(art_traj.T), axis=0) synth_art[:, :] = art_traj.T return power * self.synth.sound_wave(synth_art.T) def play_sound(self, art_traj): sound = self.sound_wave(art_traj) self.stream.write(sound.astype(float32).tostring())
class DynamicEnvironment(Environment): def __init__(self, env_cls, env_cfg, m_mins, m_maxs, s_mins, s_maxs, n_bfs, move_steps, n_dynamic_motor_dims, n_dynamic_sensori_dims, max_params, n_sensori_traj_points=None, motor_traj_type="DMP", sensori_traj_type="samples", optim_initial_position=False, optim_end_position=False, default_motor_initial_position=None, default_motor_end_position=None, default_sensori_initial_position=None, default_sensori_end_position=None): self.env = env_cls(**env_cfg) self.n_bfs = n_bfs self.n_motor_traj_points = self.n_bfs + optim_initial_position + optim_end_position self.n_sensori_traj_points = n_sensori_traj_points or self.n_bfs self.move_steps = move_steps self.n_dynamic_motor_dims = n_dynamic_motor_dims self.n_dynamic_sensori_dims = n_dynamic_sensori_dims self.max_params = max_params self.motor_traj_type = motor_traj_type self.sensori_traj_type = sensori_traj_type self.optim_initial_position = optim_initial_position self.optim_end_position = optim_end_position Environment.__init__(self, m_mins, m_maxs, s_mins, s_maxs) self.s_traj = None if self.motor_traj_type == "DMP": self.init_motor_DMP(optim_initial_position, optim_end_position, default_motor_initial_position, default_motor_end_position) else: raise NotImplementedError if self.sensori_traj_type == "DMP": self.init_sensori_DMP(optim_initial_position, optim_end_position, default_sensori_initial_position, default_sensori_end_position) elif self.sensori_traj_type == "samples": self.samples = np.array(np.linspace( -1, self.move_steps - 1, self.n_sensori_traj_points + 1), dtype=int)[1:] elif self.sensori_traj_type == "end_point": self.end_point = self.move_steps - 1 else: raise NotImplementedError def reset(self): self.env.reset() def init_motor_DMP(self, optim_initial_position=True, optim_end_position=True, default_motor_initial_position=None, default_motor_end_position=None): default = np.zeros(self.n_dynamic_motor_dims * (self.n_bfs + 2)) if not optim_initial_position: default[:self. n_dynamic_motor_dims] = default_motor_initial_position or [ 0. ] * self.n_dynamic_motor_dims dims_optim = [False] * self.n_dynamic_motor_dims else: dims_optim = [True] * self.n_dynamic_motor_dims dims_optim += [True] * (self.n_dynamic_motor_dims * self.n_bfs) if not optim_end_position: default[-self. n_dynamic_motor_dims:] = default_motor_end_position or [ 0. ] * self.n_dynamic_motor_dims dims_optim += [False] * self.n_dynamic_motor_dims else: dims_optim += [True] * self.n_dynamic_motor_dims self.motor_dmp = DmpPrimitive(self.n_dynamic_motor_dims, self.n_bfs, dims_optim, default, type='discrete', timesteps=self.move_steps) def init_sensori_DMP(self, optim_initial_position=True, optim_end_position=True, default_sensori_initial_position=None, default_sensori_end_position=None): default = np.zeros(self.n_dynamic_sensori_dims * (self.n_sensori_traj_points + 2)) if not optim_initial_position: default[:self. n_dynamic_sensori_dims] = default_sensori_initial_position dims_optim = [False] * self.n_dynamic_sensori_dims else: dims_optim = [True] * self.n_dynamic_sensori_dims dims_optim += [True] * (self.n_dynamic_sensori_dims * self.n_sensori_traj_points) if not optim_end_position: default[-self. n_dynamic_sensori_dims:] = default_sensori_end_position dims_optim += [False] * self.n_dynamic_sensori_dims else: dims_optim += [True] * self.n_dynamic_sensori_dims self.sensori_dmp = DmpPrimitive(self.n_dynamic_sensori_dims, self.n_sensori_traj_points, dims_optim, default, type='discrete', timesteps=self.move_steps) def compute_motor_command(self, m_ag): m_ag = bounds_min_max(m_ag, self.conf.m_mins, self.conf.m_maxs) if self.motor_traj_type == "DMP": dyn_idx = range(self.n_dynamic_motor_dims * self.n_motor_traj_points) m_weighted = m_ag[dyn_idx] * self.max_params if self.optim_initial_position: m_weighted[:self. n_dynamic_motor_dims] = m_weighted[:self. n_dynamic_motor_dims] / self.max_params if self.optim_end_position: m_weighted[-self.n_dynamic_motor_dims:] = m_weighted[ -self.n_dynamic_motor_dims:] / self.max_params m_dyn = self.motor_dmp.trajectory(m_weighted) static_idx = range( self.n_dynamic_motor_dims * self.n_motor_traj_points, self.conf.m_ndims) m_static = m_ag[static_idx] m = [ list(m_dyn_param) + list(m_static) for m_dyn_param in list(m_dyn) ] else: raise NotImplementedError return m def compute_sensori_effect(self, m_traj): s = self.env.update(m_traj, reset=False, log=False) self.s_traj = s y = np.array(s[:self.move_steps]) if self.sensori_traj_type == "DMP": self.sensori_dmp.dmp.imitate_path(np.transpose(y)) w = self.sensori_dmp.dmp.w.flatten() s_ag = list(w) elif self.sensori_traj_type == "samples": w = y[self.samples, :] s_ag = list(np.transpose(w).flatten()) elif self.sensori_traj_type == "end_point": s_ag = y[self.end_point, :].flatten() else: raise NotImplementedError s = list(s_ag) + list(s[self.move_steps:]) return bounds_min_max(s, self.conf.s_mins, self.conf.s_maxs) def update(self, m_ag, reset=True, log=False): if reset: self.reset() if len(np.array(m_ag).shape) == 1: s = self.one_update(m_ag, log) else: s = [] for m in m_ag: s.append(self.one_update(m, log)) s = np.array(s) return s def plot(self, fig, ax, **kwargs): ax.cla() ax.set_aspect('equal') ax.set_xlim((-1.5, 1.5)) ax.set_ylim((-1.5, 1.5)) def animate(i): return tuple(self.env.plot_update(ax, i)) return animation.FuncAnimation(fig, animate, frames=50, interval=50, blit=True).to_html5_video()
class DivaDMPEnvironment(Environment): def __init__(self, synth, m_mins, m_maxs, s_mins, s_maxs, m_used, s_used, n_dmps, n_bfs, dmp_move_steps, dmp_max_param, sensory_traj_samples, audio, diva_path=None): self.m_mins = m_mins self.m_maxs = m_maxs self.s_mins = s_mins self.s_maxs = s_maxs self.m_used = m_used self.s_used = s_used self.n_dmps = n_dmps self.n_bfs = n_bfs self.dmp_move_steps = dmp_move_steps self.dmp_max_param = dmp_max_param self.samples = array(linspace(-1, self.dmp_move_steps-1, sensory_traj_samples + 1), dtype=int)[1:] self.audio = audio self.f0 = 1. self.pressure = 1. self.voicing = 1. if self.audio: import pyaudio self.pa = pyaudio.PyAudio() self.stream = self.pa.open(format=pyaudio.paFloat32, channels=1, rate=11025, output=True) if synth == "octave": self.synth = DivaOctaveSynth(diva_path) elif synth == "matlab": self.synth = DivaMatlabSynth() else: raise NotImplementedError self.art = array([0.]*10 + [self.f0, self.pressure, self.voicing]) # 13 articulators is a constant from diva_synth.m in the diva source code self.max_params = array([1.] * self.n_dmps + [self.dmp_max_param] * self.n_bfs * self.n_dmps + [1.] * self.n_dmps) self.dmp = DmpPrimitive(dmps=self.n_dmps, bfs=self.n_bfs, timesteps=self.dmp_move_steps) Environment.__init__(self, self.m_mins, self.m_maxs, self.s_mins, self.s_maxs) def compute_motor_command(self, m): return bounds_min_max(m, self.m_mins, self.m_maxs) def compute_sensori_effect(self, m): m = self.trajectory(m) self.art_traj = zeros((13, array(m).shape[0])) self.art_traj[10, :] = self.f0 self.art_traj[11, :] = self.pressure self.art_traj[12, :] = self.voicing self.art_traj[self.m_used,:] = transpose(m) res = self.synth.execute(2.*(self.art_traj)) formants = log2(transpose(res[self.s_used,:])) formants[isnan(formants)] = 0. self.formants_traj = formants return list(formants[self.samples,0]) + list(formants[self.samples,1]) def trajectory(self, m): y = self.dmp.trajectory(array(m) * self.max_params) if len(y) > self.dmp_move_steps: ls = linspace(0,len(y)-1,self.dmp_move_steps) ls = array(ls, dtype='int') y = y[ls] return y def update(self, mov, audio=True): s = Environment.update(self, mov) if self.audio and audio: self.play_sound(self.art_traj) return s def sound_wave(self, art_traj, power=2.): synth_art = self.art.reshape(1, -1).repeat(len(art_traj.T), axis=0) synth_art[:, :] = art_traj.T return power * self.synth.sound_wave(synth_art.T) def play_sound(self, art_traj): sound = self.sound_wave(art_traj) self.stream.write(sound.astype(float32).tostring())