Dynamic ratio in a function and Tdef

Hello;
I have this script:

~amb0.clear(4)
~amb0.play;
~amb0.pause


~amb0.play; ~amb0.awake_(false);
~amb0 = {
	//var rates = Pxrand([0.7, 0.1, 1, 0.5, 2], inf).asStream.next;
	var sig , env;
	env = Env.asr(\atk.ir(4), \sus.ir(4), \rel.ir(2)).ar(2);
	sig = PlayBuf.ar(1,d["voces"][0], rate:1,startPos:0.1, loop:1);
	sig = sig*env;
	sig = Pan2.ar(sig,0 )*1;
	
};

(
~m = Tdef(\m, {
		var rates = Pxrand([0.7, 0.1, 1, 0.5, 2], inf).asStream.next;

    loop{
        ~amb0.spawn([\rate, rates]); // Ejecuta la función y reproduce el sonido
        15.wait;        // Espera 15 segundos
    };
});
)
~m.play
~m.clear

I want the audio file to play at a different rate each time it is repeated in the task. I have looked for several solutions but always get the same result: when I run the Tdef, it takes one rate and stays there forever.
How can I do this dynamically in a Tdef or in the function (I know that in a Pbind this would be easy)?

Thank you.

As i see it, the Function is missing a rate argument.
And .asStream.next returns a Number not a Stream. Better to just call .asStream, then you get a Routine and you can call .next on it inside the loop.
Also with .spawn there were synths piling up so i use .set.

Here is my version that changes the rate of the Playbuf every 5 seconds.

(
p = ProxySpace.new.push;
b = Buffer.read(s, ExampleFiles.child);
)

(
~amb0.play;
~amb0 = { arg rate = 1;
	var sig , env;
	env = Env.asr(\atk.ir(4), \sus.ir(4), \rel.ir(2)).ar(2);
	sig = PlayBuf.ar(1, b, rate: rate,startPos:0.1, loop:1);
	sig = sig*env;
	sig = Pan2.ar(sig,0 )*0.5;	
};
)

(
m = Tdef(\m, {
		var rates = Pxrand([1, 1.3, 1.5, 1.7, 2], inf).asStream;

    loop{
        ~amb0.set(\rate, rates.next);
        5.wait;    
    };
});
m.play
)

(
m.clear;
~amb0.free;
~amb0.clear;
)

(
b.free;
p.pop;
)