Sound effect while typing?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Message
Author
User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Sound effect while typing?

#1 Post by namastaii » Tue Sep 06, 2016 2:06 pm

So...I'm curious if this is possible. I know that there is this (which I'm assuming is similar to my idea) https://www.renpy.org/wiki/renpy/FAQ#Ho ... _Wright.3F

Can I have a sound playing while someone is typing into an input? And this is based off of the click-to-type sort of input like the example in my signature. But I only want it to play sound as long as the person is pressing keys..

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Sound effect while typing?

#2 Post by xela » Tue Sep 06, 2016 2:22 pm

namastaii wrote:So...I'm curious if this is possible. I know that there is this (which I'm assuming is similar to my idea) https://www.renpy.org/wiki/renpy/FAQ#Ho ... _Wright.3F

Can I have a sound playing while someone is typing into an input? And this is based off of the click-to-type sort of input like the example in my signature. But I only want it to play sound as long as the person is pressing keys..

Code: Select all

changed
    A python function that is called with what the user has typed, when the string changes.
This should work.
Like what we're doing? Support us at:
Image

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: Sound effect while typing?

#3 Post by namastaii » Tue Sep 06, 2016 2:56 pm

Ohhh
Thanks :)

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: Sound effect while typing?

#4 Post by namastaii » Tue Sep 06, 2016 3:19 pm

Uh...how exactly do I implement that though? The only way I know how to use 'changed' is to tell it to do a function in which it's already using the name change function. Do I have to create a python function to play a sound and while it do both changed actions?

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Sound effect while typing?

#5 Post by xela » Tue Sep 06, 2016 3:34 pm

namastaii wrote:Uh...how exactly do I implement that though? The only way I know how to use 'changed' is to tell it to do a function in which it's already using the name change function. Do I have to create a python function to play a sound and while it do both changed actions?
I imagine it would look something like:

In init python:

Code: Select all

def my_func():
    renpy.music.play("my_type_soundbyte.oog", channel="audio")
In screen:

Code: Select all

input(*bla bla bla, changed=my_func)
I have not tested this, I am 101% sure that what you ask is doable and this would be the first thing I'd try. There are many other options to get it working.
Like what we're doing? Support us at:
Image

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: Sound effect while typing?

#6 Post by namastaii » Tue Sep 06, 2016 3:44 pm

I guess my main concern is can I have two changed's lol or do I just add the play audio to the change text function I have created? If I do that, then I'll have to do it for every function but oh well that's fine. I think I'm going to try that.

update: yes this is the best way thanks :)

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: Sound effect while typing?

#7 Post by namastaii » Tue Sep 06, 2016 4:01 pm

Sorry, one more thing if you happen to know... >.<
Is there a correct way to do something like this?

Code: Select all

renpy.music.play(renpy.random.choice(['sounds/writing1.mp3','sounds/writing2.mp3']), channel="audio")

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Sound effect while typing?

#8 Post by xela » Tue Sep 06, 2016 4:20 pm

I'd expect your code to just work? What goes wrong with it?
Like what we're doing? Support us at:
Image

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: Sound effect while typing?

#9 Post by namastaii » Tue Sep 06, 2016 4:27 pm

Oh...I forgot that this was something that needed to run before the game ran so once I opened it back up instead of refreshing it, it worked.

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: Sound effect while typing?

#10 Post by namastaii » Tue Sep 06, 2016 4:34 pm

Though I wish there was an easy solution to make an erasing sound if the person backspaces the text. I already know that's going to be far more complicated. But it'd be nice.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Sound effect while typing?

#11 Post by xela » Tue Sep 06, 2016 5:13 pm

namastaii wrote:Though I wish there was an easy solution to make an erasing sound if the person backspaces the text. I already know that's going to be far more complicated. But it'd be nice.
This isn't something I can answer without testing, give me 10 mins...
Like what we're doing? Support us at:
Image

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Sound effect while typing?

#12 Post by xela » Tue Sep 06, 2016 5:49 pm

My apologies for supremely sh!tty code but it's very late :D It should work and it should also be safe (8 is also PyGame's backspace index so it shouldn't be bound to anything else):

Code: Select all

init python:
    def my_func(what):
        if renpy.display.interface.last_event.__dict__.get("key", None) == 8:
            # play delete sound...
        else:
            # play typing sound...
Bind the function to your input screen statement and see if it does anything useful... I only tested it through raising Exceptions. There is a way to make fail-safe but this should work fine. And there is prolly a cleaner way to get the same done, I just can't figure out what that is :(
Like what we're doing? Support us at:
Image

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: Sound effect while typing?

#13 Post by namastaii » Tue Sep 06, 2016 9:06 pm

Oh wow. I didn't think it'd be something so specific. I was thinking you'd have to maybe set up a variable that counts the characters of input and once that variable becomes less then it plays a different sound or something haha

Thanks a lot, really:) I can't wait to try it out.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Sound effect while typing?

#14 Post by xela » Wed Sep 07, 2016 2:21 am

namastaii wrote:I was thinking you'd have to maybe set up a variable that counts the characters of input and once that variable becomes less then it plays a different sound or something haha.
Yeah, that would work too, maybe even through InputValue. But you prolly would not be able to distinguish between backspace and delete keys.

There are usually multiple ways to get something done in Ren'Py...
Like what we're doing? Support us at:
Image

bloobeary
Regular
Posts: 36
Joined: Fri Oct 04, 2019 3:02 pm
Deviantart: bloobeary
Soundcloud: user-212448702
Contact:

Re: Sound effect while typing?

#15 Post by bloobeary » Wed Oct 13, 2021 2:23 am

Sorry to drag out an old thread, but I've been attempting to implement this, and I cannot get it to work at all. The instructions given are quite vague, and trying to follow them has proven impossible. Can someone please walk me through how you set this sort of thing up?

I would like a random typing keystrike sound to play as the player types their name in at the start of the game.

I've got this bit of code in the init block before the label start:

Code: Select all

init python:
    def my_func():
        renpy.music.play(renpy.random.choice(['sounds/typing1.wav','sounds/typing2.wav','sounds/typing3.wav']), channel="sound")
But I have no idea where to put the...

Code: Select all

input(*bla bla bla, changed=my_func)
...in the screens.rpy

"bla bla bla" isn't really that helpful for nailing down exactly where this is supposed to go.

I tried sticking it in the..

Code: Select all

screen input(prompt):
like so:

Code: Select all

screen input(prompt, changed=my_func):
...but got nothing. Oddly, it didn't error out on me either. It just didn't provide typing noises on input.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]