Speech.speak() more than once?

I tried creating a simple script that runs a loop and calls Speech.speak() on each iteration. In theory, running this script through a shortcut via Siri should result in Siri counting one number at a time, but in practice only the last iteration of the loop is output from Siri.

I looked at the example here: Script to read Reuters headlines which seems to imply that this was working as expected in the past. Has something changed?

Here’s my example code:

// Loop through a range of numbers

for (let i = 0; i < 10; i++) {
    await Speech.speak(`The number is ${i}`);

The output in shortcuts, or via Siri is always simply “Okay done. The number is 9.”

I don’t get anything when this is run in Shortcuts as a call to a script in Scriptable or inline script. It completes without any audible output for me. No “Okay done” (I don’t even see that in the script), and no numbers - it is silent and I did double check my volume.

If I run the script in Scriptable it works fine - I hear the output.

If I enable the “run in app” option in the run inline script or run script actions in Shortcuts, then again, it works fine - it is after all jumping into the app at that point.

I tried it by running the script inline in a shortcut with “Show when run” turned on and it displayed what OP said. The same was true when I invoked the shortcut with Siri but it was spoken.

When I run it with “Run in app” then it works as it should as @sylumer wrote.

When both toggles are off then it doesn’t do anything.

Unless the “OK done” output is loosely a description for the tick and the name of the button and were given in a different order to how they actually occur, then I still don’t get a match to the output that @RossGGG has given when enabling the show when run option.

Maybe it is a match, but I really have to want it to be to read it like that :man_shrugging:t2:

Run it with Siri. Then it matches.

But you already see the problem because you also got only “The number is 9” without the other phrases

In all cases Scriptable has to be the foreground app to speak.

When run via Siri, Siri is just speaking the show when run response, which would just give you the last output in the script. It isn’t being spoken by the script, is it?

You’re right. It isn’t spoken by the script but by Siri.

So you’re saying that this only ever worked when Scriptable is the foreground app?

I’m just saying that is how it is now. I’ve not got any qualified prior data points to reference.