Script in Python to sample Sounds from real MIDI-Keyboard

Erich posted Feb 17, 23:48:

Hi all, this is only a simple script .. my first Python-Script ever.

import sounddevice as sd
from import write
import mido
import time
mido.get_output_names() // check the names and use the right interface in the port=mido... declaration.

velocity = 100;

port=mido.open_output('MIDIOUT2 (USB2.0-MIDI)')

fs = 44100 # Sample rate
seconds = 3 # Duration of recording

i = 32
while i < 90:
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 )
time.sleep(0.5) // wait some time before sending the
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 )
i += 10

Erich posted Feb 17, 23:52:

After the line while i< 90 all following line have to be indent by 2 spaces to the right!
The Script captures all notes beginning at note 32 and ends before note 90. It does it all in steps of 10 sounds. I used it because I wanted to capture a multilayered sound from different Synths and VST-Instruments and did not want to start a session with Audacity to capture a lot of single WAV-Samples. And this way, I am able to use a constant Velocity.


  (not published)
  I want to post as guest