I think this may be what you are looking for Frere Jaques Records my violin and generates a four part round in Sonic Pi.
The program is shown here
live_audio is essentially just a switch which enables sound input as specified in the parameters. Once starterd it is active until a live_audio :stop command is issued with the same name parameter.
I use live_audio :violin,input: 2 to start it running, :violin is just the name I assign to the input stream, and input: 2 was the input channel I used (only recording mono here from the pickup. Input channels are numbered according to the number of input channels you have enabled. This depends on your audio input card.
Later I stop the input stream using live_audio :violin, :stop
The duration of the buffer is set by the time between these two commands
I use fx :record to specify where the input stream is recorded using three buffers named :v0,:v1,:v2 and :v3 to store the four seperate recordings.
At the beginning I played some tones (in my headphones) to hep me get the tempo and the point at which to start playinfg.
It doesn’t have to be a violin. You can record any instrument or even just sing into a mic. Let me know if you need more info to get going.