Page 1 of 2

Sound effect while typing?

Posted: Tue Sep 06, 2016 2:06 pm
by namastaii
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..

Re: Sound effect while typing?

Posted: Tue Sep 06, 2016 2:22 pm
by xela
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.

Re: Sound effect while typing?

Posted: Tue Sep 06, 2016 2:56 pm
by namastaii
Ohhh
Thanks :)

Re: Sound effect while typing?

Posted: Tue Sep 06, 2016 3:19 pm
by namastaii
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?

Re: Sound effect while typing?

Posted: Tue Sep 06, 2016 3:34 pm
by xela
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.

Re: Sound effect while typing?

Posted: Tue Sep 06, 2016 3:44 pm
by namastaii
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 :)

Re: Sound effect while typing?

Posted: Tue Sep 06, 2016 4:01 pm
by namastaii
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")

Re: Sound effect while typing?

Posted: Tue Sep 06, 2016 4:20 pm
by xela
I'd expect your code to just work? What goes wrong with it?

Re: Sound effect while typing?

Posted: Tue Sep 06, 2016 4:27 pm
by namastaii
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.

Re: Sound effect while typing?

Posted: Tue Sep 06, 2016 4:34 pm
by namastaii
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.

Re: Sound effect while typing?

Posted: Tue Sep 06, 2016 5:13 pm
by xela
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...

Re: Sound effect while typing?

Posted: Tue Sep 06, 2016 5:49 pm
by xela
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 :(

Re: Sound effect while typing?

Posted: Tue Sep 06, 2016 9:06 pm
by namastaii
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.

Re: Sound effect while typing?

Posted: Wed Sep 07, 2016 2:21 am
by xela
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...

Re: Sound effect while typing?

Posted: Wed Oct 13, 2021 2:23 am
by bloobeary
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.