import serial ser = serial.Serial('/dev/ttyACM0', 115200) # open serial port import time import fluidsynth fs = fluidsynth.Synth() fs.start(driver="alsa") ## Your installation of FluidSynth may require a different driver. ## Use something like: # fs.start(driver="pulseaudio") #sfid = fs.sfload("example.sf2") fs.program_select(0, sfid, 0, 0) loopFlag = True print 'READY !' while (loopFlag): if (ser.in_waiting): message = ser.read(3) # lets get the command first command = ord(message[0]) note = ord(message[1]) pitch = ord(message[2]) channel = 0 print "command - " + str(command) + " note - " + str(note) + " pitch - " + str(pitch) #if command is over 143 it menas it start note if command > 143: #player.set_instrument(command - 144) #player.note_on(note,pitch,command - 144) fs.noteon(channel, note, pitch) else : #player.set_instrument(command - 128) #player.note_off(note,pitch,command - 128) fs.noteoff(channel, note) print 'EXIT' fs.delete() ser.close()