Hi all, this is only a simple script .. my first Python-Script ever.
import sounddevice as sd
from scipy.io.wavfile import write
import mido
import time
mido.set_backend('mido.backends.portmidi')
mido.get_output_names() // check the names and use the right interface in the port=mido... declaration.
samplesetname="piano"
velocity = 100;
port=mido.open_output('MIDIOUT2 (USB2.0-MIDI)')
fs = 44100 # Sample rate
seconds = 3 # Duration of recording
i = 32
while i < 90:
print(i)
myrecording = sd.rec(int(seconds * fs), samplerate=fs, channels=2)
msg=mido.Message('note_on', channel=0, note=i, velocity=90 )
msg2=mido.Message('noteoff', channel=0, note=i, velocity=0 )
port.send(msg)
time.sleep(0.5) // wait some time before sending the
port.send(msg2)
sd.wait() # Wait until recording is finished
write( str(i) +''+ str(velocity) + '_' + samplesetname +'.wav', fs, myrecording) # Save as WAV file
msg2=mido.Message('note_off', channel=0, note=i, velocity=0 )
port.send(msg2)
i += 10