Set tempo according to buffer length

I wonder if anyone can help me. I have a folder loaded into SC. It’s in a dictionary so I recall a buffer using b[\folder][0].
I want to make a function where the tempo is a function of the current buffer length. The spoken lines are about 4 - 7 seconds long.

I imagine it like this:
It’s a loop
The buffer is randomly picked from the folder each repeat.
The current buffer sets the new tempo. The current buffer is supposed to be one bar.
Example:
The measure is 4/4. Every buffer should be 3 beats and then 1 beat extra as a pause.
b[1] is 4 seconds long, i want to add a beat/ after the buffer. Let´s say that the beat is 1 second long. This makes it 5 seconds, so the bpm should add up to 75 bpm. Next one is 6 seconds long, so I want the bpm to follow that length and also add one beat.

Tempo should be a function of the buffer duration, but I don’t know how to solve this. It feels quite simple…

// Would this be correct math? 
t.tempo = (b.folder[buf].numFrames/s.sampleRate - 1) * 4 ;

you want 3 beats per buffer

so to get your beat duration you want to divide your buffer duration by 3

and tempo will be the reciprocal of beat duration

so I think: t.tempo = (b.folder[buf].numFrames / s.sampleRate / 3).reciprocal ;

The problem is that using s.sample rate isn’t guaranteed to work if the buffer sample rate doesn’t match the server sample rate.
You can call .dur or .duration or something to that effect (away from my computer right now) on a buffer and then you don’t have to write out all of the math either. Then all you need to do is divide by the number of beats to get beat duration, which is the reciprocal of tempo.

This is how I’ve done it so far. It works, but it feels like it can be improved.

(
var s, t;
s = Server.default;
t = TempoClock.default;

Routine({
	8.do {
	var tempo, buffer;
	buffer = b.repliker[(0..16).choose];
	s.bind {Synth(\buffer, [buf: buffer, atk: 0.01, rel:12])};
	s.bind {tempo = TempoClock.default.tempo_((buffer.duration)/4)};
	buffer.duration.wait;
	};

}).play;

Routine({
	32.do {. // could be infinite as well. 
		s.bind {Synth(\ping)};
		1.wait;
	}
	}).play(t);



)