Newsroom Update

The redesigned iPad Air and new iPad Pro with Apple silicon are now available. Learn more >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Voice commands- can I use a variable?

I want to set up a voice command that does several things.


"Hey Siri, nap 30 minutes" should:

-turn on do not disturb for 30 minutes

-play the first 30 minutes of a white noise file

-and turn on a 30-minute timer.


The 30 minutes is the variable. I could kludge it by making commands for 30,45, hour etc but I'm hoping that one command could suffice.


I could do this in any programming language, but I don't yet understand how voice commands are set up.


How would I do this?

Posted on Jun 26, 2022 10:22 AM

Reply
3 replies

Jul 5, 2022 5:33 AM in response to biggerhammer

You can use the Shortcuts app to create a shortcut that includes a Dictate Text action, then use Siri to input a time variable and run it. The shortcut once created can run from anywhere and doesn't require the Shortcuts app to be open.


A better approach to using an audio file of specific length is to use a system background sound; it’s more flexible for use with a time variable, easier to implement, and provides a seamless auditory result. You can select the background sound by navigating to Settings > Accessibility > Audio & Visual > Background Sounds > Sound. The available options are: Balanced Noise, Bright Noise, Dark noise, Ocean, Rain, and Stream.


While in Settings you may also want to set the volume for the background noise which is set independently to that of the system volume. Optionally, you can change the background sound and its volume with actions in the shortcut.


The shortcut workflow by necessity uses a two-part voice command: invoking the name of the shortcut, then when prompted by Siri, providing the text for dictation including the required time variable. For instance, if you say, "Hey Siri, Time to Nap" Siri responds with the prompt, "What’s the text?" To which you might respond with, "Let’s nap for thirty minutes." Note, for any time less than ten minutes you’ll need to prefix 'zero' for Siri to convert a number name to numerical digits. For example, say, "Let’s nap for zero five minutes." Be careful if using words that sound like a number, particularly before 'zero,' such as 'to' and 'for'.



The shortcut forgoes error handling and assumes appropriate verbal input by the user. Specifically, that means including only one number which is the time variable. Also note, if you stop the shortcut before the sleep timer finishes the background sound will keep running until you stop it manually in Settings.



The shortcut actions used in sequence: Dictate Text, Dismiss Siri and Continue, Match Text, Set Variable, Start Timer, Date, Adjust Date, Set Focus, Calculate, Set Variable, Set Background Sounds, Wait, and Set Background Sounds.



Create the shortcut yourself or download it from this link: Time to Nap. Modify it to suit your needs.


Shortcuts User Guide


iPad Pro (12.9-inch) (3rd generation), iPadOS 15.5

Voice commands- can I use a variable?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.