AppleScript How To "keystroke" Slower
I am currently making a "Choose your own adventure" game using AppleScript. I need it to type out text just a bit slower then usual using "keystroke". I have typed out each letter of each word and added delays manually, but I don't want to type them out letter by letter going forward. Would there be a way to cut each sentence letter by letter, then type them out slowly, maybe with "to"? (AppleScript and "to" example below)
"To" Example
to typeTextSlowly(textToType)
//Need some help here
//Would be called with the code below
//Some random code
typeTextSlowly("text")
//Some random code
Manually Made Code
tell application "System Events"
keystroke "H"
delay 0.03
keystroke "e"
delay 0.03
keystroke "l"
delay 0.03
keystroke "l"
delay 0.03
keystroke "o"
delay 0.03
keystroke "."
delay 0.5
keystroke " "
delay 0.03
keystroke "N"
delay 0.03
keystroke "i"
delay 0.03
keystroke "c"
delay 0.03
keystroke "e"
delay 0.03
keystroke " "
delay 0.03
keystroke "t"
delay 0.03
keystroke "o"
delay 0.03
keystroke " "
delay 0.03
keystroke "s"
delay 0.03
keystroke "e"
delay 0.03
keystroke "e"
delay 0.03
keystroke " "
delay 0.03
keystroke "y"
delay 0.03
keystroke "o"
delay 0.03
keystroke "u"
delay 0.03
keystroke "!"
end tell