Convert one sound sample in different sample where each sample's pitch is a note (do-re-mi...) For example, I would like to do like in this video:
https://www.youtube.com/watch?v=YBhneZuAb5k

We have for example a goat yelling sample and from this sample, we can change the pitch according to the pressed piano key. I would like to make a script that will, from one input sample, generate all samples for each pitch/note (do re mi...).
What is the algorithm for doing that?
One generic term for the class of libraries and algorithms that do this, make a set of music keyboard notes from random (psuedo-periodic) pitched sounds, is "time pitch modification".  This is sometimes accomplished by frequency domain phase vocoder analysis-resynthesis or by time domain synchronized overlap-add, followed by filtered resampling.  One example library might be Apple's OS X AVAudioUnitTimePitch effect unit.  Here's a wikipedia page on the topic: https://en.wikipedia.org/wiki/Audio_time-scale/pitch_modification 

First, you might have to use a pitch estimation algorithm to determine a perceived pitch for the original sound sample.  Here's a wikipedia page summarizing some of these methods: https://en.wikipedia.org/wiki/Pitch_detection_algorithm