Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pause macro during speech #124

Open
elpimous opened this issue Jun 20, 2018 · 5 comments
Open

pause macro during speech #124

elpimous opened this issue Jun 20, 2018 · 5 comments

Comments

@elpimous
Copy link

Hi all.

Need to see Alfred pause into a retry, to simulate brain search activity...

here is my simple macro :

> object pause python
    from time import sleep
    a = (args)
    a = "".join(a)
    sleep(int(a))
< object

here is my try (failed) :

...
- a moment,  searching for best AI response <call>pause 2</call> Ok, I have it now {weight=50}

It should speak, make a 2s pause, and speak again,
but it just starts with pause, and after, speak all sentence (a moment, searching for best AI response Ok, I have it now)

?

@kirsle
Copy link
Member

kirsle commented Jun 20, 2018

Hi

It's because rs.reply() is a synchronous method and can't return the reply until everything has finished. When it's processing the tags in the reply and sees the <call> tag, it runs the Python pause function you defined, which makes it wait a couple seconds before returning a string. Then it can finally substitute that string in place of the <call> tag and start returning the reply.

So you'll call rs.reply() and it will hang for 2 seconds before returning the final reply all at once.

You're probably best off handling the delay outside the RiveScript module, like,

# (rivescript)
# make up a `<pause #>` tag and use it instead of `<call>`:
- a moment,  searching for best AI response <pause 2> Ok, I have it now {weight=50}
reply = bot.reply(user, message)
parts = re.split(r'<pause \d+?>', reply)  # split at a `<pause>` tag but include the tag:
# ["a moment,  searching for best AI response ", "<pause 2>", "Ok, I have it now"]
for part in parts:
    m = re.search(r'^<pause (\d+?)>$', part)
    if m:  # this is the `<pause>` tag
        time.sleep( int(m.group(1) )  # sleep the 2 seconds
    else:
        print(part)  # or whatever

@elpimous
Copy link
Author

elpimous commented Jun 21, 2018

Thanks for explanations !!
and (félicitations pour la demande en mariage !)
(I wish you the best, Noah)
Vincent

ps : parts = re.split(r'<pause \d+?>', reply) doesn't keep pause part in parts !
searching...

@elpimous
Copy link
Author

another re command ? Didn't find correct one ! thanks

@kirsle
Copy link
Member

kirsle commented Jun 25, 2018

Ah sorry, I meant to include parenthesis around the regexp:

parts = re.split(r'(<pause \d+?>)', reply)

@elpimous
Copy link
Author

elpimous commented Jun 25, 2018

Very good ! works very nicely !!

reply = rs.reply(user, message)

# added pause tag  ex : <pause 2> (2 seconds)
parts = re.split(r'(<pause \d+?>)', reply)  # split at a `<pause>` tag but include the tag:
# ["a moment,  searching for best AI response ", "<pause 2>", "Ok, I have it now"]
for part in parts:
    m = re.search(r'^<pause (\d+?)>$', part)
    if m:  # this is the `<pause>` tag
        time.sleep( int(m.group(1) ))  # sleep x seconds
    else:
        print(part)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants