Record vocal and playback with effects

Hi
Im looking for code to record my voice and then play this back with weird effects like echo, vibrate, sustain etc…
Please can someone help.

thanks
w

ps when recording again the previous if any recording must be deleted and/or overwritten with the new recording

What type computer ?

rasberry pi
want to have a 5 sec gap after recording for the playback to begin automatically

Here is a very simple solution which can be developed as required. It sets up an 8 beat (by default) recording, which is then replayed 5 seconds later in this case with some reverb applied and altering the playback rate to 1.4 which raises the pitch.
The process repeats endlessly.
You could develop the program to provide alternative modifications/efffects, which might be controlled for example by a TouchOSC interface or by a midi controller to select what is required. You can use longer recording by altering the number of beats in the buffer length.

use_bpm 60
use_real_time
loop do
  puts "record";play 84,release: 0.2
  sleep 0.2
  b=buffer(:buff_one,8)
  puts "buffer beats #{b.duration}"
  with_fx :record, buffer: b do
    with_fx :level, amp: 2 do
      live_audio :mic
      sleep b.duration
      puts "pause";play 72,release: 0.2
      sleep rt(5)
    end
  end
  puts "play"
  with_fx :reverb,room: 0.8 do #apply some reverb as an example
    pb_rate =1.4 #change to value you want. 1 is normal playback
    sample b,rate: pb_rate
    sleep b.duration/pb_rate
  end
  puts "ended"
  puts "wait"
  sleep rt(5)
end

I used rt(5) so that if you alter the bpm used (which will alter the timing of the buffer) you still get 5 seconds before the recording replays.

Note if you are using a Raspberry PI there is no detault microphone input. You can get a mono input which will work using a cheap interface such as Techrise usb audio interface card, currently on offer at £7.64 from Amazon. You can of course get a more expensive and better external audio card.

1 Like

Love your work Robin thank you for the feedback and you read my mind re the microphone Ill look into that - Thank you

how do I stop it recording if volume is below a certain threshold - say basic background room noise

Hey hey, I’ll jump in. @robin.newman might have other advice still, but I’m pretty sure that what you’re after is not possible purely with Sonic Pi.

My assumption is that you would need to use some sort of external program or hardware device to do the threshold activated recording, and then just play the resulting samples with Sonic Pi.

Here is a webpage I found that describes one technique that might help:
Sound Activated Recording - Setup - PiBatPiBat

I\d agree with @ethancrawford I don’t think there is a way to adjust theinoput mike to elimintate background noise within Sonic Pi. Working on a Mac you can use something like audio hijack (need to buy it or use for a short demo period of time), which has tools to allow input above a certain trigger level. YOu would still be rocording all the time but with siIence if only background noise present. I suggest the easiest thing is to try and use a quiet environment!

thanks for the feedback and suggestions.
Quick question on the existing code:
how do I extend the recording time and then prolong the playback time ?

In fact, in his first post above, Robin has already mentioned how to change the length of recording. You alter the buffer function.

How long a sample plays depends (of course) on its actual length, but also on its rate:. How long Sonic Pi waits while the sample is playing, is determined by a following sleep/wait or sync.