Play sample for a first few beats/first few seconds

I have a wav file (example.wav) which has a duration of 5 seconds
How can I play the first 2 seconds of the wav file.
After two seconds, audio must stop.
The rate: command will downsample the wave file(my understanding). The sound is very much different from the original file.

use_bpm 60
sample “C:/spi/sounds/example.wav”,rate: 2
sleep 2

Hello vinodv!
This will tell you all about it:
https://sonic-pi.net/tutorial.html#section-3-5

Have a read and let us know if you have further questions :slightly_smiling_face:

1 Like
use_bpm 60
sample “C:/spi/sounds/example.wav”,finish: 0.4
sleep 2

will do the job.
Thanks @ ethancrawford

2 Likes

Great - you’re welcome! :slightly_smiling_face: