Sampling audio not working

I attempted to sample a sound using:

file = "[path_to_file]"
sample file

With [path_to_file] substituted for the actual filepath to the .wav file (which plays perfectly fine on my computer). However this does not produce any sound, although no errors are displayed. Additionally the code does not terminate, even though I would expect it to stop after the duration of the sample.

Hm. Works fine on my Sonic Pi

s = "/Users/rbn/Desktop/samples/handbell.wav"
puts sample_duration s
sample s
sleep sample_duration s
puts "got here"
{run: 10, time: 0.0}
 ├─ 9.064013605442177
 └─ sample "~/Desktop/samples",
{run: 10, time: 9.0639}
 └─ Stopped internal thread
{run: 10, time: 9.0639}
 └─ "got here"

What version of Sonic Pi are you using, and on what Computer

Thanks for responding! Strangely enough it’s working now after I copy pasted your code. The most likely explanation is probably that I was typing something wrong without realising. Not sure what that was about, but in any case I’m running v4.3.0 on Windows 10.

1 Like

Glad it’s working for you now.

I had an issue where Sonic Pi would not play samples from a sample library. So giving the path to the directory and trying to play random ones using sample path_to_sample_folder, pick didn’t work. But after I played a sample from that same directory with sample path_to_sample_in_that_folder, which did work, the random sample bit started working. Was driving me nuts as it was working the day before and I wanted to get something done. Now that I see this thread I tried to reproduce it but it just works now. :crazy_face:

Another trick you can try (if you haven’t already) is to open the finder window and drag the file right into the Sonic Pi IDE. This will automatically give you the file directory path with having to type anything which avoids making the mistakes of trying to type it out manually.

1 Like