Skip to content

Instantly share code, notes, and snippets.

@ChrisMorrisOrg
Last active December 10, 2015 15:08
Show Gist options
  • Save ChrisMorrisOrg/4452066 to your computer and use it in GitHub Desktop.
Save ChrisMorrisOrg/4452066 to your computer and use it in GitHub Desktop.
Given some text, this function will print out the text as if the computer is typing it live, in front of you.
def fakeChat(text):
# Set SPEED_VARIANCE to 0.001 for low variance, 10 for high variance
SPEED_VARIANCE = 0.1
x = 0
rate = 1
# Ensure clean input
text = str(text)
rate = int(rate)
while x < len(text):
print(text[x:x+1], end="")
sys.stdout.flush()
sleep(random.random()*SPEED_VARIANCE)
x += rate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment